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

fix finding 24 #656

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion zkevm-circuits/src/rlp_circuit_fsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ pub struct RlpCircuitConfig<F> {
/// ROM table
rom_table: RlpFsmRomTable,
/// Range256 table
range256_table: Range256Table,
pub(crate) range256_table: Range256Table,
}

impl<F: Field> RlpCircuitConfig<F> {
Expand Down
1 change: 1 addition & 0 deletions zkevm-circuits/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ impl SubCircuitConfig<Fr> for SuperCircuitConfig<Fr> {
block_table: block_table.clone(),
tx_table: tx_table.clone(),
keccak_table: keccak_table.clone(),
u8_table: rlp_circuit.range256_table.clone(),
rlp_table,
sig_table,
challenges: challenges_expr.clone(),
Expand Down
32 changes: 31 additions & 1 deletion zkevm-circuits/src/tx_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use gadgets::{
util::{and, not, select, sum, Expr},
};
use halo2_proofs::{
circuit::{Layouter, Region, Value},
circuit::{Chip, Layouter, Region, Value},
plonk::{Advice, Column, ConstraintSystem, Error, Expression, VirtualCells},
poly::Rotation,
};
Expand All @@ -58,6 +58,7 @@ use halo2_proofs::plonk::SecondPhase;
use halo2_proofs::plonk::{Fixed, TableColumn};

use crate::{
rlp_circuit_fsm::Range256Table,
table::{BlockContextFieldTag::CumNumTxs, TxFieldTag::ChainID},
util::rlc_be_bytes,
witness::{
Expand Down Expand Up @@ -153,6 +154,7 @@ pub struct TxCircuitConfig<F: Field> {
block_table: BlockTable,
rlp_table: RlpTable,
keccak_table: KeccakTable,
u8_table: Range256Table,

_marker: PhantomData<F>,
}
Expand All @@ -167,6 +169,8 @@ pub struct TxCircuitConfigArgs<F: Field> {
pub keccak_table: KeccakTable,
/// RlpTable
pub rlp_table: RlpTable,
/// Range256 Table
pub u8_table: Range256Table,
/// SigTable
pub sig_table: SigTable,
/// Challenges
Expand All @@ -185,6 +189,7 @@ impl<F: Field> SubCircuitConfig<F> for TxCircuitConfig<F> {
keccak_table,
rlp_table,
sig_table,
u8_table,
challenges,
}: Self::ConfigArgs,
) -> Self {
Expand Down Expand Up @@ -715,6 +720,30 @@ impl<F: Field> SubCircuitConfig<F> for TxCircuitConfig<F> {
|meta| meta.query_advice(cum_num_txs, Rotation::cur()),
);

meta.lookup("tx_id is in u16", |meta| {
let tx_id = meta.query_advice(tx_table.tx_id, Rotation::cur());
let q_enable = meta.query_fixed(q_enable, Rotation::cur());

vec![(q_enable * tx_id, u16_table)]
});

meta.lookup("cum_num_txs is in u16", |meta| {
let cum_num_txs = meta.query_advice(cum_num_txs, Rotation::cur());
let q_enable = meta.query_fixed(q_enable, Rotation::cur());

vec![(q_enable * cum_num_txs, u16_table)]
});

for diff in tx_id_cmp_cum_num_txs.lt_chip.config().diff {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want the overall diff to be a byte, right?

Here you've constrained that each diff cell is a byte, which is already constrained within the LtGadget here:
https://github.com/scroll-tech/zkevm-circuits/blob/develop/gadgets/src/less_than.rs#L97-L105

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add this because the range checks of each diff cell are not there when the auditing is done. Yeah, we should remove these redundant checks.

meta.lookup_any("comparator diff must be in u8", |meta| {
let q_enable = meta.query_fixed(q_enable, Rotation::cur());
let diff = meta.query_advice(diff, Rotation::cur());
let u8_table = u8_table.table_exprs(meta);

vec![(q_enable * diff, u8_table[0].clone())]
});
}

meta.create_gate("tx_id <= cum_num_txs", |meta| {
let mut cb = BaseConstraintBuilder::default();

Expand Down Expand Up @@ -978,6 +1007,7 @@ impl<F: Field> SubCircuitConfig<F> for TxCircuitConfig<F> {
tx_table,
keccak_table,
rlp_table,
u8_table,
is_tag_block_num,
_marker: PhantomData,
}
Expand Down
6 changes: 6 additions & 0 deletions zkevm-circuits/src/tx_circuit/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::get_sign_data;
pub use super::TxCircuit;

use crate::{
rlp_circuit_fsm::Range256Table,
sig_circuit::{SigCircuit, SigCircuitConfig, SigCircuitConfigArgs},
table::{BlockTable, KeccakTable, RlpFsmRlpTable as RlpTable, SigTable, TxTable},
tx_circuit::{TxCircuitConfig, TxCircuitConfigArgs},
Expand Down Expand Up @@ -63,6 +64,7 @@ impl<F: Field> SubCircuitConfig<F> for TxCircuitTesterConfig<F> {
keccak_table: keccak_table.clone(),
},
);
let u8_table = Range256Table::construct(meta);
let tx_config = TxCircuitConfig::new(
meta,
TxCircuitConfigArgs {
Expand All @@ -71,6 +73,7 @@ impl<F: Field> SubCircuitConfig<F> for TxCircuitTesterConfig<F> {
tx_table,
keccak_table,
rlp_table,
u8_table,
challenges,
},
);
Expand Down Expand Up @@ -155,6 +158,7 @@ impl<F: Field> Circuit<F> for TxCircuitTester<F> {
keccak_table: keccak_table.clone(),
},
);
let u8_table = Range256Table::construct(meta);
let tx_config = TxCircuitConfig::new(
meta,
TxCircuitConfigArgs {
Expand All @@ -163,6 +167,7 @@ impl<F: Field> Circuit<F> for TxCircuitTester<F> {
tx_table,
keccak_table,
rlp_table,
u8_table,
challenges,
},
);
Expand Down Expand Up @@ -215,6 +220,7 @@ impl<F: Field> Circuit<F> for TxCircuitTester<F> {
.collect(),
&challenges,
)?;
config.tx_config.u8_table.load(&mut layouter)?;

self.tx_circuit
.assign_dev_block_table(config.tx_config.clone(), &mut layouter)?;
Expand Down