From fb07f58fbbd7f9cb0b3627f5ebafa6306c4376c4 Mon Sep 17 00:00:00 2001 From: kunxian xia Date: Thu, 11 Jan 2024 19:51:52 +0800 Subject: [PATCH 1/4] reproduce phase issues in sha256_circuit --- zkevm-circuits/src/sha256_circuit/test.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/zkevm-circuits/src/sha256_circuit/test.rs b/zkevm-circuits/src/sha256_circuit/test.rs index 1b0ce5b45d..8d3669f7a4 100644 --- a/zkevm-circuits/src/sha256_circuit/test.rs +++ b/zkevm-circuits/src/sha256_circuit/test.rs @@ -20,6 +20,8 @@ use halo2_proofs::{ }, transcript::{TranscriptReadBuffer, TranscriptWriterBuffer}, }; +use halo2_proofs::plonk::SecondPhase; +use crate::util::Challenges; const CAP_BLK: usize = 24; @@ -29,7 +31,7 @@ struct MyCircuit { } impl Circuit for MyCircuit { - type Config = CircuitConfig; + type Config = (CircuitConfig, Challenges); type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { @@ -59,23 +61,25 @@ impl Circuit for MyCircuit { let dev_table = DevTable { s_enable: meta.fixed_column(), - input_rlc: meta.advice_column(), input_len: meta.advice_column(), - hashes_rlc: meta.advice_column(), + input_rlc: meta.advice_column_in(SecondPhase), + hashes_rlc: meta.advice_column_in(SecondPhase), is_effect: meta.advice_column(), }; meta.enable_constant(dev_table.s_enable); - let chng = Expression::Constant(Fr::from(0x100u64)); - Self::Config::configure(meta, dev_table, chng) + let challenges = Challenges::construct(meta); + let chng = challenges.exprs(meta).keccak_input(); + (CircuitConfig::configure(meta, dev_table, chng), challenges) } fn synthesize( &self, - config: Self::Config, + (config, challenges): Self::Config, mut layouter: impl Layouter, ) -> Result<(), Error> { - let chng_v = Value::known(Fr::from(0x100u64)); + let challenges = challenges.values(&layouter); + let chng_v = challenges.keccak_input(); let mut hasher = Hasher::new(config, &mut layouter)?; for _ in 0..self.blocks { @@ -114,7 +118,7 @@ fn vk_stable() { ¶ms, &pk, &[circuit], - &[], + &[&[]], OsRng, &mut transcript, ) From f691e8aab833d9eeefb2f13ffc94d3f0212553ad Mon Sep 17 00:00:00 2001 From: Ho Vei Date: Fri, 12 Jan 2024 22:32:23 +0800 Subject: [PATCH 2/4] fix issues --- zkevm-circuits/src/sha256_circuit/circuit.rs | 9 +++++---- zkevm-circuits/src/sha256_circuit/test.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/zkevm-circuits/src/sha256_circuit/circuit.rs b/zkevm-circuits/src/sha256_circuit/circuit.rs index 8e8eebd8a4..4c28533c2a 100644 --- a/zkevm-circuits/src/sha256_circuit/circuit.rs +++ b/zkevm-circuits/src/sha256_circuit/circuit.rs @@ -270,12 +270,12 @@ impl CircuitConfig { sha256_table: impl SHA256Table, spec_challenge: Expression, ) -> Self { - let helper = meta.advice_column(); // index 3 - let trans_byte = meta.advice_column(); // index 4 + let copied_data = meta.advice_column(); + let trans_byte = meta.advice_column(); let bytes_rlc = sha256_table.hashes_rlc(); let byte_counter = sha256_table.input_len(); - let copied_data = sha256_table.input_rlc(); + let helper = sha256_table.input_rlc(); let s_output = sha256_table.s_enable(); let s_final_block = sha256_table.is_effect(); @@ -290,6 +290,7 @@ impl CircuitConfig { let byte_range = meta.lookup_table_column(); let table16 = Table16Chip::configure(meta); + meta.enable_equality(helper); meta.enable_equality(copied_data); meta.enable_equality(bytes_rlc); meta.enable_equality(s_final_block); @@ -763,7 +764,7 @@ impl CircuitConfig { input_block.bytes_rlc.copy_advice( || "copy input rlc", &mut region, - self.copied_data, + self.helper, final_row, )?; input_block.byte_counter.copy_advice( diff --git a/zkevm-circuits/src/sha256_circuit/test.rs b/zkevm-circuits/src/sha256_circuit/test.rs index 8d3669f7a4..a10f2d9f83 100644 --- a/zkevm-circuits/src/sha256_circuit/test.rs +++ b/zkevm-circuits/src/sha256_circuit/test.rs @@ -131,7 +131,7 @@ fn vk_stable() { ¶ms, &vk_from_empty, strategy, - &[], + &[&[]], &mut transcript, ) .unwrap(); From 58b7f3773f70b69f7a3fc26c7871d2b4033feb0f Mon Sep 17 00:00:00 2001 From: Ho Vei Date: Sun, 14 Jan 2024 18:45:27 +0800 Subject: [PATCH 3/4] fmt and clippy --- zkevm-circuits/src/sha256_circuit/test.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/zkevm-circuits/src/sha256_circuit/test.rs b/zkevm-circuits/src/sha256_circuit/test.rs index a10f2d9f83..9a85cc0e51 100644 --- a/zkevm-circuits/src/sha256_circuit/test.rs +++ b/zkevm-circuits/src/sha256_circuit/test.rs @@ -1,5 +1,5 @@ use halo2_proofs::{ - circuit::{Layouter, SimpleFloorPlanner, Value}, + circuit::{Layouter, SimpleFloorPlanner}, plonk::{create_proof, keygen_pk, keygen_vk, verify_proof, Circuit, ConstraintSystem, Error}, transcript::{Blake2bRead, Blake2bWrite, Challenge255}, }; @@ -7,9 +7,10 @@ use rand::rngs::OsRng; use super::{circuit::*, BLOCK_SIZE}; +use crate::util::Challenges; use halo2_proofs::{ halo2curves::bn256::{Bn256, Fr}, - plonk::{Advice, Any, Column, Expression, Fixed}, + plonk::{Advice, Any, Column, Fixed, SecondPhase}, poly::{ commitment::ParamsProver, kzg::{ @@ -20,8 +21,6 @@ use halo2_proofs::{ }, transcript::{TranscriptReadBuffer, TranscriptWriterBuffer}, }; -use halo2_proofs::plonk::SecondPhase; -use crate::util::Challenges; const CAP_BLK: usize = 24; From d8c88c837dc418275a84086f3e976783845ae9d9 Mon Sep 17 00:00:00 2001 From: Ho Vei Date: Sun, 14 Jan 2024 22:07:20 +0800 Subject: [PATCH 4/4] fix gate issue --- zkevm-circuits/src/sha256_circuit/circuit.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/zkevm-circuits/src/sha256_circuit/circuit.rs b/zkevm-circuits/src/sha256_circuit/circuit.rs index 4c28533c2a..3f20471f55 100644 --- a/zkevm-circuits/src/sha256_circuit/circuit.rs +++ b/zkevm-circuits/src/sha256_circuit/circuit.rs @@ -780,12 +780,14 @@ impl CircuitConfig { final_row, )?; - region.assign_advice( - || "flush unused row", - self.trans_byte, - final_row, - || Value::known(Fr::zero()), - )?; + for col in [self.trans_byte, self.copied_data] { + region.assign_advice( + || "flush unused row", + col, + final_row, + || Value::known(Fr::zero()), + )?; + } region.assign_advice( || "flush unused row",