Skip to content

Commit

Permalink
Only update trace memory clear by amount cleared (#6644)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Jan 31, 2024
1 parent f0ea7fc commit a33a8b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Nethermind/Nethermind.Evm.Test/EvmPooledMemoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ public void GetTrace_memory_should_not_bleed_between_txs()
Assert.That(b, Is.EqualTo(a));
}

[Test]
public void GetTrace_memory_should_not_overflow()
{
var input = new byte[] {
0x5b, 0x59, 0x60, 0x20, 0x59, 0x81, 0x91, 0x52, 0x44, 0x36, 0x5a, 0x3b,
0x59, 0xf4, 0x5b, 0x31, 0x56, 0x08};
run(input);
}

private static PrivateKey PrivateKeyD = new("0000000000000000000000000000000000000000000000000000001000000000");
private static Address sender = new Address("0x59ede65f910076f60e07b2aeb189c72348525e72");

Expand Down
6 changes: 5 additions & 1 deletion src/Nethermind/Nethermind.Evm/EvmPooledMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private void ClearForTracing(ulong size)
{
int lengthToClear = (int)(Math.Min(size, (ulong)_memory.Length) - _lastZeroedSize);
Array.Clear(_memory, (int)_lastZeroedSize, lengthToClear);
_lastZeroedSize = size;
_lastZeroedSize += (uint)lengthToClear;
}
}

Expand Down Expand Up @@ -307,6 +307,10 @@ private void UpdateSize(ulong length, bool rentIfNeeded = true)
{
Array.Clear(_memory, lastZeroedSize, (int)(Size - _lastZeroedSize));
}
else
{
return;
}
}

_lastZeroedSize = Size;
Expand Down

0 comments on commit a33a8b9

Please sign in to comment.