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
pubfnop_blobhash(&mutself,current_call_frame:&mutCallFrame,) -> Result<OpcodeSuccess,VMError>{self.increase_consumed_gas(current_call_frame, gas_cost::BLOBHASH)?;let index = current_call_frame.stack.pop()?.as_usize();let blob_hash:H256 = match&self.env.tx_blob_hashes{Some(vec) => match vec.get(index){Some(el) => *el,None => {returnErr(VMError::BlobHashIndexOutOfBounds);}},None => {returnErr(VMError::MissingBlobHashes);}};// Could not find a better way to translate from H256 to U256let u256_blob = U256::from(blob_hash.as_bytes());
current_call_frame.stack.push(u256_blob)?;Ok(OpcodeSuccess::Continue)}
let index = current_call_frame.stack.pop()?.as_usize(); We can give a value greater than usize's maximum length to trigger an overflow because stack.pop() will return a U256.
#[test]fntest_usize_overflow_blobhash(){letmut vm = new_vm_with_bytecode(Bytes::copy_from_slice(&[71,73]));letmut current_call_frame = vm.call_frames.pop().unwrap();
vm.execute(&mut current_call_frame);}
Backtrace
---- tests::test_usize_overflow_blobhash stdout ----
thread 'tests::test_usize_overflow_blobhash' panicked at /home/.../.cargo/registry/src/index.crates.io-6f17d22bba15001f/primitive-types-0.12.2/src/lib.rs:38:1:Integer overflow when casting to usize
stack backtrace:0: rust_begin_unwind
at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/std/src/panicking.rs:658:51: core::panicking::panic_fmt
at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/core/src/panicking.rs:74:142: primitive_types::U256::as_usize
at /home/mhoste/.cargo/registry/src/index.crates.io-6f17d22bba15001f/uint-0.9.5/src/uint.rs:661:63: ethereum_rust_levm::opcode_handlers::block::<impl ethereum_rust_levm::vm::VM>::op_blobhash
at ./src/opcode_handlers/block.rs:167:214: ethereum_rust_levm::vm::VM::execute
at ./src/vm.rs:186:375: lib::tests::test_usize_overflow_blobhash
at ./tests/tests.rs:103:56: lib::tests::test_usize_overflow_blobhash::{{closure}}
at ./tests/tests.rs:100:347: core::ops::function::FnOnce::call_once
at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/core/src/ops/function.rs:250:58: core::ops::function::FnOnce::call_once
at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/core/src/ops/function.rs:250:5
The text was updated successfully, but these errors were encountered:
Our team at https://github.com/FuzzingLabs discovered a bug in the op_blobhash function, this bug can lead to a panic when casting to usize.
Root cause
let index = current_call_frame.stack.pop()?.as_usize();
We can give a value greater than usize's maximum length to trigger an overflow because stack.pop() will return a U256.Step to reproduce
Payload
Add to [test](https://github.com/lambdaclass/lambda_ethereum_rust/blob/main/crates/vm/levm/tests/tests.rs) :
Backtrace
The text was updated successfully, but these errors were encountered: