You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our team at FuzzingLabs discovered a new non-compliance in the current implementation of the op_extcodecopy function in levm, the allocated memory size during the execution of the EXTCODECOPY opcode is not aligned to a multiple of 32 bytes, which is the expected behavior as per EVM standards. For instance, if a size of size = 12 is specified, the function allocates memory of exactly 12 bytes instead of rounding up to 32 bytes.
#[test]fntest_non_compliance_extcodecopy_memory_resize(){letmut vm = new_vm_with_bytecode(Bytes::copy_from_slice(&[0x60,12,0x5f,0x5f,0x5f,0x3c,89])).unwrap();letmut current_call_frame = vm.call_frames.pop().unwrap();
vm.execute(&mut current_call_frame);assert_eq!(current_call_frame.stack.stack[0], U256::from(32));}
Backtrace
thread 'test_non_compliance_extcodecopy_memory_resize' panicked at crates/vm/levm/tests/edge_case_tests.rs:17:5:
assertion `left == right` failed
left:12
right:32
stack backtrace:0: rust_begin_unwind
at /rustc/8adb4b30f40e6fbd21dc1ba26c3301c7eeb6de3c/library/std/src/panicking.rs:665:51: core::panicking::panic_fmt
at /rustc/8adb4b30f40e6fbd21dc1ba26c3301c7eeb6de3c/library/core/src/panicking.rs:76:142: core::panicking::assert_failed_inner3: core::panicking::assert_failed
at /home/mhoste/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panicking.rs:373:54: edge_case_tests::test_non_compliance_extcodecopy_memory_resize
at ./tests/edge_case_tests.rs:17:55: edge_case_tests::test_non_compliance_extcodecopy_memory_resize::{{closure}}
at ./tests/edge_case_tests.rs:11:516: core::ops::function::FnOnce::call_once
at /home/mhoste/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:57: core::ops::function::FnOnce::call_once
at /rustc/8adb4b30f40e6fbd21dc1ba26c3301c7eeb6de3c/library/core/src/ops/function.rs:250:5
note:Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
failures:
test_non_compliance_extcodecopy_memory_resize
test result:FAILED.0 passed;1 failed;0 ignored;0 measured;18 filtered out; finished in0.10s
The text was updated successfully, but these errors were encountered:
**Motivation**
Fixes an implementation error found by
[FuzzingLabs](https://github.com/FuzzingLabs) in extcodecopy opcode
implementation.
**Description**
Previously, in EXTCODECOPY the allocated memory size was not aligned to
a multiple of 32 bytes, and was added in, for example, 12 bytes (should
increase in blocks of 32). Now the increases are done in groups of 32.
Closes#1251
Our team at FuzzingLabs discovered a new non-compliance in the current implementation of the op_extcodecopy function in
levm
, the allocated memory size during the execution of theEXTCODECOPY
opcode is not aligned to a multiple of 32 bytes, which is the expected behavior as per EVM standards. For instance, if a size ofsize = 12
is specified, the function allocates memory of exactly 12 bytes instead of rounding up to 32 bytes.Root cause
Here is the portion of code responsible for this non-compliance:
Memory is resized directly to
size
without considering 32-byte alignment. For example:size = 12
, memory is resized to 12 bytes.size = 64
, memory is correctly resized to 64 bytes (already aligned).However, the EVM specification requires that all memory allocations be aligned to the next multiple of 32 bytes. (explained in this issue)
Step to reproduce
Payload
Add to test :
Backtrace
The text was updated successfully, but these errors were encountered: