From 0254b36dc17ee5e727f97c91b1fb2d4cdafb7f21 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 31 Jan 2016 22:47:24 +0100 Subject: [PATCH 1/2] Fix CALLDATACOPY (and bonus CODECOPY, too!). Fixes #269 Fixes #270 Also fix evm debug feature. --- ethcore/Cargo.toml | 2 +- ethcore/src/evm/interpreter.rs | 35 ++++++++++++++++++++-------------- ethcore/src/tests/state.rs | 8 +++++--- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index ef8111272..92236bd93 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -26,5 +26,5 @@ lazy_static = "0.1" [features] jit = ["evmjit"] -evm_debug = [] +evm-debug = [] test-heavy = [] diff --git a/ethcore/src/evm/interpreter.rs b/ethcore/src/evm/interpreter.rs index 7657b1bbe..f55b94adb 100644 --- a/ethcore/src/evm/interpreter.rs +++ b/ethcore/src/evm/interpreter.rs @@ -791,23 +791,30 @@ impl Interpreter { Ok(InstructionResult::Ok) } - fn copy_data_to_memory(&self, - mem: &mut Memory, - stack: &mut Stack, - data: &[u8]) { - let offset = stack.pop_back(); - let index = stack.pop_back(); + fn copy_data_to_memory(&self, mem: &mut Memory, stack: &mut Stack, 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]); } } diff --git a/ethcore/src/tests/state.rs b/ethcore/src/tests/state.rs index 1956ed91f..a39953199 100644 --- a/ethcore/src/tests/state.rs +++ b/ethcore/src/tests/state.rs @@ -84,7 +84,7 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec { 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"} @@ -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"} @@ -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"} From 5ef9e9d55ffe81065843dce6eddf0bb02cc38c82 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 31 Jan 2016 23:48:13 +0100 Subject: [PATCH 2/2] Remove invalid comments. Reorder Stage 4 verification to check easier things first. --- ethcore/src/tests/state.rs | 2 -- ethcore/src/verification.rs | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ethcore/src/tests/state.rs b/ethcore/src/tests/state.rs index a39953199..947782e8f 100644 --- a/ethcore/src/tests/state.rs +++ b/ethcore/src/tests/state.rs @@ -298,7 +298,6 @@ declare_test!{StateTests_RandomTests_st201503181358CPPJIT, "StateTests/RandomTes declare_test!{StateTests_RandomTests_st201503181358GO, "StateTests/RandomTests/st201503181358GO"} declare_test!{StateTests_RandomTests_st201503181359GO, "StateTests/RandomTests/st201503181359GO"} 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"} @@ -571,7 +570,6 @@ declare_test!{StateTests_RandomTests_st201503181931CPPJIT, "StateTests/RandomTes declare_test!{StateTests_RandomTests_st201503181931GO, "StateTests/RandomTests/st201503181931GO"} declare_test!{StateTests_RandomTests_st201503181931PYTHON, "StateTests/RandomTests/st201503181931PYTHON"} 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"} diff --git a/ethcore/src/verification.rs b/ethcore/src/verification.rs index 368ff84e9..020f1b40f 100644 --- a/ethcore/src/verification.rs +++ b/ethcore/src/verification.rs @@ -147,14 +147,14 @@ pub fn verify_block_final(expected: &Header, got: &Header) -> Result<(), Error> if expected.gas_used != got.gas_used { return Err(From::from(BlockError::InvalidGasUsed(Mismatch { expected: expected.gas_used, found: got.gas_used }))) } - if expected.receipts_root != got.receipts_root { - return Err(From::from(BlockError::InvalidReceiptsStateRoot(Mismatch { expected: expected.receipts_root.clone(), found: got.receipts_root.clone() }))) + if expected.log_bloom != got.log_bloom { + return Err(From::from(BlockError::InvalidLogBloom(Mismatch { expected: expected.log_bloom.clone(), found: got.log_bloom.clone() }))) } if expected.state_root != got.state_root { return Err(From::from(BlockError::InvalidStateRoot(Mismatch { expected: expected.state_root.clone(), found: got.state_root.clone() }))) } - if expected.log_bloom != got.log_bloom { - return Err(From::from(BlockError::InvalidLogBloom(Mismatch { expected: expected.log_bloom.clone(), found: got.log_bloom.clone() }))) + if expected.receipts_root != got.receipts_root { + return Err(From::from(BlockError::InvalidReceiptsStateRoot(Mismatch { expected: expected.receipts_root.clone(), found: got.receipts_root.clone() }))) } Ok(()) }