Skip to content

Conversation

@quangvdao
Copy link
Contributor

@quangvdao quangvdao commented Nov 21, 2025

NOTE

Does NOT support arbitrary phase1 and phase2 num rounds. However, we do support the cases we care about:

  • Bind all cycle variables first (or even all but one cycle variables)
  • Bind zero cycle variable, start with some address variables, then materialize

Added TODO for the future to make things work for all parameters


PR Summary: RAM Read/Write Checking Refactoring with RA Reduction Sumcheck & Advice Opening Optimization

Overview

This PR introduces several major changes to the RAM subsystem:

  1. New RA Reduction Sumcheck - Consolidates four RAM RA claims into a single reduced claim
  2. Sparse Matrix Restructuring - New AddressMajor and CycleMajor matrix representations
  3. Phase-based Read/Write Checking - Three-phase structure for flexible variable binding
  4. Advice Opening Optimization - Opens advice at TWO points Conditionally opens at ONE or TWO points based on phase configuration

Key Changes by File

1. opening_proof.rs (+81 lines)

  • OpeningId enum refactored: Advice variants now take SumcheckId parameter
  • New SumcheckId::RamRaReduction variant added
  • Getter/setter methods updated to take SumcheckId parameter

2. proof_serialization.rs (+106 lines)

  • Four advice proof fields (but second pair may be None when single opening is used):
    pub trusted_advice_val_evaluation_proof: Option<PCS::Proof>,
    pub trusted_advice_val_final_proof: Option<PCS::Proof>,      // None when single_opening
    pub untrusted_advice_val_evaluation_proof: Option<PCS::Proof>,
    pub untrusted_advice_val_final_proof: Option<PCS::Proof>,    // None when single_opening

3. ram/mod.rs (+224 lines)

  • prover_accumulate_advice: Conditionally opens at ONE or TWO points:
    pub fn prover_accumulate_advice<F: JoltField>(
        ...,
        single_opening: bool,  // NEW: when true, skip second opening
    )
  • verifier_accumulate_advice: Same conditional pattern

4. prover.rs (+127 lines)

  • prove_trusted_advice / prove_untrusted_advice:
    • Returns (Some(proof), None) when needs_single_advice_opening(T) is true
    • Returns (Some(proof), Some(proof)) otherwise

5. verifier.rs (+98 lines)

  • verify_trusted_advice_opening_proofs / verify_untrusted_advice_opening_proofs:
    • Skips second proof verification when needs_single_advice_opening(T) is true

6. ram/read_write_checking.rs (+497 lines)

  • NEW: needs_single_advice_opening(T: usize) -> bool function:
    /// Returns true if all cycle variables are bound in phase 1.
    /// When true, advice opening points are identical → only need one opening.
    pub fn needs_single_advice_opening(T: usize) -> bool {
        phase1_num_rounds(0, T) == T.log_2()
    }
  • Documented supported configurations:
    • (T.log_2(), any) - All cycle vars bound in phase 1 → single advice opening
    • (0, any) - Skip phase 1 → two advice openings needed

7. ram/output_check.rs (+22 lines)

  • Updated to use correct SumcheckId based on needs_single_advice_opening:
    let advice_sumcheck_id = if needs_single_advice_opening(trace_len) {
        SumcheckId::RamValEvaluation      // Reuse the single opening
    } else {
        SumcheckId::RamValFinalEvaluation // Use dedicated opening
    };

8. ram/ra_reduction.rs (NEW +868 lines)

  • RamRaReductionSumcheckProver: Consolidates four RA claims into one
  • RamRaReductionSumcheckVerifier: Verifies the reduced claim

9. ram/val_evaluation.rs (+16 lines)

  • Updated docstring: LT is LT(j, r_cycle) (bitstring j < r_cycle)

Why Two Advice Opening Points?Advice Opening Optimization

Previous behavior: Always open advice at TWO points.

New behavior: Conditionally open at ONE or TWO points:

Phase Config needs_single_advice_opening Advice Openings
phase1 = T.log_2() (all cycle vars) true ONE (points identical)
phase1 = 0 (all address vars first) false TWO (points differ)

Savings when single_opening = true:

  • ✅ Skip 2 PCS proof generations
  • ✅ Skip 2 polynomial evaluations
  • ✅ Skip 2 PCS verifications
  • ✅ Smaller proof size

Required Invariants (from ram/mod.rs documentation)

For the RA reduction to work correctly:

  1. OutputCheck and RafEvaluation MUST be in the same batched sumcheck (Stage 2)
  2. ValEvaluation and ValFinal MUST be in the same batched sumcheck (Stage 4)
  3. ValEvaluation MUST read r_address from RamReadWriteChecking's opening
  4. ValFinal MUST read r_address from OutputCheck's opening (or RamReadWriteChecking if single_opening)

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