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

Fix the bugs in Tx & PI circuits reported by Zellic & KALOS auditors #612

Merged
merged 14 commits into from
Aug 16, 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
5 changes: 5 additions & 0 deletions eth-types/src/geth_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ impl TxType {
matches!(*self, TxType::L1Msg)
}

/// If this type is Eip155 or not
pub fn is_eip155_tx(&self) -> bool {
matches!(*self, TxType::Eip155)
}

/// Get the type of transaction
pub fn get_tx_type(tx: &crate::Transaction) -> Self {
match tx.transaction_type {
Expand Down
23 changes: 11 additions & 12 deletions zkevm-circuits/src/pi_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,11 @@ impl<F: Field> PiCircuitConfig<F> {
Coinbase, Timestamp, Number, Difficulty, GasLimit, BaseFee, ChainId, NumTxs,
CumNumTxs,
];

// index_cells of same block are equal to block_number.
let mut index_cells = vec![];
let mut block_number_cell = None;

let mut cum_num_txs_field = F::from(cum_num_txs as u64);
cum_num_txs += num_txs;
for (row, tag) in block_ctx
Expand All @@ -1384,9 +1389,6 @@ impl<F: Field> PiCircuitConfig<F> {
offset,
|| row[0],
)?;
// index_cells of same block are equal to block_number.
let mut index_cells = vec![];
let mut block_number_cell = None;
for (column, value) in block_table_columns.iter().zip_eq(&row[1..]) {
let cell = region.assign_advice(
|| format!("block table row {offset}"),
Expand All @@ -1404,15 +1406,6 @@ impl<F: Field> PiCircuitConfig<F> {
block_value_cells.push(cell);
}
}
for i in 0..(index_cells.len() - 1) {
region.constrain_equal(index_cells[i].cell(), index_cells[i + 1].cell())?;
}
if *tag == Number {
region.constrain_equal(
block_number_cell.unwrap().cell(),
index_cells[0].cell(),
)?;
}

region.assign_fixed(
|| "is_block_num_txs",
Expand Down Expand Up @@ -1452,6 +1445,12 @@ impl<F: Field> PiCircuitConfig<F> {
}
offset += 1;
}
// block_num == index[0]
region.constrain_equal(block_number_cell.unwrap().cell(), index_cells[0].cell())?;
// index[i] == index[i+1]
for i in 0..(index_cells.len() - 1) {
region.constrain_equal(index_cells[i].cell(), index_cells[i + 1].cell())?;
}
}

Ok(block_value_cells)
Expand Down
Loading