Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

fix calldatalen in calldata{copy,load} for contract deployment #1593

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bus-mapping/src/circuit_input_builder/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
};
Expand Down
9 changes: 8 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,14 @@ impl<F: Field> ExecutionGadget<F> for CallDataCopyGadget<F> {

// 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)
};
Expand Down
12 changes: 10 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/calldataload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,15 @@ impl<F: Field> ExecutionGadget<F> for CallDataLoadGadget<F> {

// 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,
Expand Down Expand Up @@ -249,7 +257,7 @@ impl<F: Field> ExecutionGadget<F> for CallDataLoadGadget<F> {
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 {
Expand Down
Loading