Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 76989b3

Browse files
authored
fix returndatacopy len (#724)
* fix returndatacopy len * lint
1 parent 8f3e82a commit 76989b3

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

bus-mapping/src/circuit_input_builder.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl<'a> CircuitInputBuilder {
525525
state_ref.call().map(|c| c.call_id).unwrap_or(0),
526526
state_ref.call_ctx()?.memory.len(),
527527
if geth_step.op.is_push_with_data() {
528-
format!("{:?}", geth_trace.struct_logs[index + 1].stack.last())
528+
format!("{:?}", geth_trace.struct_logs.get(index + 1).map(|step| step.stack.last()))
529529
} else if geth_step.op.is_call_without_value() {
530530
format!(
531531
"{:?} {:40x} {:?} {:?} {:?} {:?}",
@@ -577,7 +577,13 @@ impl<'a> CircuitInputBuilder {
577577
geth_step.stack.nth_last(0),
578578
geth_step.stack.nth_last(1),
579579
)
580-
} else {
580+
} else if matches!(geth_step.op, OpcodeId::RETURN) {
581+
format!(
582+
"{:?} {:?}",
583+
geth_step.stack.nth_last(0),
584+
geth_step.stack.nth_last(1),
585+
)
586+
} else {
581587
"".to_string()
582588
}
583589
);

bus-mapping/src/circuit_input_builder/input_state_ref.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1316,10 +1316,17 @@ impl<'a> CircuitInputStateRef<'a> {
13161316
} else {
13171317
0
13181318
};
1319-
geth_step.gas.0 - memory_expansion_gas_cost - code_deposit_cost
1319+
geth_step.gas.0
1320+
- memory_expansion_gas_cost
1321+
- code_deposit_cost
1322+
- if geth_step.op == OpcodeId::SELFDESTRUCT {
1323+
GasCost::SELFDESTRUCT.as_u64()
1324+
} else {
1325+
0
1326+
}
13201327
};
13211328

1322-
let caller_gas_left = geth_step_next.gas.0 - gas_refund;
1329+
let caller_gas_left = geth_step_next.gas.0.checked_sub(gas_refund).unwrap_or_else(|| panic!("caller_gas_left underflow geth_step_next.gas {:?}, gas_refund {:?}, exec_step {:?}, geth_step {:?}", geth_step_next.gas.0, gas_refund, exec_step, geth_step));
13231330

13241331
for (field, value) in [
13251332
(CallContextField::IsRoot, (caller.is_root as u64).into()),

bus-mapping/src/evm/opcodes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,6 @@ fn dummy_gen_selfdestruct_ops(
10901090
state.sdb.destruct_account(sender);
10911091
}
10921092

1093-
state.handle_return(&mut exec_step, geth_steps, false)?;
1093+
state.handle_return(&mut exec_step, geth_steps, true)?;
10941094
Ok(vec![exec_step])
10951095
}

bus-mapping/src/evm/opcodes/returndatacopy.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ fn gen_returndatacopy_step(
6363
(CallContextField::LastCalleeId, last_callee_id.into()),
6464
(
6565
CallContextField::LastCalleeReturnDataOffset,
66-
last_callee_return_data_offset.into(),
66+
if return_data_len == 0 {
67+
0.into()
68+
} else {
69+
last_callee_return_data_offset.into()
70+
},
6771
),
6872
(
6973
CallContextField::LastCalleeReturnDataLength,

integration-tests/tests/mainnet.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ fn test_with<C: SubCircuit<Fr> + Circuit<Fr>>(block: &witness::Block<Fr>) -> Moc
9393
MockProver::<Fr>::run(k, &circuit, circuit.instance()).unwrap()
9494
}
9595
fn test_witness_block(block: &witness::Block<Fr>) -> Vec<VerifyFailure> {
96+
if *CIRCUIT == "none" {
97+
return Vec::new();
98+
}
9699
let prover = if *CIRCUIT == "evm" {
97100
test_with::<EvmCircuit<Fr>>(block)
98101
} else if *CIRCUIT == "copy" {
@@ -153,7 +156,7 @@ async fn test_circuit_all_block() {
153156
return;
154157
}
155158

156-
let block = block_convert(&builder.block, &builder.code_db).unwrap();
159+
let block = block_convert::<Fr>(&builder.block, &builder.code_db).unwrap();
157160
let errs = test_witness_block(&block);
158161
log::info!(
159162
"test {} circuit, block number: {} err num {:?}",

0 commit comments

Comments
 (0)