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

Commit fd2be1c

Browse files
kunxian-xiaroynalnarutolispc
authored andcommitted
Fix the bugs in RLP/Tx/PI circuit which are reported by Zellic & KALOS auditors (#572)
* fix finding 3 (#575) * Fix zellic finding 4 (#576) * fix finding 3 (#575) * fix finding 4 --------- Co-authored-by: Rohit Narurkar <rohit.narurkar@protonmail.com> * add range check on diffs (#586) * Fix finding 10 (#578) * fix finding 3 (#575) * fix finding 10 * Fix finding 13 (#579) * fix finding 3 (#575) * fix finding 13 * Fix zellic finding 14 (#580) * fix finding 3 (#575) * fix finding 14 * Fix zellic finding 5 (#584) * fix finding 3 (#575) * fix finding 5 * refine comments * fmt * Fix finding 17 (#602) * add q_last * fix * add more diff range check * fix finding 7 (#625) * tx_id = 1 when sm starts * Fix finding 11 : use length for rlc in rlp table (#719) * fix: use tag_bytes_rlc and tag_length to copy tag's bytes around * fix lookup input for Len & RLC & GasCost fields in tx circuit * refactor * fix * refactor * fix col phase issue * refactor bytes_rlc type * Fix the bugs in Tx & PI circuits reported by Zellic & KALOS auditors (#612) * lookup chain_id to RLP table * fix finding 22 (#614) * fix finding 21 (#613) * fix finding 23 (#618) * fix finding 26 (#622) * fix finding 28 (#624) Co-authored-by: Rohit Narurkar <rohit.narurkar@protonmail.com> * fix finding 29 (#623) Co-authored-by: Rohit Narurkar <rohit.narurkar@protonmail.com> * enforce is_final is true at the last row and fix RLC related vul (#735) * Fix finding 30 (#733) * enforce all txs in a block are included in the tx table * clippy --------- Co-authored-by: Rohit Narurkar <rohit.narurkar@protonmail.com> * Fix Zellic / Kalos finding25 (#619) * fix finding 25 * add comment --------- Co-authored-by: Rohit Narurkar <rohit.narurkar@protonmail.com> * fix conflicts --------- Co-authored-by: Rohit Narurkar <rohit.narurkar@protonmail.com> Co-authored-by: Zhang Zhuo <mycinbrin@gmail.com> * use q_first instead * fmt --------- Co-authored-by: Rohit Narurkar <rohit.narurkar@protonmail.com> Co-authored-by: Zhang Zhuo <mycinbrin@gmail.com>
1 parent 80d0c37 commit fd2be1c

File tree

9 files changed

+747
-117
lines changed

9 files changed

+747
-117
lines changed

eth-types/src/geth_types.rs

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ impl TxType {
5252
matches!(*self, TxType::L1Msg)
5353
}
5454

55+
/// If this type is Eip155 or not
56+
pub fn is_eip155_tx(&self) -> bool {
57+
matches!(*self, TxType::Eip155)
58+
}
59+
5560
/// Get the type of transaction
5661
pub fn get_tx_type(tx: &crate::Transaction) -> Self {
5762
match tx.transaction_type {

zkevm-circuits/src/pi_circuit.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,11 @@ impl<F: Field> PiCircuitConfig<F> {
13791379
Coinbase, Timestamp, Number, Difficulty, GasLimit, BaseFee, ChainId, NumTxs,
13801380
CumNumTxs, NumAllTxs,
13811381
];
1382+
1383+
// index_cells of same block are equal to block_number.
1384+
let mut index_cells = vec![];
1385+
let mut block_number_cell = None;
1386+
13821387
let mut cum_num_txs_field = F::from(cum_num_txs as u64);
13831388
cum_num_txs += num_txs;
13841389
for (row, tag) in block_ctx
@@ -1392,9 +1397,6 @@ impl<F: Field> PiCircuitConfig<F> {
13921397
offset,
13931398
|| row[0],
13941399
)?;
1395-
// index_cells of same block are equal to block_number.
1396-
let mut index_cells = vec![];
1397-
let mut block_number_cell = None;
13981400
for (column, value) in block_table_columns.iter().zip_eq(&row[1..]) {
13991401
let cell = region.assign_advice(
14001402
|| format!("block table row {offset}"),
@@ -1412,15 +1414,6 @@ impl<F: Field> PiCircuitConfig<F> {
14121414
block_value_cells.push(cell);
14131415
}
14141416
}
1415-
for i in 0..(index_cells.len() - 1) {
1416-
region.constrain_equal(index_cells[i].cell(), index_cells[i + 1].cell())?;
1417-
}
1418-
if *tag == Number {
1419-
region.constrain_equal(
1420-
block_number_cell.unwrap().cell(),
1421-
index_cells[0].cell(),
1422-
)?;
1423-
}
14241417

14251418
region.assign_fixed(
14261419
|| "is_block_num_txs",
@@ -1460,6 +1453,12 @@ impl<F: Field> PiCircuitConfig<F> {
14601453
}
14611454
offset += 1;
14621455
}
1456+
// block_num == index[0]
1457+
region.constrain_equal(block_number_cell.unwrap().cell(), index_cells[0].cell())?;
1458+
// index[i] == index[i+1]
1459+
for i in 0..(index_cells.len() - 1) {
1460+
region.constrain_equal(index_cells[i].cell(), index_cells[i + 1].cell())?;
1461+
}
14631462
}
14641463

14651464
Ok(block_value_cells)

0 commit comments

Comments
 (0)