lp: 4086 title: Pedersen Tree-Reduce Vector Commit description: Shared-memory tree reduction for the width-256 Pedersen vector commitment, replacing a 255-step serial accumulator with an 8-level pairwise reduction — and the measurement showing where that does and does not pay author: Lux Core Team (@luxfi) discussions-to: https://github.com/luxfi/lps/discussions status: Final implementation-rust: none implementation-cpp: shipped type: Standards Track category: Core tags: [pedersen, vector-commitment, verkle, tree-reduce, gpu, banderwagon]
- lp-4370
- lp-4190
- lp-4040
Abstract
Tree reduction in shared memory for the width-256 Pedersen vector
commitment, replacing the sequential 256-step accumulator with a
log₂(256) = 8-deep pairwise reduction. Each level halves the active
point count and runs all surviving additions in parallel; the canonical
fold survives only at the final root.
This LP is also an honest negative result on one backend, which is why its Performance section is worth reading before its Algorithm section.
Specification
Algorithm
Width-w Pedersen vector commit:
Pedersen(values v_0..v_{w-1}, generators G_0..G_{w-1}) = sum_i v_i * G_i
Sequential form:
acc = 0
for i in 0..w-1:
acc = acc + v_i * G_i # w scalar muls + w-1 adds, all serial
Tree-reduce form:
# Stage 1: parallel scalar muls (already parallel today)
P[i] = v_i * G_i for i in 0..w-1
# Stage 2: tree-reduce in shared memory, log_2(w) levels
for level in 0..log2(w)-1:
stride = 2^level
parfor i in 0..w-1 step 2*stride:
P[i] = P[i] + P[i + stride] # ALL pairs add in parallel within level
return P[0]
For w = 256 the tree is 8 levels — 128, 64, 32, 16, 8, 4, 2, 1
additions — each level serialized but every addition within a level
concurrent. Wall clock is 8·t_add against 255·t_add, a 32×
theoretical ceiling.
Reduction order is canonical: left-to-right pairing within each level. That fixes byte-equality across CPU, Metal, CUDA and WGSL regardless of how threads happen to get scheduled.
Performance — and where the ceiling actually binds
End-to-end width-256 commit:
| Backend | Legacy two-stage | Tree-reduce | Ratio |
|---|---|---|---|
| Metal (Apple M2 Ultra, 24 KiB threadgroup memory) | 2,774 µs/commit | 3,814 µs/commit | 0.73× |
| CUDA (A100/H100, 192 KiB shared/SM) | — | — | pending real-device |
| WGSL (modern wgpu adapter) | — | — | pending real-device |
| CPU canonical | linear loop | linear loop | 1.0× (oracle) |
On Apple silicon the tree-reduce loses. The 24 KiB threadgroup memory ceiling caps occupancy at width 256 — the 256-point staging buffer does not fit in fast on-chip storage, so the reduction spills and the two-stage pipeline wins. The transform is profitable on devices with 192 KiB of shared memory per SM, where the whole buffer stays resident.
So the dispatcher routes per device from measured thresholds, and the
legacy two-stage path stays the fallback on Apple hardware. The
_w256 specialization is not universally better and is not claimed to
be. A theoretical 32× ceiling is a statement about the algorithm; which
side of the crossover a device lands on is a statement about its memory.
Known-answer tests
crypto/pedersen/test/kat_width256.json — 100 random
(v_0..v_255, G_0..G_255) batches with golden output points.
Generators derive from the canonical PEDERSEN_SEEDED_GEN_V1 domain
separation tag (LP-4365) and reproduce
G[0..31] = c563aa8a283f268b65b4210a0a78ee1341f76b59d94c1ac626effe1a5aa0c6b7
byte for byte.
Implementation
CPU canonical
crypto/pedersen/cpp/pedersen.{hpp,cpp} adds
pedersen_commit_tree(values, generators, w) alongside the linear
pedersen_commit. The CPU implementation stays the linear loop — there
is no win on CPU, and it is kept as the byte-equality oracle.
GPU kernels
pedersen_tree.{metal,cu,wgsl} — width-parameterized tree reduce, plus
host drivers. The existing linear pedersen.metal is retained for
w < 8.
C-ABI
// Width-256 Pedersen tree-reduce (Verkle hot path)
int pedersen_commit_tree_w256(const uint8_t *values, // 256 * 32 bytes (Fr scalars)
const uint8_t *generators, // 256 * 32 bytes (Banderwagon affine x)
uint8_t *commit_out); // 32 bytes
// Width-parameterized variant
int pedersen_commit_tree(uint32_t width, // power-of-2, <= 1024
const uint8_t *values,
const uint8_t *generators,
uint8_t *commit_out);
The _w256 specialization is the Verkle-tuned path with compile-time
loop bounds and a fixed shared-memory layout. The general variant serves
IPA inner-product, KZG-Pedersen hybrids and other variable-width
consumers.
Determinism harness
pedersen_tree_test.{cpp,mm,cu} — w ∈ {8, 16, 32, 64, 128, 256, 512,
1024}, 100 random batches per w, byte-equal CPU (linear) against
Metal/CUDA/WGSL (tree). Cross-oracle: gnark-crypto
bandersnatch.MultiExp, an independent canonical-order accumulator.
Security Considerations
- Pedersen commitment is a public-input operation on the verifier side (Verkle proof check, IPA inner product), so a variable-time tree-reduce is acceptable there.
- Prover-side commits with secret
v_i— blinded balances, confidential amounts — MUST apply blinded multi-exponentiation first (LP-4040). The tree-reduce is variable-time on the bit pattern of the scalar multiplications feeding it. - The kernel takes generators as input; it does not derive them. Generator-source integrity is the caller's responsibility, and the generators MUST match the LP-4365 golden vector byte for byte. A commitment against the wrong generators is a valid-looking commitment to nothing.
- Canonical left-to-right pairing per level makes the reduction deterministic regardless of thread scheduling.
Crossover
w* = 8. Below w = 8 the tree depth (3 levels) does not amortize
dispatch overhead and the dispatcher routes to the linear accumulator.
CPU has no crossover — the linear loop stays canonical at every w.
References
- Pedersen, "Non-Interactive and Information-Theoretic Secure Verifiable Secret Sharing" (CRYPTO 1991)
- Kuszmaul, "Verkle Trees" (2018) — width-256 internal-node commit
- Buterin et al., "Verkle Trees for Stateless Ethereum" (2021)
- Harris, "Parallel Prefix Sum (Scan) with CUDA" (2007) — the shared-memory tree-reduce pattern
Copyright
Copyright (C) 2024-2026, Lux Industries Inc. All rights reserved.
Licensed under the MIT License.