From 15b92fa15a6c6ae186473cd0aa3015a4f3dfb8b8 Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Tue, 12 Sep 2023 22:50:39 +0800 Subject: [PATCH] fix calldatalen in calldata{copy,load} for contract deployment (#1593) ### Description The 'calldata' for a call with Kind::Create/Ceate2, should always be empty. We handled this correctly for create/create2 opcode. But for tx.to == None deployment, it was wrong. This PR fixes this problem. ### Issue Link [_link issue here_] ### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update --- bus-mapping/src/circuit_input_builder/transaction.rs | 2 +- .../src/evm_circuit/execution/calldatacopy.rs | 9 ++++++++- .../src/evm_circuit/execution/calldataload.rs | 12 ++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/bus-mapping/src/circuit_input_builder/transaction.rs b/bus-mapping/src/circuit_input_builder/transaction.rs index 7016c0a7dc7..9b86e197e11 100644 --- a/bus-mapping/src/circuit_input_builder/transaction.rs +++ b/bus-mapping/src/circuit_input_builder/transaction.rs @@ -241,7 +241,7 @@ impl Transaction { code_hash, depth: 1, value: eth_tx.value, - call_data_length: eth_tx.input.len().try_into().unwrap(), + call_data_length: 0, ..Default::default() } }; diff --git a/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs b/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs index e31047b09b9..f7d9a762400 100644 --- a/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs @@ -199,7 +199,14 @@ impl ExecutionGadget for CallDataCopyGadget { // Call data length and call data offset let (call_data_length, call_data_offset) = if call.is_root { - (tx.call_data.len() as u64, 0_u64) + ( + if tx.is_create() { + 0 + } else { + tx.call_data.len() as u64 + }, + 0_u64, + ) } else { (call.call_data_length, call.call_data_offset) }; diff --git a/zkevm-circuits/src/evm_circuit/execution/calldataload.rs b/zkevm-circuits/src/evm_circuit/execution/calldataload.rs index d7b0aba51a6..ff0890bb8fe 100644 --- a/zkevm-circuits/src/evm_circuit/execution/calldataload.rs +++ b/zkevm-circuits/src/evm_circuit/execution/calldataload.rs @@ -213,7 +213,15 @@ impl ExecutionGadget for CallDataLoadGadget { // Assign to the buffer reader gadget. let (src_id, call_data_offset, call_data_length) = if call.is_root { - (tx.id, 0, tx.call_data.len() as u64) + ( + tx.id, + 0, + if tx.is_create() { + 0 + } else { + tx.call_data.len() as u64 + }, + ) } else { ( call.caller_id as u64, @@ -249,7 +257,7 @@ impl ExecutionGadget for CallDataLoadGadget { for (i, byte) in calldata_bytes.iter_mut().enumerate() { if call.is_root { // Fetch from tx call data. - if src_addr + (i as u64) < tx.call_data.len() as u64 { + if src_addr + (i as u64) < call_data_length { *byte = tx.call_data[src_addr as usize + i]; } } else {