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

Commit

Permalink
Fix phases in is_zero gagets
Browse files Browse the repository at this point in the history
  • Loading branch information
adria0 committed Jan 9, 2023
1 parent 3ded707 commit 8bfda72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) const STEP_STATE_HEIGHT: usize = 1;
pub(crate) const N_CELLS_STEP_STATE: usize = 11;

// Number of phase2 columns
pub(crate) const N_PHASE2_COLUMNS: usize = 2;
pub(crate) const N_PHASE2_COLUMNS: usize = 3;

// Number of phase3 columns
pub(crate) const N_PHASE3_COLUMNS: usize = 1;
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl CellType {
/// Return the phase for the inverse of an the expression
pub(crate) fn storage_for_inv<F: FieldExt>(value: &Expression<F>) -> CellType {
match Self::expr_phase(value) {
0 => CellType::StoragePhase1,
0 => CellType::StoragePhase2,
1 => CellType::StoragePhase3,
2 => unimplemented!(),
_ => unreachable!(),
Expand Down
16 changes: 10 additions & 6 deletions zkevm-circuits/src/evm_circuit/util/math_gadget/batched_is_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ pub struct BatchedIsZeroGadget<F, const N: usize> {

impl<F: Field, const N: usize> BatchedIsZeroGadget<F, N> {
pub(crate) fn construct(cb: &mut ConstraintBuilder<F>, values: [Expression<F>; N]) -> Self {
let values_in_phase_1 = values
let max_values_phase= values
.iter()
.any(|value| CellType::storage_for(value) == CellType::StoragePhase1);
let in_phase = if values_in_phase_1 {
CellType::StoragePhase2
} else {
CellType::StoragePhase1
.map(CellType::expr_phase)
.max()
.expect("BatchedIsZeroGadget needs at least one expression");

let in_phase = match max_values_phase {
0 => CellType::StoragePhase2,
1 => CellType::StoragePhase3,
_ => unimplemented!()
};

let is_zero = cb.query_bool_with_type(in_phase);
let nonempty_witness = cb.query_cell_with_type(in_phase);

Expand Down

0 comments on commit 8bfda72

Please sign in to comment.