-
Notifications
You must be signed in to change notification settings - Fork 854
Conversation
714b4fe
to
63dfabf
Compare
state: [Column<Advice>; 25], | ||
_marker: PhantomData<F>, | ||
} | ||
|
||
impl<F: FieldExt> PiConfig<F> { | ||
pub const OFFSET: usize = 2; |
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.
Please. Don't remove the OFFSET as it's required later for assembliyng the entire Keccak circuit.
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.
Sorry, I'll return them back.
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.
Oh, I realize it's part of the layouter refactor.
Currently the circuit looks like this
state = {
// Apply pi outside circuit
let out_state = KeccakFArith::pi(&state_to_biguint(state));
let out_state = state_bigint_to_pallas(out_state);
// assignment
self.pi_config
.assign_state(region, offset, state, out_state)?
};
offset += PiConfig::OFFSET;
With the new interface, we can do
state = self.pi_config.assign_state(mut layouter, state, out_state)?;
No need to track the region and the offset. The layouter find a new region for it.
What do you think?
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.
hmmm.
So the proposal is to have each gate/config application within a different region then?
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.
Yes, it makes sense to let layouter decide where to put the state row. Counting offsets is like doing the layouter's job.
meta.create_gate("pi", |meta| { | ||
let q_enable = meta.query_selector(q_enable); | ||
(0..5) | ||
.cartesian_product(0..5) | ||
.map(|(x, y)| { | ||
let lane = meta.query_advice( | ||
state[5 * ((x + 3 * y) % 5) + x], | ||
Rotation::cur(), | ||
); | ||
let new_lane = | ||
meta.query_advice(state[5 * x + y], Rotation::next()); | ||
|
||
q_enable.clone() * (new_lane - lane) | ||
}) | ||
.collect::<Vec<Expression<F>>>() |
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.
Why are you removing the gate from Pi??
It does not apply any constraints now.
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.
I realized that using purely copy constraints can achieve pi gate. There's no need to add polys for the gate.
What do you think
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.
Hmmm. But copy constraints can only enforce that the provided input is indeed the one that has to be used.
Not sure how you still enforce with constraints:
let lane = meta.query_advice(
state[5 * ((x + 3 * y) % 5) + x],
Rotation::cur(),
);
let new_lane =
meta.query_advice(state[5 * x + y], Rotation::next());
q_enable.clone() * (new_lane - lane)
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.
IIU the halo2 code correctly, copy constraints are applicable as long as we know what cells to copy. We don't have to create custom gates for them.
I did realize I forgot to add enable equality in this case. Will add now.
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.
Ohh I see! That sounds correct! Thanks!
63dfabf
to
f2d2d55
Compare
f2d2d55
to
0cb7976
Compare
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.
LGTM!
Depending on the Layouter
instead of Region + offset
seems like a really nice idea!
Close in favor of #234 |
[(Cell, F);25]
as state output and recieve as input to copy states between gates #219, take and return [(Cell, F); 25] in assign region