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

Commit f5c8682

Browse files
lispcicemelon
andauthored
Fix incorrect current_cumulative_gas_used in end_tx_gadget (#535)
* Fix flakiness in begin_tx_gadget * Update end_tx.rs * Update zkevm-circuits/src/evm_circuit/execution/end_tx.rs Co-authored-by: Haichen Shen <shenhaichen@gmail.com> Co-authored-by: Haichen Shen <shenhaichen@gmail.com>
1 parent f6adca3 commit f5c8682

File tree

1 file changed

+13
-15
lines changed
  • zkevm-circuits/src/evm_circuit/execution

1 file changed

+13
-15
lines changed

zkevm-circuits/src/evm_circuit/execution/end_tx.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,11 @@ impl<F: Field> ExecutionGadget<F> for EndTxGadget<F> {
254254
let current_cumulative_gas_used: u64 = if tx.id == 1 {
255255
0
256256
} else {
257+
// first transaction needs TxReceiptFieldTag::COUNT(3) lookups to tx receipt,
258+
// while later transactions need 4 (with one extra cumulative gas read) lookups
257259
let rw = &block.rws[(
258260
RwTableTag::TxReceipt,
259-
(tx.id - 1) * TxReceiptFieldTag::COUNT - 1,
261+
(tx.id - 2) * (TxReceiptFieldTag::COUNT + 1) + 2,
260262
)];
261263
rw.receipt_value()
262264
};
@@ -280,8 +282,8 @@ mod test {
280282
use crate::evm_circuit::{
281283
test::run_test_circuit_incomplete_fixed_table, witness::block_convert,
282284
};
283-
use eth_types::{self, address, bytecode, geth_types::GethData, Word};
284-
use mock::TestContext;
285+
use eth_types::{self, bytecode, geth_types::GethData};
286+
use mock::{eth, test_ctx::helpers::account_0_code_account_1_no_code, TestContext};
285287

286288
fn test_ok(block: GethData) {
287289
let block_data = bus_mapping::mock::BlockData::new_from_geth_data(block);
@@ -313,26 +315,22 @@ mod test {
313315
// Multiple txs
314316
test_ok(
315317
// Get the execution steps from the external tracer
316-
TestContext::<2, 2>::new(
318+
TestContext::<2, 3>::new(
317319
None,
318-
|accs| {
319-
accs[0]
320-
.address(address!("0x00000000000000000000000000000000000000fe"))
321-
.balance(Word::from(10u64.pow(19)))
322-
.code(bytecode! { STOP });
323-
accs[1]
324-
.address(address!("0x00000000000000000000000000000000000000fd"))
325-
.balance(Word::from(10u64.pow(19)));
326-
},
320+
account_0_code_account_1_no_code(bytecode! { STOP }),
327321
|mut txs, accs| {
328322
txs[0]
329323
.to(accs[0].address)
330324
.from(accs[1].address)
331-
.value(Word::from(10u64.pow(17)));
325+
.value(eth(1));
332326
txs[1]
333327
.to(accs[0].address)
334328
.from(accs[1].address)
335-
.value(Word::from(10u64.pow(17)));
329+
.value(eth(1));
330+
txs[2]
331+
.to(accs[0].address)
332+
.from(accs[1].address)
333+
.value(eth(1));
336334
},
337335
|block, _tx| block.number(0xcafeu64),
338336
)

0 commit comments

Comments
 (0)