From 7bb963f866b533c5cfd07246f2da66a5f95bb5bf Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Fri, 15 Jan 2016 20:19:46 +0100 Subject: [PATCH] Fixing CALLDATALOAD for big indexes --- src/evm/interpreter.rs | 5 +++-- src/tests/executive.rs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/evm/interpreter.rs b/src/evm/interpreter.rs index 00cb83351..ac2f092e6 100644 --- a/src/evm/interpreter.rs +++ b/src/evm/interpreter.rs @@ -564,10 +564,11 @@ impl Interpreter { stack.push(params.value.clone()); }, instructions::CALLDATALOAD => { - let id = stack.pop_back().low_u64() as usize; + let big_id = stack.pop_back(); + let id = big_id.low_u64() as usize; let max = id.wrapping_add(32); let bound = cmp::min(params.data.len(), max); - if id < bound { + if id < bound && big_id < U256::from(params.data.len()) { let mut v = params.data[id..bound].to_vec(); v.resize(32, 0); stack.push(U256::from(&v[..])) diff --git a/src/tests/executive.rs b/src/tests/executive.rs index 5c4ba152a..68cc65c10 100644 --- a/src/tests/executive.rs +++ b/src/tests/executive.rs @@ -168,7 +168,7 @@ fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec { let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid"); let mut failed = Vec::new(); for (name, test) in json.as_object().unwrap() { - // if name != "calldataload0" { + // if name != "calldataload_BigOffset" { // continue; // } println!("name: {:?}", name);