diff --git a/crates/chisel/src/executor.rs b/crates/chisel/src/executor.rs index b4b33bfca8ccc..f9cd04af13f6a 100644 --- a/crates/chisel/src/executor.rs +++ b/crates/chisel/src/executor.rs @@ -152,11 +152,17 @@ impl SessionSource { // the file compiled correctly, thus the last stack item must be the memory offset of // the `bytes memory inspectoor` value - let mut offset = stack.last().unwrap().to::(); - let mem_offset = &memory[offset..offset + 32]; - let len = U256::try_from_be_slice(mem_offset).unwrap().to::(); - offset += 32; - let data = &memory[offset..offset + len]; + let data = (|| -> Option<_> { + let mut offset: usize = stack.last()?.try_into().ok()?; + debug!("inspect memory @ {offset}: {}", hex::encode(memory)); + let mem_offset = memory.get(offset..offset + 32)?; + let len: usize = U256::try_from_be_slice(mem_offset)?.try_into().ok()?; + offset += 32; + memory.get(offset..offset + len) + })(); + let Some(data) = data else { + eyre::bail!("Failed to inspect last expression: could not retrieve data from memory") + }; let token = ty.abi_decode(data).wrap_err("Could not decode inspected values")?; let c = if should_continue(contract_expr) { ControlFlow::Continue(())