-
Notifications
You must be signed in to change notification settings - Fork 3
Add local poseidon2-air crate with extra index columns #131
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
base: main
Are you sure you want to change the base?
Conversation
|
If we're just adding columns, I don't think we need to copy the code. We can make Poseidon2 columns part of our Poseidon2's columns, and those columns can be made into a subair (which applies the same constraints as Plonky3's Poseidon2 (SP1 and OpenVM do that, for Keccak at least) |
|
I'd agree with Linda, I don't see why we'd need a blatant copy of the P3 code, unless you'd be modifying the existing internal structure? If yes, please clarify why it's needed and in that case, we'd need a renaming of the copied crate to be able to publish it with our own changes. |
sai-deng
left a comment
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.
Could we include a minimal trace-generation helper plus unit tests to harden this PR?
| @@ -0,0 +1,266 @@ | |||
| use core::array; | |||
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 suggest rename it to p3-poseidon2-recursion-air as poseidon2-circuit-air does not emphasize the extra columns you add for the 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.
I think that circuit denotes instead that the extra columns are for our circuit in particular, and not for a generic recursion method. But I don't have a strong opinion on this.
| // Code from SP1 with minor modifications: | ||
| // https://github.com/succinctlabs/sp1/blob/main/crates/stark/src/air/sub_builder.rs |
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 think it'd be useful to extract this piece outside of the poseidon2-circuit-air crate to make it widely accessible, as this is fairly valuable even for external users.
| use p3_air::{Air, AirBuilder}; | ||
| use p3_matrix::Matrix; | ||
|
|
||
| /// A submatrix of a matrix. The matrix will contain a subset of the columns of `self.inner`. |
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.
| /// A submatrix of a matrix. The matrix will contain a subset of the columns of `self.inner`. | |
| /// A submatrix of a matrix. The matrix will contain a subset of the columns of `self.inner`. |
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.
also nit but doesn't submatrix imply it's from a "larger" matrix already?
| const WIDTH: usize, | ||
| const WIDTH_EXT: usize, | ||
| const RATE_EXT: usize, | ||
| const SBOX_DEGREE: u64, | ||
| const SBOX_REGISTERS: usize, | ||
| const HALF_FULL_ROUNDS: usize, | ||
| const PARTIAL_ROUNDS: usize, |
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.
Not really blocking but 70% of this file (and a good portion of the air module are due to all these associated constants.
Could be worth diving into some way to refactor this later on to make it a bit more concise / readable.
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 thought the same. I think something like
pub struct Poseidon2CircuitCols<
T,
const WIDTH_EXT: usize,
const RATE_EXT: usize,
P: PermutationColumns<T>,
> {
pub poseidon2: P,
pub is_sponge: T,
pub reset: T,
pub sponge_reset: T,
pub absorb_flags: [T; RATE_EXT],
pub input_indices: [T; WIDTH_EXT],
pub output_indices: [T; RATE_EXT],
}
trait PermutationColumns<T> {}
impl<
T,
const WIDTH: usize,
const SBOX_DEGREE: u64,
const SBOX_REGISTERS: usize,
const HALF_FULL_ROUNDS: usize,
const PARTIAL_ROUNDS: usize,
> PermutationColumns<T>
for Poseidon2Cols<T, WIDTH, SBOX_DEGREE, SBOX_REGISTERS, HALF_FULL_ROUNDS, PARTIAL_ROUNDS>
{
}could make the trick.
| pub const fn new( | ||
| constants: RoundConstants<F, WIDTH, HALF_FULL_ROUNDS, PARTIAL_ROUNDS>, | ||
| ) -> Self { | ||
| assert!(CAPACITY_EXT + RATE_EXT == WIDTH_EXT); |
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.
You can also do
const _: () = {
assert!(CAPACITY_EXT + RATE_EXT == WIDTH_EXT, "capacity+rate mismatch");
assert!(WIDTH_EXT * D == WIDTH, "width extension mismatch");
};|
|
||
| for i in 0..n { | ||
| let row = &mut vec[(i * ncols)..((i + 1) * ncols)]; | ||
| let left_part = p2_trace |
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.
This is copying the whole poseidon trace. The problem is that generate_trace_rows allocs a new matrix, while we would like to have the matrix at some specific addresses (at every row, before the right_part). But we need to figure out a way of doing so.
The local copy will be extended to verify Poseidon2 operations used in challenger/sponge circuits and MMCS verification AIR with CTLs.