Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
rm minimal_rows
Browse files Browse the repository at this point in the history
  • Loading branch information
ChihChengLiang committed Sep 28, 2023
1 parent c036246 commit 1c56c0d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
6 changes: 2 additions & 4 deletions circuit-benchmarks/src/bytecode_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ mod tests {
let bytecodes_num: usize = max_bytecode_row_num / bytecode_len;

// Create the circuit
let bytecode_circuit = TestBytecodeCircuit::<Fr>::new(
fillup_codebytes(bytecodes_num, bytecode_len),
2usize.pow(degree),
);
let bytecode_circuit =
TestBytecodeCircuit::<Fr>::new(fillup_codebytes(bytecodes_num, bytecode_len), degree);

// Initialize the polynomial commitment parameters
let mut rng = XorShiftRng::from_seed([
Expand Down
35 changes: 19 additions & 16 deletions zkevm-circuits/src/bytecode_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
},
table::{BytecodeFieldTag, BytecodeTable, KeccakTable, LookupTable},
util::{
self, get_push_size,
self, get_push_size, log2_ceil,
word::{empty_code_hash_word_value, Word, Word32, WordExpr},
Challenges, Expr, SubCircuit, SubCircuitConfig,
},
Expand Down Expand Up @@ -162,7 +162,6 @@ impl<F: Field> Deref for BytecodeCircuitAssignment<F> {
#[derive(Clone, Debug)]
/// Bytecode circuit configuration
pub struct BytecodeCircuitConfig<F> {
minimum_rows: usize,
q_enable: Column<Fixed>,
q_first: Column<Fixed>,
q_last: Column<Fixed>,
Expand Down Expand Up @@ -555,7 +554,6 @@ impl<F: Field> SubCircuitConfig<F> for BytecodeCircuitConfig<F> {
let index_length_diff_is_zero = IsZeroChip::construct(index_length_diff_is_zero);

BytecodeCircuitConfig {
minimum_rows: meta.minimum_rows(),
q_enable,
q_first,
q_last,
Expand All @@ -576,19 +574,17 @@ impl<F: Field> BytecodeCircuitConfig<F> {
pub(crate) fn assign_internal(
&self,
layouter: &mut impl Layouter<F>,
size: usize,
degree: u32,
unusable_rows: usize,
witness: &BytecodeCircuitAssignment<F>,
challenges: &Challenges<Value<F>>,
) -> Result<(), Error> {
// Subtract the unusable rows from the size
assert!(size > self.minimum_rows);

let last_row_offset = size - self.minimum_rows + 1;
let last_row_offset = 2usize.pow(degree) - unusable_rows - 1;

trace!(
"size: {}, minimum_rows: {}, last_row_offset:{}",
size,
self.minimum_rows,
"degree: {}, unusable_rows: {}, last_row_offset:{}",
degree,
unusable_rows,
last_row_offset
);
if witness.len() > last_row_offset {
Expand Down Expand Up @@ -779,17 +775,17 @@ pub struct BytecodeCircuit<F: Field> {
/// Unrolled bytecodes
pub(crate) rows: BytecodeCircuitAssignment<F>,
/// Circuit size
pub size: usize,
pub degree: u32,
}

impl<F: Field> BytecodeCircuit<F> {
/// new BytecodeCircuitTester
pub fn new(bytecodes: CodeDB, size: usize) -> Self {
pub fn new(bytecodes: CodeDB, degree: u32) -> Self {
let rows: BytecodeCircuitAssignment<F> = bytecodes.clone().into();
Self {
bytecodes,
rows,
size,
degree,
}
}
}
Expand All @@ -804,7 +800,8 @@ impl<F: Field> SubCircuit<F> for BytecodeCircuit<F> {
}

fn new_from_block(block: &witness::Block<F>) -> Self {
Self::new(block.bytecodes.clone(), block.circuits_params.max_bytecode)
let degree = log2_ceil(block.circuits_params.max_bytecode);
Self::new(block.bytecodes.clone(), degree)
}

/// Return the minimum number of rows required to prove the block
Expand All @@ -823,6 +820,12 @@ impl<F: Field> SubCircuit<F> for BytecodeCircuit<F> {
layouter: &mut impl Layouter<F>,
) -> Result<(), Error> {
config.load_aux_tables(layouter)?;
config.assign_internal(layouter, self.size, &self.rows, challenges)
config.assign_internal(
layouter,
self.degree,
Self::unusable_rows(),
&self.rows,
challenges,
)
}
}
6 changes: 3 additions & 3 deletions zkevm-circuits/src/bytecode_circuit/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{BytecodeCircuit, BytecodeCircuitRow};
use crate::util::{log2_ceil, unusable_rows, SubCircuit};
use crate::util::{unusable_rows, SubCircuit};
use bus_mapping::{evm::OpcodeId, state_db::CodeDB};
use eth_types::Field;
use halo2_proofs::{arithmetic::Field as Halo2Field, dev::MockProver, halo2curves::bn256::Fr};
Expand All @@ -20,11 +20,11 @@ impl<F: Field> BytecodeCircuit<F> {
}

fn from_bytes(bytecodes: impl Into<CodeDB>, k: u32) -> Self {
Self::new(bytecodes.into(), 2usize.pow(k))
Self::new(bytecodes.into(), k)
}

fn verify(&self, success: bool) {
let prover = MockProver::<F>::run(log2_ceil(self.size), self, Vec::new()).unwrap();
let prover = MockProver::<F>::run(self.degree, self, Vec::new()).unwrap();
let result = prover.verify_par();
if success {
if let Err(failures) = &result {
Expand Down

0 comments on commit 1c56c0d

Please sign in to comment.