mirror of https://github.com/zcash/halo2.git
Restrict query_fixed to current Rotation.
query_fixed no longer takes a Rotation argument and can only be used to query the current rotation.
This commit is contained in:
parent
153a08c755
commit
41c87eac0f
|
@ -137,7 +137,7 @@ impl<FixedPoints: super::FixedPoints<pallas::Affine>> Config<FixedPoints> {
|
|||
) -> Vec<(&'static str, Expression<pallas::Base>)> {
|
||||
let y_p = meta.query_advice(self.add_config.y_p, Rotation::cur());
|
||||
let x_p = meta.query_advice(self.add_config.x_p, Rotation::cur());
|
||||
let z = meta.query_fixed(self.fixed_z, Rotation::cur());
|
||||
let z = meta.query_fixed(self.fixed_z);
|
||||
let u = meta.query_advice(self.u, Rotation::cur());
|
||||
|
||||
let window_pow: Vec<Expression<pallas::Base>> = (0..H)
|
||||
|
@ -150,9 +150,7 @@ impl<FixedPoints: super::FixedPoints<pallas::Affine>> Config<FixedPoints> {
|
|||
|
||||
let interpolated_x = window_pow.iter().zip(self.lagrange_coeffs.iter()).fold(
|
||||
Expression::Constant(pallas::Base::zero()),
|
||||
|acc, (window_pow, coeff)| {
|
||||
acc + (window_pow.clone() * meta.query_fixed(*coeff, Rotation::cur()))
|
||||
},
|
||||
|acc, (window_pow, coeff)| acc + (window_pow.clone() * meta.query_fixed(*coeff)),
|
||||
);
|
||||
|
||||
// Check interpolation of x-coordinate
|
||||
|
|
|
@ -102,7 +102,7 @@ impl<F: Field, const WIDTH: usize, const RATE: usize> Pow5Chip<F, WIDTH, RATE> {
|
|||
let expr = (0..WIDTH)
|
||||
.map(|idx| {
|
||||
let state_cur = meta.query_advice(state[idx], Rotation::cur());
|
||||
let rc_a = meta.query_fixed(rc_a[idx], Rotation::cur());
|
||||
let rc_a = meta.query_fixed(rc_a[idx]);
|
||||
pow_5(state_cur + rc_a) * m_reg[next_idx][idx]
|
||||
})
|
||||
.reduce(|acc, term| acc + term)
|
||||
|
@ -117,8 +117,8 @@ impl<F: Field, const WIDTH: usize, const RATE: usize> Pow5Chip<F, WIDTH, RATE> {
|
|||
let cur_0 = meta.query_advice(state[0], Rotation::cur());
|
||||
let mid_0 = meta.query_advice(partial_sbox, Rotation::cur());
|
||||
|
||||
let rc_a0 = meta.query_fixed(rc_a[0], Rotation::cur());
|
||||
let rc_b0 = meta.query_fixed(rc_b[0], Rotation::cur());
|
||||
let rc_a0 = meta.query_fixed(rc_a[0]);
|
||||
let rc_b0 = meta.query_fixed(rc_b[0]);
|
||||
|
||||
let s_partial = meta.query_selector(s_partial);
|
||||
|
||||
|
@ -127,7 +127,7 @@ impl<F: Field, const WIDTH: usize, const RATE: usize> Pow5Chip<F, WIDTH, RATE> {
|
|||
let mid = mid_0.clone() * m_reg[idx][0];
|
||||
(1..WIDTH).fold(mid, |acc, cur_idx| {
|
||||
let cur = meta.query_advice(state[cur_idx], Rotation::cur());
|
||||
let rc_a = meta.query_fixed(rc_a[cur_idx], Rotation::cur());
|
||||
let rc_a = meta.query_fixed(rc_a[cur_idx]);
|
||||
acc + (cur + rc_a) * m_reg[idx][cur_idx]
|
||||
})
|
||||
};
|
||||
|
@ -143,7 +143,7 @@ impl<F: Field, const WIDTH: usize, const RATE: usize> Pow5Chip<F, WIDTH, RATE> {
|
|||
};
|
||||
|
||||
let partial_round_linear = |idx: usize, meta: &mut VirtualCells<F>| {
|
||||
let rc_b = meta.query_fixed(rc_b[idx], Rotation::cur());
|
||||
let rc_b = meta.query_fixed(rc_b[idx]);
|
||||
mid(idx, meta) + rc_b - next(idx, meta)
|
||||
};
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ where
|
|||
/// Derives the expression `q_s3 = (q_s2) * (q_s2 - 1)`.
|
||||
fn q_s3(&self, meta: &mut VirtualCells<pallas::Base>) -> Expression<pallas::Base> {
|
||||
let one = Expression::Constant(pallas::Base::one());
|
||||
let q_s2 = meta.query_fixed(self.q_sinsemilla2, Rotation::cur());
|
||||
let q_s2 = meta.query_fixed(self.q_sinsemilla2);
|
||||
q_s2.clone() * (q_s2 - one)
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ where
|
|||
// https://p.z.cash/halo2-0.1:sinsemilla-constraints?partial
|
||||
meta.create_gate("Initial y_Q", |meta| {
|
||||
let q_s4 = meta.query_selector(config.q_sinsemilla4);
|
||||
let y_q = meta.query_fixed(config.fixed_y_q, Rotation::cur());
|
||||
let y_q = meta.query_fixed(config.fixed_y_q);
|
||||
|
||||
// Y_A = (lambda_1 + lambda_2) * (x_a - x_r)
|
||||
let Y_A_cur = Y_A(meta, Rotation::cur());
|
||||
|
|
|
@ -40,7 +40,7 @@ impl GeneratorTableConfig {
|
|||
// https://p.z.cash/halo2-0.1:sinsemilla-constraints?partial
|
||||
meta.lookup(|meta| {
|
||||
let q_s1 = meta.query_selector(config.q_sinsemilla1);
|
||||
let q_s2 = meta.query_fixed(config.q_sinsemilla2, Rotation::cur());
|
||||
let q_s2 = meta.query_fixed(config.q_sinsemilla2);
|
||||
let q_s3 = config.q_s3(meta);
|
||||
let q_run = q_s2 - q_s3;
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@ and this project adheres to Rust's notion of
|
|||
- `VirtualCells`
|
||||
- `query_any` now panics if a non-`cur` `Rotation` is used with the
|
||||
`Column<Fixed>` variant.
|
||||
- `query_fixed` now no longer takes a `Rotation` argument,
|
||||
and can only be used to query the current rotation.
|
||||
|
||||
## [0.2.0] - 2022-06-23
|
||||
### Added
|
||||
|
|
|
@ -200,10 +200,10 @@ fn criterion_benchmark(c: &mut Criterion) {
|
|||
let b = meta.query_advice(b, Rotation::cur());
|
||||
let c = meta.query_advice(c, Rotation::cur());
|
||||
|
||||
let sa = meta.query_fixed(sa, Rotation::cur());
|
||||
let sb = meta.query_fixed(sb, Rotation::cur());
|
||||
let sc = meta.query_fixed(sc, Rotation::cur());
|
||||
let sm = meta.query_fixed(sm, Rotation::cur());
|
||||
let sa = meta.query_fixed(sa);
|
||||
let sb = meta.query_fixed(sb);
|
||||
let sc = meta.query_fixed(sc);
|
||||
let sm = meta.query_fixed(sm);
|
||||
|
||||
vec![a.clone() * sa + b.clone() * sb + a * b * sm - (c * sc)]
|
||||
});
|
||||
|
|
|
@ -211,15 +211,15 @@ impl<F: Field> Circuit<F> for MyCircuit<F> {
|
|||
meta.create_gate("Combined add-mult", |meta| {
|
||||
let d = meta.query_advice(d, Rotation::next());
|
||||
let a = meta.query_advice(a, Rotation::cur());
|
||||
let sf = meta.query_fixed(sf, Rotation::cur());
|
||||
let sf = meta.query_fixed(sf);
|
||||
let e = meta.query_advice(e, Rotation::prev());
|
||||
let b = meta.query_advice(b, Rotation::cur());
|
||||
let c = meta.query_advice(c, Rotation::cur());
|
||||
|
||||
let sa = meta.query_fixed(sa, Rotation::cur());
|
||||
let sb = meta.query_fixed(sb, Rotation::cur());
|
||||
let sc = meta.query_fixed(sc, Rotation::cur());
|
||||
let sm = meta.query_fixed(sm, Rotation::cur());
|
||||
let sa = meta.query_fixed(sa);
|
||||
let sb = meta.query_fixed(sb);
|
||||
let sc = meta.query_fixed(sc);
|
||||
let sm = meta.query_fixed(sm);
|
||||
|
||||
vec![a.clone() * sa + b.clone() * sb + a * b * sm - (c * sc) + sf * (d * e)]
|
||||
});
|
||||
|
|
|
@ -1070,7 +1070,7 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
panic!("expression containing simple selector supplied to lookup argument");
|
||||
}
|
||||
|
||||
let table = cells.query_fixed(table.inner(), Rotation::cur());
|
||||
let table = cells.query_fixed(table.inner());
|
||||
|
||||
(input, table)
|
||||
})
|
||||
|
@ -1083,17 +1083,17 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
index
|
||||
}
|
||||
|
||||
fn query_fixed_index(&mut self, column: Column<Fixed>, at: Rotation) -> usize {
|
||||
fn query_fixed_index(&mut self, column: Column<Fixed>) -> usize {
|
||||
// Return existing query, if it exists
|
||||
for (index, fixed_query) in self.fixed_queries.iter().enumerate() {
|
||||
if fixed_query == &(column, at) {
|
||||
if fixed_query == &(column, Rotation::cur()) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
// Make a new query
|
||||
let index = self.fixed_queries.len();
|
||||
self.fixed_queries.push((column, at));
|
||||
self.fixed_queries.push((column, Rotation::cur()));
|
||||
|
||||
index
|
||||
}
|
||||
|
@ -1132,7 +1132,7 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
fn query_any_index(&mut self, column: Column<Any>, at: Rotation) -> usize {
|
||||
match column.column_type() {
|
||||
Any::Advice => self.query_advice_index(Column::<Advice>::try_from(column).unwrap(), at),
|
||||
Any::Fixed => self.query_fixed_index(Column::<Fixed>::try_from(column).unwrap(), at),
|
||||
Any::Fixed => self.query_fixed_index(Column::<Fixed>::try_from(column).unwrap()),
|
||||
Any::Instance => {
|
||||
self.query_instance_index(Column::<Instance>::try_from(column).unwrap(), at)
|
||||
}
|
||||
|
@ -1273,7 +1273,7 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
let column = self.fixed_column();
|
||||
new_columns.push(column);
|
||||
Expression::Fixed(FixedQuery {
|
||||
index: self.query_fixed_index(column, Rotation::cur()),
|
||||
index: self.query_fixed_index(column),
|
||||
column_index: column.index,
|
||||
rotation: Rotation::cur(),
|
||||
})
|
||||
|
@ -1497,12 +1497,12 @@ impl<'a, F: Field> VirtualCells<'a, F> {
|
|||
}
|
||||
|
||||
/// Query a fixed column at a relative position
|
||||
pub fn query_fixed(&mut self, column: Column<Fixed>, at: Rotation) -> Expression<F> {
|
||||
self.queried_cells.push((column, at).into());
|
||||
pub fn query_fixed(&mut self, column: Column<Fixed>) -> Expression<F> {
|
||||
self.queried_cells.push((column, Rotation::cur()).into());
|
||||
Expression::Fixed(FixedQuery {
|
||||
index: self.meta.query_fixed_index(column, at),
|
||||
index: self.meta.query_fixed_index(column),
|
||||
column_index: column.index,
|
||||
rotation: at,
|
||||
rotation: Rotation::cur(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1539,7 +1539,7 @@ impl<'a, F: Field> VirtualCells<'a, F> {
|
|||
if at != Rotation::cur() {
|
||||
panic!("Fixed columns can only be queried at the current rotation");
|
||||
}
|
||||
self.query_fixed(Column::<Fixed>::try_from(column).unwrap(), at)
|
||||
self.query_fixed(Column::<Fixed>::try_from(column).unwrap())
|
||||
}
|
||||
Any::Instance => self.query_instance(Column::<Instance>::try_from(column).unwrap(), at),
|
||||
}
|
||||
|
|
|
@ -316,15 +316,15 @@ fn plonk_api() {
|
|||
meta.create_gate("Combined add-mult", |meta| {
|
||||
let d = meta.query_advice(d, Rotation::next());
|
||||
let a = meta.query_advice(a, Rotation::cur());
|
||||
let sf = meta.query_fixed(sf, Rotation::cur());
|
||||
let sf = meta.query_fixed(sf);
|
||||
let e = meta.query_advice(e, Rotation::prev());
|
||||
let b = meta.query_advice(b, Rotation::cur());
|
||||
let c = meta.query_advice(c, Rotation::cur());
|
||||
|
||||
let sa = meta.query_fixed(sa, Rotation::cur());
|
||||
let sb = meta.query_fixed(sb, Rotation::cur());
|
||||
let sc = meta.query_fixed(sc, Rotation::cur());
|
||||
let sm = meta.query_fixed(sm, Rotation::cur());
|
||||
let sa = meta.query_fixed(sa);
|
||||
let sb = meta.query_fixed(sb);
|
||||
let sc = meta.query_fixed(sc);
|
||||
let sm = meta.query_fixed(sm);
|
||||
|
||||
vec![a.clone() * sa + b.clone() * sb + a * b * sm - (c * sc) + sf * (d * e)]
|
||||
});
|
||||
|
@ -332,7 +332,7 @@ fn plonk_api() {
|
|||
meta.create_gate("Public input", |meta| {
|
||||
let a = meta.query_advice(a, Rotation::cur());
|
||||
let p = meta.query_instance(p, Rotation::cur());
|
||||
let sp = meta.query_fixed(sp, Rotation::cur());
|
||||
let sp = meta.query_fixed(sp);
|
||||
|
||||
vec![sp * (a - p)]
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue