-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cc63d2
commit 816767c
Showing
5 changed files
with
149 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use halo2_proofs::{ | ||
arithmetic::FieldExt, | ||
circuit::{Layouter, Value}, | ||
plonk::{Challenge, ConstraintSystem, Expression, FirstPhase, VirtualCells}, | ||
}; | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub struct Challenges<T = Challenge> { | ||
mpt_word: T, | ||
} | ||
|
||
impl Challenges { | ||
pub fn construct<F: FieldExt>(meta: &mut ConstraintSystem<F>) -> Self { | ||
Self { | ||
mpt_word: meta.challenge_usable_after(FirstPhase), | ||
} | ||
} | ||
|
||
/// Return `Expression` of challenges from `ConstraintSystem`. | ||
pub fn exprs<F: FieldExt>(&self, meta: &mut ConstraintSystem<F>) -> Challenges<Expression<F>> { | ||
let [mpt_word] = query_expression(meta, |meta| { | ||
[self.mpt_word].map(|challenge| meta.query_challenge(challenge)) | ||
}); | ||
|
||
Challenges { mpt_word } | ||
} | ||
|
||
/// Return `Value` of challenges from `Layouter`. | ||
pub fn values<F: FieldExt>(&self, layouter: &impl Layouter<F>) -> Challenges<Value<F>> { | ||
Challenges { | ||
mpt_word: layouter.get_challenge(self.mpt_word), | ||
} | ||
} | ||
} | ||
|
||
impl<T: Clone> Challenges<T> { | ||
pub fn mpt_word(&self) -> T { | ||
self.mpt_word.clone() | ||
} | ||
} | ||
|
||
fn query_expression<F: FieldExt, T>( | ||
meta: &mut ConstraintSystem<F>, | ||
mut f: impl FnMut(&mut VirtualCells<F>) -> T, | ||
) -> T { | ||
let mut expr = None; | ||
meta.create_gate("Query expression", |meta| { | ||
expr = Some(f(meta)); | ||
Some(Expression::Constant(F::from(0))) | ||
}); | ||
expr.unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.