Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] sha256 witness issue (#1081) #1087

Merged
merged 5 commits into from
Jan 16, 2024
Merged
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
23 changes: 13 additions & 10 deletions zkevm-circuits/src/sha256_circuit/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ impl CircuitConfig {
sha256_table: impl SHA256Table,
spec_challenge: Expression<Fr>,
) -> 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();

Expand All @@ -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);
Expand Down Expand Up @@ -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(
Expand All @@ -779,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",
Expand Down
25 changes: 14 additions & 11 deletions zkevm-circuits/src/sha256_circuit/test.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
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},
};
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::{
Expand All @@ -29,7 +30,7 @@ struct MyCircuit {
}

impl Circuit<Fr> for MyCircuit {
type Config = CircuitConfig;
type Config = (CircuitConfig, Challenges);
type FloorPlanner = SimpleFloorPlanner;

fn without_witnesses(&self) -> Self {
Expand Down Expand Up @@ -59,23 +60,25 @@ impl Circuit<Fr> 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<Fr>,
) -> 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 {
Expand Down Expand Up @@ -114,7 +117,7 @@ fn vk_stable() {
&params,
&pk,
&[circuit],
&[],
&[&[]],
OsRng,
&mut transcript,
)
Expand All @@ -127,7 +130,7 @@ fn vk_stable() {
&params,
&vk_from_empty,
strategy,
&[],
&[&[]],
&mut transcript,
)
.unwrap();
Expand Down
Loading