Skip to content

Conversation

@sai-deng
Copy link
Contributor

@sai-deng sai-deng commented Oct 9, 2025

The local copy will be extended to verify Poseidon2 operations used in challenger/sponge circuits and MMCS verification AIR with CTLs.

@LindaGuiga
Copy link
Contributor

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)

@Nashtare
Copy link
Contributor

Nashtare commented Oct 9, 2025

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 sai-deng assigned hratoanina and unassigned sai-deng Oct 9, 2025
@sai-deng sai-deng changed the title Add local poseidon2-air crate copied from upstream Plonky3 Add local poseidon2-air crate with extra index columns Oct 9, 2025
@sai-deng sai-deng marked this pull request as draft October 9, 2025 21:44
@Nashtare Nashtare removed the request for review from hratoanina October 10, 2025 06:46
@hratoanina hratoanina mentioned this pull request Oct 10, 2025
@Nashtare Nashtare added this to the Core recursive verifier milestone Oct 11, 2025
@Nashtare Nashtare changed the base branch from main to robin/recursive_challenger October 13, 2025 13:54
Base automatically changed from robin/recursive_challenger to main October 13, 2025 16:16
@hratoanina hratoanina marked this pull request as ready for review October 20, 2025 22:15
Copy link
Contributor Author

@sai-deng sai-deng left a 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;
Copy link
Contributor Author

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

Copy link
Contributor

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.

@Nashtare Nashtare moved this from Todo to Ready for review in Plonky3 Recursion Nov 7, 2025
Comment on lines +1 to +2
// Code from SP1 with minor modifications:
// https://github.com/succinctlabs/sp1/blob/main/crates/stark/src/air/sub_builder.rs
Copy link
Contributor

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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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`.

Copy link
Contributor

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?

Comment on lines +43 to +49
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,
Copy link
Contributor

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.

Copy link
Contributor

@4l0n50 4l0n50 Nov 7, 2025

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);
Copy link
Contributor

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

6 participants