Skip to content

use auto gen code from air infra for cairo claim generator struct, get_sub_components and fil_cairo_claim_generator#1543

Merged
Stavbe merged 1 commit intomainfrom
stav/integrate_cairo_claim_generator_code_gen
Jan 7, 2026
Merged

use auto gen code from air infra for cairo claim generator struct, get_sub_components and fil_cairo_claim_generator#1543
Stavbe merged 1 commit intomainfrom
stav/integrate_cairo_claim_generator_code_gen

Conversation

@Stavbe
Copy link
Contributor

@Stavbe Stavbe commented Dec 25, 2025

This change is Reviewable

Copy link
Contributor Author

Stavbe commented Dec 25, 2025

@Stavbe Stavbe force-pushed the stav/integrate_cairo_claim_generator_code_gen branch 3 times, most recently from db30738 to a0eb6da Compare December 28, 2025 15:25
Copy link
Contributor Author

@Stavbe Stavbe left a comment

Choose a reason for hiding this comment

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

Required changes for the integration:

  1. Update the builtin names in BuiltinSegments to match their names in air-infra.

  2. Add #[derive(Default)] to PublicData, MemorySmallValue, SegmentRange, PublicSegmentRanges, and PublicMemory for use by CairoClaimGenerator::default.

  3. Add a RANGE_CHECK96_MEMORY_CELLS constant for cleaner and more unified code in the codegen.

  4. Remove BuiltinsClaimGenerator, OpcodesClaimGenerator, BlakeContextClaimGenerator, PedersenContextClaimGenerator, RangeChecksClaimGenerator, and PoseidonContextClaimGenerator, and update their write_trace functions to construct the existing claim.

@Stavbe made 1 comment.
Reviewable status: 0 of 20 files reviewed, all discussions resolved.

@Stavbe Stavbe force-pushed the stav/integrate_cairo_claim_generator_code_gen branch from a0eb6da to 5e7218e Compare December 28, 2025 15:45
Copy link
Contributor Author

@Stavbe Stavbe left a comment

Choose a reason for hiding this comment

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

  1. Clone the memory in the BlakeRound::ClaimGenerator::new ()

@Stavbe made 1 comment.
Reviewable status: 0 of 22 files reviewed, all discussions resolved.

@Stavbe Stavbe marked this pull request as ready for review December 28, 2025 16:15
@Stavbe Stavbe self-assigned this Dec 28, 2025
Copy link
Contributor

@anatgstarkware anatgstarkware left a comment

Choose a reason for hiding this comment

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

It looks great!

@anatgstarkware reviewed 16 files and made 3 comments.
Reviewable status: 16 of 22 files reviewed, 2 unresolved discussions (waiting on @Stavbe).


stwo_cairo_prover/crates/prover/src/witness/cairo.rs line 200 at r2 (raw file):

    };

    cairo_claim_generator.public_data = public_data;

I think that if you call fill_cairo_claim_generator here, you can pass the memory, and you don't need to clone it

Suggestion:

let mut cairo_claim_generator = CairoClaimGenerator {
    public_data;
    ..
}
cairo_claim_generator.fill_components(&all_components, )

stwo_cairo_prover/crates/prover/src/witness/opcodes.rs line 17 at r2 (raw file):

use crate::witness::utils::TreeBuilder;

pub fn get_opcodes(casm_states_by_opcodes: &CasmStatesByOpcode) -> Vec<&'static str> {

Suggestion:

casm_states_by_opcode

@Stavbe Stavbe force-pushed the stav/integrate_cairo_claim_generator_code_gen branch from 5e7218e to d415be9 Compare January 1, 2026 15:27
Copy link
Contributor Author

@Stavbe Stavbe left a comment

Choose a reason for hiding this comment

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

@Stavbe made 3 comments.
Reviewable status: 8 of 25 files reviewed, 3 unresolved discussions (waiting on @anatgstarkware).


stwo_cairo_prover/crates/prover/src/witness/cairo.rs line 200 at r2 (raw file):

Previously, anatgstarkware (anatg) wrote…

I think that if you call fill_cairo_claim_generator here, you can pass the memory, and you don't need to clone it

Done. Note that I needed the loop on the memory after the fill_components, that's why I took it down.
Moreover, the problem with cloning the memory was inside the fill_components function (because Blake Round consumed it), so it doesn't affect that (regardless, I moved the clone inside the Blake Round for a cleaner auto-gen, as we discussed).


stwo_cairo_prover/crates/prover/src/witness/opcodes.rs line 17 at r2 (raw file):

use crate::witness::utils::TreeBuilder;

pub fn get_opcodes(casm_states_by_opcodes: &CasmStatesByOpcode) -> Vec<&'static str> {

Done.


stwo_cairo_prover/crates/common/src/builtins.rs line 1 at r3 (raw file):

pub const ADD_MOD_MEMORY_CELLS: usize = 7;

I renamed this file to builtins_constant

Copy link
Contributor

@anatgstarkware anatgstarkware left a comment

Choose a reason for hiding this comment

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

@anatgstarkware reviewed 12 files and all commit messages, made 4 comments, and resolved 1 discussion.
Reviewable status: 20 of 25 files reviewed, 4 unresolved discussions (waiting on @Stavbe).


stwo_cairo_prover/crates/common/src/builtins.rs line 1 at r3 (raw file):

Previously, Stavbe wrote…

I renamed this file to builtins_constant

why? this is a very big pr, please don't add unrelated changes


stwo_cairo_prover/crates/prover/src/witness/cairo.rs line 200 at r2 (raw file):

Previously, Stavbe wrote…

Done. Note that I needed the loop on the memory after the fill_components, that's why I took it down.
Moreover, the problem with cloning the memory was inside the fill_components function (because Blake Round consumed it), so it doesn't affect that (regardless, I moved the clone inside the Blake Round for a cleaner auto-gen, as we discussed).

I don't understand why we can't fill the memory tables before fill_components?


stwo_cairo_prover/crates/prover/Cargo.toml line 38 at r3 (raw file):

tracing.workspace = true
dashmap.workspace = true
indexmap = "2.2.6"

please add to the workspace toml


stwo_cairo_prover/crates/prover/src/witness/cairo_claim_generator.rs line 95 at r3 (raw file):

        self.blake_compress_opcode = components.contains(&"blake_compress_opcode").then(|| {
            blake_compress_opcode::ClaimGenerator::new(
                casm_states_by_opcode.blake_compress_opcode.clone(),

My mistake, sorry, we shouldn't pass CasmStatesByOpcode by reference just to clone it here

Code quote:

.clone()

@Stavbe Stavbe force-pushed the stav/integrate_cairo_claim_generator_code_gen branch from d415be9 to 4380f02 Compare January 5, 2026 13:33
Copy link
Contributor Author

@Stavbe Stavbe left a comment

Choose a reason for hiding this comment

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

@Stavbe made 2 comments and resolved 1 discussion.
Reviewable status: 10 of 26 files reviewed, 3 unresolved discussions (waiting on @anatgstarkware).


stwo_cairo_prover/crates/prover/Cargo.toml line 38 at r3 (raw file):

Previously, anatgstarkware (anatg) wrote…

please add to the workspace toml

Done.


stwo_cairo_prover/crates/prover/src/witness/cairo_claim_generator.rs line 95 at r3 (raw file):

Previously, anatgstarkware (anatg) wrote…

My mistake, sorry, we shouldn't pass CasmStatesByOpcode by reference just to clone it here

Done.

Copy link
Contributor

@anatgstarkware anatgstarkware left a comment

Choose a reason for hiding this comment

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

please rebase

@anatgstarkware partially reviewed 13 files and all commit messages, made 1 comment, and resolved 3 discussions.
Reviewable status: 23 of 26 files reviewed, all discussions resolved (waiting on @Stavbe).

@anatgstarkware
Copy link
Contributor

stwo_cairo_prover/crates/cairo-air/src/air.rs line 234 at r4 (raw file):

}

#[derive(Serialize, Deserialize, CairoSerialize, CairoDeserialize, Default)]

I think you can revert the changes to this file

@Stavbe Stavbe force-pushed the stav/integrate_cairo_claim_generator_code_gen branch from 4380f02 to e2f2f88 Compare January 6, 2026 16:40
Copy link
Contributor Author

@Stavbe Stavbe left a comment

Choose a reason for hiding this comment

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

Done

@Stavbe made 2 comments.
Reviewable status: 9 of 26 files reviewed, 1 unresolved discussion (waiting on @anatgstarkware and @Stavbe).


stwo_cairo_prover/crates/cairo-air/src/air.rs line 234 at r4 (raw file):

Previously, anatgstarkware (anatg) wrote…

I think you can revert the changes to this file

I thought about that as well, but apparently the ..Default() call initializes the struct first and then overrides the specified fields — so it’s still needed. I could have explicitly set None for all the fields, but I preferred this way.

Copy link
Contributor

@anatgstarkware anatgstarkware left a comment

Choose a reason for hiding this comment

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

@anatgstarkware reviewed 14 files and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: 23 of 26 files reviewed, 1 unresolved discussion (waiting on @Stavbe).


stwo_cairo_prover/crates/prover/src/witness/components/poseidon.rs line 56 at r5 (raw file):

        .expect("Should have poseidon round keys trace generator at this point");
    let mut range_check_252_width_27_trace_generator = range_check_252_width_27_trace_generator
        .expect("Should have range check 252 width 27 trace generator at this point");

Why is this different than the rest? Why not just unwrap?

Code quote:

    let poseidon_aggregator_trace_generator = poseidon_aggregator_trace_generator
        .expect("Should have poseidon aggregator trace generator at this point");
    let mut poseidon_3_partial_rounds_chain_trace_generator =
        poseidon_3_partial_rounds_chain_trace_generator
            .expect("Should have poseidon 3 partial rounds chain trace generator at this point");
    let mut poseidon_full_round_chain_trace_generator = poseidon_full_round_chain_trace_generator
        .expect("Should have poseidon full round chain trace generator at this point");
    let mut cube_252_trace_generator =
        cube_252_trace_generator.expect("Should have cube 252 trace generator at this point");
    let poseidon_round_keys_trace_generator = poseidon_round_keys_trace_generator
        .expect("Should have poseidon round keys trace generator at this point");
    let mut range_check_252_width_27_trace_generator = range_check_252_width_27_trace_generator
        .expect("Should have range check 252 width 27 trace generator at this point");

Copy link
Contributor

@anatgstarkware anatgstarkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

@anatgstarkware reviewed 3 files and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Stavbe).

Copy link
Contributor

@anatgstarkware anatgstarkware left a comment

Choose a reason for hiding this comment

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

@anatgstarkware resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Stavbe).

@Stavbe Stavbe merged commit 7bdfb86 into main Jan 7, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants