Skip to content

Commit

Permalink
do not reverse order of elements on stack
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzSchueler committed Aug 19, 2024
1 parent 8297255 commit 3a30b3b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions cpp/vm/evmzero/evmzero.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,10 @@ class VM : public evmc_vm {
// Copy stack to raw buffer.
evmc_uint256be* stack_data = nullptr;
if (stepping_result.stack.GetSize()) {
stack_data = new evmc_uint256be[stepping_result.stack.GetSize()];
for (size_t i = 0; i < stepping_result.stack.GetSize(); ++i) {
stack_data[i] = ToEvmcBytes(stepping_result.stack[i]);
auto stack_size = stepping_result.stack.GetSize();
stack_data = new evmc_uint256be[stack_size];
for (size_t i = 0; i < stack_size; ++i) {
stack_data[stack_size - 1 - i] = ToEvmcBytes(stepping_result.stack[i]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion go/interpreter/evmc/evmc_steppable_interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func convertEvmcStackToCtStack(stack []byte, result *st.Stack) (*st.Stack, error
return nil, fmt.Errorf("stack size is not a multiple of 32")
}
result.Resize(0)
for i := len(stack) - 32; i >= 0; i -= 32 {
for i := 0; i <= len(stack)-32; i += 32 {
val := common.NewU256FromBytes(stack[i : i+32]...)
result.Push(val)
}
Expand Down
8 changes: 4 additions & 4 deletions go/interpreter/evmc/evmc_steppable_interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ func TestConvertToCt_Stack(t *testing.T) {
0xBA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAD,
},
st.NewStack(
ct.NewU256(0xAB000000000000CD, 0xBA000000000000AD),
ct.NewU256(0xDE000000000000AD, 0xBE000000000000EF, 0, 0)),
ct.NewU256(0xDE000000000000AD, 0xBE000000000000EF, 0, 0),
ct.NewU256(0xAB000000000000CD, 0xBA000000000000AD)),
true}},
"three-elements": {{
[]byte{
Expand All @@ -218,9 +218,9 @@ func TestConvertToCt_Stack(t *testing.T) {
0xBA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAD,
},
st.NewStack(
ct.NewU256(0xAB000000000000CD, 0xBA000000000000AD),
ct.NewU256(0x0001020304050607, 0x0809101112131415, 0x1617181920212223, 0x2425262728293031),
ct.NewU256(0xDE000000000000AD, 0xBE000000000000EF, 0x0000000000000000, 0x0000000000000000),
ct.NewU256(0x0001020304050607, 0x0809101112131415, 0x1617181920212223, 0x2425262728293031)),
ct.NewU256(0xAB000000000000CD, 0xBA000000000000AD)),
true}},
"error": {{
[]byte{
Expand Down

0 comments on commit 3a30b3b

Please sign in to comment.