Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Fix CALLDATACOPY (and bonus CODECOPY, too!).
Browse files Browse the repository at this point in the history
Fixes #269
Fixes #270
Also fix evm debug feature.
  • Loading branch information
gavofyork committed Jan 31, 2016
1 parent 122e1ff commit 0254b36
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ lazy_static = "0.1"

[features]
jit = ["evmjit"]
evm_debug = []
evm-debug = []
test-heavy = []
35 changes: 21 additions & 14 deletions ethcore/src/evm/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,23 +791,30 @@ impl Interpreter {
Ok(InstructionResult::Ok)
}

fn copy_data_to_memory(&self,
mem: &mut Memory,
stack: &mut Stack<U256>,
data: &[u8]) {
let offset = stack.pop_back();
let index = stack.pop_back();
fn copy_data_to_memory(&self, mem: &mut Memory, stack: &mut Stack<U256>, data: &[u8]) {
let dest_offset = stack.pop_back();
let source_offset = stack.pop_back();
let size = stack.pop_back();
let data_size = data.len();
let source_size = U256::from(data.len());

if index < U256::from(data_size) {
let u_index = index.low_u64() as usize;
let bound_size = match size + index > U256::from(data_size) {
true => data_size,
false => size.low_u64() as usize + u_index
};
let output_end = match source_offset > source_size || size > source_size || source_offset + size > source_size {
true => {
let zero_slice = if source_offset > source_size {
mem.writeable_slice(dest_offset, size)
} else {
mem.writeable_slice(dest_offset + source_size - source_offset, source_offset + size - source_size)
};
for i in zero_slice.iter_mut() {
*i = 0;
}
data.len()
},
false => (size.low_u64() + source_offset.low_u64()) as usize
};

mem.write_slice(offset, &data[u_index..bound_size]);
if source_offset < source_size {
let output_begin = source_offset.low_u64() as usize;
mem.write_slice(dest_offset, &data[output_begin..output_end]);
}
}

Expand Down
8 changes: 5 additions & 3 deletions ethcore/src/tests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {

declare_test!{StateTests_stBlockHashTest, "StateTests/stBlockHashTest"}
declare_test!{StateTests_stCallCodes, "StateTests/stCallCodes"}
//declare_test!{StateTests_stCallCreateCallCodeTest, "StateTests/stCallCreateCallCodeTest"}
declare_test!{StateTests_stCallCreateCallCodeTest, "StateTests/stCallCreateCallCodeTest"}
declare_test!{StateTests_stDelegatecallTest, "StateTests/stDelegatecallTest"}
declare_test!{StateTests_stExample, "StateTests/stExample"}
declare_test!{StateTests_stInitCodeTest, "StateTests/stInitCodeTest"}
Expand Down Expand Up @@ -297,7 +297,8 @@ declare_test!{StateTests_RandomTests_st201503181357CPPJIT, "StateTests/RandomTes
declare_test!{StateTests_RandomTests_st201503181358CPPJIT, "StateTests/RandomTests/st201503181358CPPJIT"}
declare_test!{StateTests_RandomTests_st201503181358GO, "StateTests/RandomTests/st201503181358GO"}
declare_test!{StateTests_RandomTests_st201503181359GO, "StateTests/RandomTests/st201503181359GO"}
//declare_test!{StateTests_RandomTests_st201503181402CPPJIT, "StateTests/RandomTests/st201503181402CPPJIT"}
declare_test!{StateTests_RandomTests_st201503181402CPPJIT, "StateTests/RandomTests/st201503181402CPPJIT"}
// ^^^ BROKEN ^^^
declare_test!{StateTests_RandomTests_st201503181403GO, "StateTests/RandomTests/st201503181403GO"}
declare_test!{StateTests_RandomTests_st201503181406CPPJIT, "StateTests/RandomTests/st201503181406CPPJIT"}
declare_test!{StateTests_RandomTests_st201503181406GO, "StateTests/RandomTests/st201503181406GO"}
Expand Down Expand Up @@ -569,7 +570,8 @@ declare_test!{StateTests_RandomTests_st201503181929GO, "StateTests/RandomTests/s
declare_test!{StateTests_RandomTests_st201503181931CPPJIT, "StateTests/RandomTests/st201503181931CPPJIT"}
declare_test!{StateTests_RandomTests_st201503181931GO, "StateTests/RandomTests/st201503181931GO"}
declare_test!{StateTests_RandomTests_st201503181931PYTHON, "StateTests/RandomTests/st201503181931PYTHON"}
//declare_test!{StateTests_RandomTests_st201503191646GO, "StateTests/RandomTests/st201503191646GO"}
declare_test!{StateTests_RandomTests_st201503191646GO, "StateTests/RandomTests/st201503191646GO"}
// ^^^ BROKEN ^^^
declare_test!{StateTests_RandomTests_st201503200837JS, "StateTests/RandomTests/st201503200837JS"}
declare_test!{StateTests_RandomTests_st201503200838JS, "StateTests/RandomTests/st201503200838JS"}
declare_test!{StateTests_RandomTests_st201503200841JS, "StateTests/RandomTests/st201503200841JS"}
Expand Down

0 comments on commit 0254b36

Please sign in to comment.