From e3799b43a87b197e37053ec2d65adaf0411402be Mon Sep 17 00:00:00 2001 From: Dream Wu Date: Wed, 31 Jul 2024 14:59:45 +0800 Subject: [PATCH] fix copytable lookup --- zkevm-circuits/src/copy_circuit.rs | 14 +++++++----- zkevm-circuits/src/copy_circuit/test.rs | 2 +- zkevm-circuits/src/table.rs | 29 +++++++------------------ 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/zkevm-circuits/src/copy_circuit.rs b/zkevm-circuits/src/copy_circuit.rs index 2d05e7e79a..28f721e196 100644 --- a/zkevm-circuits/src/copy_circuit.rs +++ b/zkevm-circuits/src/copy_circuit.rs @@ -122,6 +122,9 @@ pub struct CopyCircuitConfig { pub is_word_end: IsEqualConfig, /// non pad and non mask witness to reduce the degree of lookups. pub non_pad_non_mask: Column, + #[cfg(feature = "dual_bytecode")] + /// Whether the bytecode is belong to the first bytecode sub circuit . + pub is_first_bytecode_table: Column, // External tables /// TxTable pub tx_table: TxTable, @@ -185,7 +188,7 @@ impl SubCircuitConfig for CopyCircuitConfig { array_init(|_| meta.advice_column()); let is_first = copy_table.is_first; #[cfg(feature = "dual_bytecode")] - let is_first_bytecode_table = copy_table.is_first_bytecode_table; + let is_first_bytecode_table = meta.advice_column_in(SecondPhase); let id = copy_table.id; let addr = copy_table.addr; let src_addr_end = copy_table.src_addr_end; @@ -497,7 +500,7 @@ impl SubCircuitConfig for CopyCircuitConfig { .collect() }); - meta.lookup_any("tx table calldata lookup", |meta| { + meta.lookup_any("tx lookup for CallData", |meta| { let cond = meta.query_fixed(q_enable, CURRENT) * meta.query_advice(is_tx_calldata, CURRENT) * meta.query_advice(non_pad_non_mask, CURRENT); @@ -638,6 +641,7 @@ impl SubCircuitConfig for CopyCircuitConfig { is_id_unchange, is_src_end, is_word_end, + is_first_bytecode_table, non_pad_non_mask, tx_table, rw_table, @@ -708,6 +712,7 @@ impl CopyCircuitConfig { self.mask, self.front_mask, self.word_index, + self.is_first_bytecode_table, ] .iter() .zip_eq(circuit_row) @@ -725,9 +730,6 @@ impl CopyCircuitConfig { // lt chip if is_read { - #[cfg(feature = "dual_bytecode")] - let addr = table_row[3].0; - #[cfg(not(feature = "dual_bytecode"))] let addr = table_row[2].0; is_src_end_chip.assign( @@ -969,7 +971,7 @@ impl CopyCircuitConfig { // is_first_bytecode_table region.assign_advice( || format!("assign is_first_bytecode_table {}", *offset), - self.copy_table.is_first_bytecode_table, + self.is_first_bytecode_table, *offset, || Value::known(F::zero()), )?; diff --git a/zkevm-circuits/src/copy_circuit/test.rs b/zkevm-circuits/src/copy_circuit/test.rs index f7f57f62a5..663eea6970 100644 --- a/zkevm-circuits/src/copy_circuit/test.rs +++ b/zkevm-circuits/src/copy_circuit/test.rs @@ -458,7 +458,7 @@ fn copy_circuit_invalid_calldatacopy() { assert_error_matches( test_copy_circuit_from_block(block), - vec!["rw lookup", "rw lookup"], + vec!["tx lookup for CallData", "rw lookup"], ); } diff --git a/zkevm-circuits/src/table.rs b/zkevm-circuits/src/table.rs index a5fe3f37cb..a4527910f5 100644 --- a/zkevm-circuits/src/table.rs +++ b/zkevm-circuits/src/table.rs @@ -1726,9 +1726,6 @@ pub struct CopyTable { pub q_enable: Column, /// Whether the row is the first read-write pair for a copy event. pub is_first: Column, - #[cfg(feature = "dual_bytecode")] - /// Whether the bytecode is belong to the first bytecode sub circuit . - pub is_first_bytecode_table: Column, /// The relevant ID for the read-write row, represented as a random linear /// combination. The ID may be one of the below: /// 1. Call ID/Caller ID for CopyDataType::Memory @@ -1761,13 +1758,10 @@ pub struct CopyTable { /// TxLog. This also now includes various precompile calls, hence will take up more cells. pub tag: BinaryNumberConfig, } -#[cfg(feature = "dual_bytecode")] -type CopyTableRow = [(Value, &'static str); 9]; -#[cfg(not(feature = "dual_bytecode"))] type CopyTableRow = [(Value, &'static str); 8]; - -type CopyCircuitRow = [(Value, &'static str); 10]; +#[cfg(feature = "dual_bytecode")] +type CopyCircuitRow = [(Value, &'static str); 11]; /// CopyThread is the state used while generating rows of the copy table. struct CopyThread { @@ -1789,8 +1783,6 @@ impl CopyTable { Self { q_enable, is_first: meta.advice_column(), - #[cfg(feature = "dual_bytecode")] - is_first_bytecode_table: meta.advice_column_in(SecondPhase), id: meta.advice_column_in(SecondPhase), tag: BinaryNumberChip::configure(meta, q_enable, None), addr: meta.advice_column(), @@ -2007,12 +1999,6 @@ impl CopyTable { thread.tag, [ (Value::known(F::from(is_first)), "is_first"), - #[cfg(feature = "dual_bytecode")] - ( - // set value from block get bytecode circuit. - Value::known(F::from(is_first_bytecode_table)), - "is_first_bytecode_table", - ), (thread.id, "id"), (Value::known(addr), "addr"), (Value::known(F::from(thread.addr_end)), "src_addr_end"), @@ -2035,6 +2021,12 @@ impl CopyTable { (Value::known(F::from(copy_step.mask)), "mask"), (Value::known(F::from(thread.front_mask)), "front_mask"), (Value::known(F::from(word_index)), "word_index"), + #[cfg(feature = "dual_bytecode")] + ( + // set value from block get bytecode circuit. + Value::known(F::from(is_first_bytecode_table)), + "is_first_bytecode_table", + ), ], )); @@ -2129,8 +2121,6 @@ impl LookupTable for CopyTable { vec![ self.q_enable.into(), self.is_first.into(), - #[cfg(feature = "dual_bytecode")] - self.is_first_bytecode_table.into(), self.id.into(), self.addr.into(), self.src_addr_end.into(), @@ -2145,7 +2135,6 @@ impl LookupTable for CopyTable { vec![ String::from("q_enable"), String::from("is_first"), - String::from("is_first_bytecode_circuit"), String::from("id"), String::from("addr"), String::from("src_addr_end"), @@ -2160,8 +2149,6 @@ impl LookupTable for CopyTable { vec![ meta.query_fixed(self.q_enable, Rotation::cur()), meta.query_advice(self.is_first, Rotation::cur()), - #[cfg(feature = "dual_bytecode")] - meta.query_advice(self.is_first_bytecode_table, Rotation::cur()), meta.query_advice(self.id, Rotation::cur()), // src_id self.tag.value(Rotation::cur())(meta), // src_tag meta.query_advice(self.id, Rotation::next()), // dst_id