Skip to content

Conversation

@quangvdao
Copy link
Contributor

@quangvdao quangvdao commented Jan 8, 2026

Summary

This PR introduces an explicit Dory matrix layout selector and adds an AddressMajor layout implementation, while preserving existing CycleMajor behavior as the default.

Motivation

We need to support an alternate OneHot/Dory layout used by other implementations without silently changing existing proof behavior.

What’s included

  • DoryLayout enum (CycleMajor, AddressMajor) + global DoryGlobals::{get_layout,set_layout}.
  • Layout-aware OneHot polynomial operations used by Dory:
    • row commitments (commit_rows)
    • VMV / VMP (vector_matrix_product)
    • evaluation path (evaluate)
  • Layout-aware dense path in RLCPolynomial for AddressMajor (CycleMajor preserved).
  • Tests:
    • address/cycle ↔ index conversions
    • global layout state
    • dense polynomial commitment invariant across layouts
  • Up-to-date with a16z/jolt:main.

Layout definition

Let K = number of addresses, T = number of cycles.

  • CycleMajor (current default):

    • linear index: idx = address * T + cycle
    • coefficients are then placed into the Dory matrix in row-major order with row length = num_columns.
  • AddressMajor:

    • linear index: idx = cycle * K + address
    • coefficients are then placed into the Dory matrix in row-major order with row length = num_columns.

How to enable AddressMajor

Call before any Dory initialization / prover work:

use crate::poly::commitment::dory::{DoryGlobals, DoryLayout};

DoryGlobals::reset();
DoryGlobals::set_layout(DoryLayout::AddressMajor);
// then initialize contexts as usual

Testing

  • cargo test -p jolt-core --lib -- dory_layout --nocapture
  • cargo test -p jolt-core --lib -- zkvm::prover::tests::sha3_e2e_dory --exact --nocapture

cursoragent and others added 8 commits January 8, 2026 07:15
Introduces DoryLayout enum for row-major and column-major coefficient mapping.
Includes global state management and updated commitment logic.

Co-authored-by: quang.dao <[email protected]>
Update test parameters to match and add E2E tests for Dory layouts.

Co-authored-by: quang.dao <[email protected]>
This commit introduces the AddressMajor layout for Dory, enabling more efficient polynomial commitments. It includes updates to OneHotPolynomial, RLCPolynomial, and DoryGlobals to handle the new layout. The verifier is also updated to initialize DoryGlobals with the new layout.

Co-authored-by: quang.dao <[email protected]>
This commit completes the AddressMajor layout implementation by updating
the core algorithms in OneHotPolynomial and RLCPolynomial:

- Updated OneHotPolynomial::num_rows() to be layout-aware
- Implemented commit_rows_address_major() with cycle-based row indexing
- Implemented vector_matrix_product_address_major() for correct VMV
- Updated RLCPolynomial to handle AddressMajor for dense polynomials
- Added get_dimension() and get_cycles_per_row() helper methods
- Fixed test num_vars consistency to avoid generator cache conflicts

The two layouts differ in how coefficients are organized:
- CycleMajor: index = address * T + cycle (groups by address)
- AddressMajor: index = cycle * K + address (groups by cycle)
@quangvdao quangvdao changed the title Dory: add layout enum + AddressMajor support (GPU-compatible) Dory: add layout enum + AddressMajor support Jan 8, 2026
@markosg04 markosg04 self-requested a review January 8, 2026 16:55
Copy link
Collaborator

@moodlezoup moodlezoup left a comment

Choose a reason for hiding this comment

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

in https://github.com/a16z/jolt/pull/996/files#diff-bcd74093e182e3cebb7ddcc4f3c4c251928a4c4a53615f8c42be8f815b7a22df, I had to make changes to the opening point passed to Dory in order to support address-major matrix layout. Why do we no longer need those changes?

// Parameters are computed from trace length as needed

// Initialize Dory globals for the verifier
// The verifier needs these to compute commitments during verification
Copy link
Collaborator

Choose a reason for hiding this comment

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

this comment is a bit misleading

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to do this anyways, so I'm deleting it.

Comment on lines +717 to +720
/// Test that dense polynomials produce the same commitment regardless of layout.
///
/// The CycleMajor vs AddressMajor distinction only affects OneHot polynomials.
/// For dense polynomials, the matrix storage is always row-major.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is true, I don't understand why this test is passing. Dense polynomials are treated as having K=1

})
.collect(),
MultilinearPolynomial::LargeScalars(poly) => {
if address_major && poly.Z.len() == t {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the len == t checks throughout this file are unnecessary? All non-one-hot polynomials should be length T

Comment on lines +374 to +379
// AddressMajor embedding for cycle-only dense polynomials (len == T):
// use bases at stride K (col = cycle_offset * K) and chunk coefficients by cycles_per_row.
macro_rules! compute_dense_address_major_msm {
($coeffs:expr, $msm_method:ident) => {{
let t = DoryGlobals::get_T();
if DoryGlobals::get_layout() == DoryLayout::AddressMajor && $coeffs.len() == t {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment and name for this macro seem to be inaccurate, as it handles the CycleMajor case in the else block. can we just fold this into the existing compute_msm! macro?

Comment on lines +343 to +344
// This batching helper was originally written for CycleMajor and is not currently
// performance-critical. For AddressMajor, fall back to per-polynomial commits to
Copy link
Collaborator

Choose a reason for hiding this comment

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

we're not using this function anywhere anymore, we can just delete it

result
}

/// AddressMajor lazy VMV over lazy trace iterator (experimental, re-runs tracer).
Copy link
Collaborator

Choose a reason for hiding this comment

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

given that we don't plan to use address-major on CPU (except for testing), I prefer to remove all the streaming-related codepaths. Wdyt?

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.

4 participants