-
Notifications
You must be signed in to change notification settings - Fork 3
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
Better column query in MPT macros #8
base: mpt-refactor
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,11 @@ | |
use crate::{evm_circuit::util::rlc, util::Expr}; | ||
use eth_types::Field; | ||
use gadgets::util::{and, select, sum, Scalar}; | ||
use halo2_proofs::plonk::{ConstraintSystem, Expression}; | ||
use halo2_proofs::{ | ||
halo2curves::bn256::Fr, | ||
plonk::{Advice, Column, ConstraintSystem, Expression, Fixed, VirtualCells}, | ||
poly::Rotation, | ||
}; | ||
use itertools::Itertools; | ||
|
||
use super::cell_manager::{Cell, CellManager, CellType, DataTransition, Trackable}; | ||
|
@@ -454,6 +458,24 @@ impl<F: Field, E: Expressable<F>> Expressable<F> for (E, E, E, E) { | |
} | ||
} | ||
|
||
/// Enables column query without knowing the Column type | ||
pub trait Querier<F: Field> { | ||
/// Query a column at a relative position | ||
fn query(self, meta: &mut VirtualCells<F>, at: Rotation) -> Expression<F>; | ||
} | ||
|
||
impl<F: Field> Querier<F> for Column<Fixed> { | ||
fn query(self, meta: &mut VirtualCells<F>, at: Rotation) -> Expression<F> { | ||
meta.query_fixed(self, at) | ||
} | ||
} | ||
|
||
impl<F: Field> Querier<F> for Column<Advice> { | ||
fn query(self, meta: &mut VirtualCells<F>, at: Rotation) -> Expression<F> { | ||
meta.query_advice(self, at) | ||
} | ||
} | ||
|
||
/// Implementation trait `Expressable` for type able to be casted to an | ||
/// Expression | ||
#[macro_export] | ||
|
@@ -1111,7 +1133,7 @@ macro_rules! circuit { | |
#[allow(unused_imports)] | ||
use gadgets::util::{and, not, or, sum, Expr}; | ||
#[allow(unused_imports)] | ||
use $crate::circuit_tools::constraint_builder::{Conditionable, Expressable, Selectable}; | ||
use $crate::circuit_tools::constraint_builder::{Conditionable, Expressable, Selectable, Querier}; | ||
|
||
#[allow(unused_macros)] | ||
macro_rules! f { | ||
|
@@ -1133,6 +1155,34 @@ macro_rules! circuit { | |
}}; | ||
} | ||
|
||
#[allow(unused_macros)] | ||
macro_rules! cur { | ||
($column:expr) => {{ | ||
$column.query($meta, Rotation::cur()) | ||
}}; | ||
} | ||
|
||
#[allow(unused_macros)] | ||
macro_rules! next { | ||
($column:expr) => {{ | ||
$column.query($meta, Rotation::next()) | ||
}}; | ||
} | ||
|
||
#[allow(unused_macros)] | ||
macro_rules! prev { | ||
($column:expr) => {{ | ||
$column.query($meta, Rotation::prev()) | ||
}}; | ||
} | ||
|
||
#[allow(unused_macros)] | ||
macro_rules! query { | ||
($column:expr, $rot:expr) => {{ | ||
$column.query($meta, Rotation($rot as i32)) | ||
}}; | ||
} | ||
Comment on lines
+1158
to
+1184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean that column.cur() would work without the meta? In that case the macros would be unnecessary I believe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! |
||
|
||
#[allow(unused_macros)] | ||
macro_rules! not { | ||
($expr:expr) => {{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Makes the API similar to what privacy-scaling-explorations/halo2#154.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, I left a comment, I think the
expr
method name is confusing and perhapscur
would be better for the method name.