From 66f3d0a0860235d300a7c1257dae49da49d379fe Mon Sep 17 00:00:00 2001 From: MauroFab Date: Mon, 29 Jun 2026 20:34:27 -0300 Subject: [PATCH] fix(test): use row-pair leaves in merkle_root_parity GPU tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gpu_merkle_root / gpu_ext3_merkle_root called keccak_leaves_base/ext3 with rows_per_leaf=1 (per-row, num_rows leaves) but compare the resulting root against the CPU commit_rows_bit_reversed, which uses the row-pair layout (ROWS_PER_LEAF=2, num_rows/2 leaves, each hashing a bit-reversed row pair). Different leaf count and bytes => different root, so the two cases never matched main's row-pair commitment scheme. Pass rows_per_leaf=2 so the generic GPU keccak-leaves + Merkle path uses the same bit-reversed row-pair layout as the CPU reference. keccak_leaves.rs already proves keccak_leaves_base(.., 2) matches the CPU row-pair prover, and the production-pipeline parity cases (new_row_major_pipeline_*) already pass, so this only realigns the generic-helper cases with main. Test-only change; the proving path uses the fused row-pair pipeline and is unaffected. GPU tests don't run in CI (no nvcc) — to be confirmed on a GPU. --- crypto/math-cuda/tests/merkle_root_parity.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crypto/math-cuda/tests/merkle_root_parity.rs b/crypto/math-cuda/tests/merkle_root_parity.rs index 0cbe016b6..ee59d323b 100644 --- a/crypto/math-cuda/tests/merkle_root_parity.rs +++ b/crypto/math-cuda/tests/merkle_root_parity.rs @@ -55,9 +55,11 @@ fn gpu_merkle_root(columns: &[Vec], blowup: usize, weights: &[u64]) -> [u8; } } - // Per-row leaves (rows_per_leaf = 1): this parity test compares the generic - // keccak-leaves + Merkle primitives against a per-row CPU reference. - let gpu_leaves = math_cuda::merkle::keccak_leaves_base(&flat, n_lde, num_cols, n_lde, 1) + // Row-pair leaves (rows_per_leaf = 2, matching `ROWS_PER_LEAF`): the CPU + // reference is `commit_rows_bit_reversed`, which hashes bit-reversed row + // pairs into each leaf, so the generic GPU keccak-leaves + Merkle path must + // use the same row-pair layout to produce a matching root. + let gpu_leaves = math_cuda::merkle::keccak_leaves_base(&flat, n_lde, num_cols, n_lde, 2) .expect("GPU keccak leaves"); let nodes = math_cuda::merkle::build_merkle_tree_on_device(&gpu_leaves).expect("GPU Merkle tree"); @@ -191,8 +193,10 @@ fn gpu_ext3_merkle_root(columns: &[Vec], blowup: usize, weights: &[u64]) -> } } + // Row-pair leaves (rows_per_leaf = 2, matching `ROWS_PER_LEAF`) to match the + // row-pair `commit_rows_bit_reversed` CPU reference below. let gpu_leaves = - math_cuda::merkle::keccak_leaves_ext3(&flat_for_keccak, lde_size, num_cols, lde_size, 1) + math_cuda::merkle::keccak_leaves_ext3(&flat_for_keccak, lde_size, num_cols, lde_size, 2) .expect("GPU ext3 keccak leaves"); let nodes = math_cuda::merkle::build_merkle_tree_on_device(&gpu_leaves).expect("GPU Merkle tree");