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

Commit

Permalink
simplify expression
Browse files Browse the repository at this point in the history
  • Loading branch information
ChihChengLiang committed Sep 14, 2023
1 parent 89f362a commit 648b428
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions zkevm-circuits/src/evm_circuit/util/constraint_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use halo2_proofs::{
circuit::Value,
plonk::{
ConstraintSystem, Error,
Expression::{self},
Expression::{self, Constant},
VirtualCells,
},
};
Expand Down Expand Up @@ -331,16 +331,32 @@ impl<F: Field> RwCounterOffset<F> {
self.special,
name,
);
let inc = variable_inc.clone().unwrap_or(1.expr());
let rwc_inc = match condition.clone() {
Some(cond) => cond * inc.expr(),
None => inc.expr(),
};
match condition.zip(variable_inc) {
Some((_, _)) => self.special += 1,
None => self.normal += 1,

// Manually constant folding is used here, since halo2 cannot do this
// automatically. Better error message will be printed during circuit
// debugging.
self.expr = match (condition, variable_inc) {
(None, None) => {
self.normal += 1;
if let Constant(v) = self.expr {
Constant(v + F::from(1u64))
} else {
self.expr.clone() + 1.expr()
}
}
(None, Some(inc)) => {
self.special += 1;
self.expr.clone() + inc
}
(Some(cond), None) => {
self.special += 1;
self.expr.clone() + cond
}
(Some(cond), Some(inc)) => {
self.special += 1;
self.expr.clone() + cond * inc
}
};
self.expr = self.expr.clone() + rwc_inc;
}
}

Expand Down

0 comments on commit 648b428

Please sign in to comment.