Skip to content

Commit

Permalink
Handle ArrayPool arrays more safely
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Jul 3, 2024
1 parent a815169 commit 486e619
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 159 deletions.
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Evm.Test/InvalidOpcodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ public void Test(long blockNumber, ulong? timestamp = null)

byte[] code = Prepare.EvmCode
.Op((byte)i)
.Done; ;
.Done;

if (InstructionExtensions.IsValid(opcode, true) && !InstructionExtensions.IsValid(opcode, false))
if (InstructionExtensions.IsValid(opcode, IsEofContext: true) && !InstructionExtensions.IsValid(opcode, IsEofContext: false))
{
var opcodeMetadata = InstructionExtensions.StackRequirements(opcode);
opcodeMetadata.InputCount ??= 1;
Expand Down
12 changes: 6 additions & 6 deletions src/Nethermind/Nethermind.Evm/BitmapHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static byte[] CreateCodeBitmap(ReadOnlySpan<byte> code, bool isEof = fals
return bitvec;
}

public static void HandleNumbits(int numbits, byte[] bitvec, scoped ref int pc)
public static void HandleNumbits(int numbits, Span<byte> bitvec, scoped ref int pc)
{
if (numbits >= 8)
{
Expand Down Expand Up @@ -72,17 +72,17 @@ public static void HandleNumbits(int numbits, byte[] bitvec, scoped ref int pc)
/// <summary>
/// Checks if the position is in a code segment.
/// </summary>
public static bool IsCodeSegment(byte[] bitvec, int pos)
public static bool IsCodeSegment(Span<byte> bitvec, int pos)
{
return (bitvec[pos / 8] & (0x80 >> (pos % 8))) == 0;
}

private static void Set1(this byte[] bitvec, int pos)
private static void Set1(this Span<byte> bitvec, int pos)
{
bitvec[pos / 8] |= _lookup[pos % 8];
}

private static void SetN(this byte[] bitvec, int pos, UInt16 flag)
private static void SetN(this Span<byte> bitvec, int pos, UInt16 flag)
{
ushort a = (ushort)(flag >> (pos % 8));
bitvec[pos / 8] |= (byte)(a >> 8);
Expand All @@ -95,14 +95,14 @@ private static void SetN(this byte[] bitvec, int pos, UInt16 flag)
}
}

private static void Set8(this byte[] bitvec, int pos)
private static void Set8(this Span<byte> bitvec, int pos)
{
byte a = (byte)(0xFF >> (pos % 8));
bitvec[pos / 8] |= a;
bitvec[pos / 8 + 1] = (byte)~a;
}

private static void Set16(this byte[] bitvec, int pos)
private static void Set16(this Span<byte> bitvec, int pos)
{
byte a = (byte)(0xFF >> (pos % 8));
bitvec[pos / 8] |= a;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Nethermind.Core.Extensions;
using Nethermind.Evm.EOF;
using Nethermind.Evm.Precompiles;
using static System.Collections.Specialized.BitVector32;

namespace Nethermind.Evm.CodeAnalysis;

Expand Down
Loading

0 comments on commit 486e619

Please sign in to comment.