Fixing CALLDATALOAD

This commit is contained in:
Tomusdrw 2016-01-15 20:14:16 +01:00
parent 46ecb16191
commit 51f828ac37
2 changed files with 22 additions and 12 deletions

View File

@ -565,9 +565,15 @@ impl Interpreter {
}, },
instructions::CALLDATALOAD => { instructions::CALLDATALOAD => {
let id = stack.pop_back().low_u64() as usize; let id = stack.pop_back().low_u64() as usize;
let mut v = params.data[id..id+32].to_vec(); let max = id.wrapping_add(32);
v.resize(32, 0); let bound = cmp::min(params.data.len(), max);
stack.push(U256::from(&v[..])) if id < bound {
let mut v = params.data[id..bound].to_vec();
v.resize(32, 0);
stack.push(U256::from(&v[..]))
} else {
stack.push(U256::zero())
}
}, },
instructions::CALLDATASIZE => { instructions::CALLDATASIZE => {
stack.push(U256::from(params.data.len())); stack.push(U256::from(params.data.len()));
@ -626,16 +632,20 @@ impl Interpreter {
stack: &mut Stack<U256>, stack: &mut Stack<U256>,
data: &Bytes) { data: &Bytes) {
let offset = stack.pop_back(); let offset = stack.pop_back();
let index = stack.pop_back().low_u64() as usize; let index = stack.pop_back();
let size = stack.pop_back().low_u64() as usize; let size = stack.pop_back();
let data_size = data.len(); let data_size = data.len();
let bound_size = if size + index > data_size {
data_size
} else {
size + index
};
mem.write_slice(offset, &data[index..bound_size]); if index < U256::from(data_size) {
let u_index = index.low_u64() as usize;
let bound_size = if size + index > U256::from(data_size) {
data_size
} else {
size.low_u64() as usize + u_index
};
mem.write_slice(offset, &data[u_index..bound_size]);
}
} }
fn verify_instructions_requirements(&self, fn verify_instructions_requirements(&self,

View File

@ -168,7 +168,7 @@ fn do_json_test_for(vm: &VMType, json_data: &[u8]) -> Vec<String> {
let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid"); let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
let mut failed = Vec::new(); let mut failed = Vec::new();
for (name, test) in json.as_object().unwrap() { for (name, test) in json.as_object().unwrap() {
// if name != "byte0" { // if name != "calldataload0" {
// continue; // continue;
// } // }
println!("name: {:?}", name); println!("name: {:?}", name);