From e728269ee2a1fccbbb3761385819877ea75732ab Mon Sep 17 00:00:00 2001 From: scooletz Date: Fri, 10 Jan 2025 14:27:52 +0100 Subject: [PATCH] pushbytes fixed --- src/Nethermind/Nethermind.Evm/EvmStack.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Evm/EvmStack.cs b/src/Nethermind/Nethermind.Evm/EvmStack.cs index 4bf0420dbf4..2d5ffccceb6 100644 --- a/src/Nethermind/Nethermind.Evm/EvmStack.cs +++ b/src/Nethermind/Nethermind.Evm/EvmStack.cs @@ -54,12 +54,25 @@ public ref Word PushRef() [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref UInt256 PushRefAsUInt256() => ref Unsafe.As(ref PushRef()); + public void PushBytes(scoped ReadOnlySpan value) { if (typeof(TTracing) == typeof(IsTracing)) _tracer.ReportStackPush(value); ref Word top = ref PushRef(); - top = Unsafe.As(ref MemoryMarshal.GetReference(value)); + if (value.Length != WordSize) + { + // Not full entry, clear first. + top = default; + var offset = WordSize - value.Length; + value.CopyTo(MemoryMarshal.CreateSpan(ref Unsafe.Add(ref Unsafe.As(ref top), offset), + value.Length)); + } + else + { + top = Unsafe.As(ref MemoryMarshal.GetReference(value)); + } + Reshuffle(ref top); }