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

Fix zellic / kalos finding 29 #623

Merged
merged 2 commits into from
Aug 9, 2023
Merged
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
23 changes: 11 additions & 12 deletions zkevm-circuits/src/pi_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,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 @@ -1317,9 +1322,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 @@ -1337,15 +1339,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 @@ -1383,6 +1376,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