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

Commit

Permalink
fix calldatalen in calldata{copy,load} for contract deployment (#1593)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
lispc authored Sep 12, 2023
1 parent 0d42a87 commit 15b92fa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
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

0 comments on commit 15b92fa

Please sign in to comment.