From 31ca6a0068d2c21f6d179780823e47b54403dba8 Mon Sep 17 00:00:00 2001 From: xkx Date: Wed, 10 Apr 2024 18:22:45 +0800 Subject: [PATCH] Fix: use indicator column to reduce tx circuit lookup degree (#1208) * use indicator column to reduce lookup degree * update unusable rows --- zkevm-circuits/src/tx_circuit.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/zkevm-circuits/src/tx_circuit.rs b/zkevm-circuits/src/tx_circuit.rs index a32c8667e0..0a041bf5cf 100644 --- a/zkevm-circuits/src/tx_circuit.rs +++ b/zkevm-circuits/src/tx_circuit.rs @@ -166,6 +166,7 @@ pub struct TxCircuitConfig { is_tag_block_num: Column, is_calldata: Column, is_caller_address: Column, + is_row_hash_rlc: Column, is_l1_msg: Column, is_eip2930: Column, is_eip1559: Column, @@ -338,6 +339,7 @@ impl SubCircuitConfig for TxCircuitConfig { let is_calldata = meta.advice_column(); let is_tx_id_zero = meta.advice_column(); let is_caller_address = meta.advice_column(); + let is_row_hash_rlc = meta.advice_column(); let is_chain_id = meta.advice_column(); let is_tag_block_num = meta.advice_column(); let lookup_conditions = [ @@ -738,6 +740,18 @@ impl SubCircuitConfig for TxCircuitConfig { cb.gate(meta.query_fixed(q_enable, Rotation::cur())) }); + meta.create_gate("is_row_hash_rlc", |meta| { + let mut cb = BaseConstraintBuilder::default(); + + cb.require_equal( + "is_row_hash_rlc", + is_hash_rlc(meta), + meta.query_advice(is_row_hash_rlc, Rotation::cur()), + ); + + cb.gate(meta.query_fixed(q_enable, Rotation::cur())) + }); + meta.create_gate("is_chain_id", |meta| { let mut cb = BaseConstraintBuilder::default(); @@ -1859,13 +1873,11 @@ impl SubCircuitConfig for TxCircuitConfig { meta.lookup_any("Correct pow_of_rand for HashLen", |meta| { let enable = and::expr(vec![ meta.query_fixed(q_enable, Rotation::cur()), + meta.query_advice(is_row_hash_rlc, Rotation::cur()), // A valid chunk txbytes tx is determined by: (tx.tx_type != TxType::L1Msg) && // !tx.caller_address.is_zero() not::expr(meta.query_advice(is_l1_msg, Rotation::cur())), - not::expr(value_is_zero.expr(Rotation( - -((HASH_RLC_OFFSET - CALLER_ADDRESS_OFFSET) as i32), - ))(meta)), - is_hash_rlc(meta), + not::expr(meta.query_advice(is_padding_tx, Rotation::cur())), ]); vec![ @@ -1942,6 +1954,7 @@ impl SubCircuitConfig for TxCircuitConfig { is_l1_msg, is_eip2930, is_eip1559, + is_row_hash_rlc, is_chain_id, is_final, calldata_gas_cost_acc, @@ -2964,6 +2977,11 @@ impl TxCircuitConfig { self.is_tag_block_num, F::from((tx_tag == BlockNumber) as u64), ), + ( + "is_tag_hash_rlc", + self.is_row_hash_rlc, + F::from((tx_tag == TxHashRLC) as u64), + ), ( "is_tag_chain_id", self.is_chain_id, @@ -3924,7 +3942,7 @@ impl SubCircuit for TxCircuit { type Config = TxCircuitConfig; fn unusable_rows() -> usize { - 10 + 9 } fn new_from_block(block: &witness::Block) -> Self {