fix(pedersen): collapse to single canonical PEDERSEN_SEEDED_GEN_V1 DST (LP-137 N3)#1
Open
abhicris wants to merge 1 commit intoluxfi:mainfrom
Open
fix(pedersen): collapse to single canonical PEDERSEN_SEEDED_GEN_V1 DST (LP-137 N3)#1abhicris wants to merge 1 commit intoluxfi:mainfrom
abhicris wants to merge 1 commit intoluxfi:mainfrom
Conversation
Closes LP-137 RED-FINAL §2.4 (issue N3): collapse the legacy two-DST
PEDERSEN_G_V1 / PEDERSEN_H_V1 path to a single canonical
PEDERSEN_SEEDED_GEN_V1 with counter-indexed generation, matching the
C++ canonical at luxcpp/crypto/pedersen/cpp/pedersen.hpp:47.
Both NewGenerators(rng) and DeterministicGenerators(seed) now flow
through pedersen_seed.NewGeneratorsFromSeed:
- NewGenerators reads 32 bytes from rng as the seed.
- DeterministicGenerators compresses arbitrary-length input via
SHA-256 to a 32-byte key, then dispatches.
- Both branches use HashToG1(key || u64_le(i), DST=SeededGenDST)
with i=0 for G and i=1 for H — byte-equivalent to C++ from_seed.
KAT vectors (pedersen_test.go::katCases) regenerated under the new
derivation. Two new tests:
- TestCanonicalSeededDST locks the on-wire DST string so any drift
fails loudly before it can break GPU↔CPU byte-equality.
- TestDeterministicMatchesFromSeed proves DeterministicGenerators
reduces to NewGeneratorsFromSeed(SHA-256(seed)) — the contract the
post-N3 collapse promises.
All 11 pedersen tests pass; existing TestNewGeneratorsFromSeed_GoldenVector
remains the cross-language anchor (matches luxcpp pedersen_kat.h G[0].x).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes LP-137 RED-FINAL §2.4 / N3 — the Pedersen DST mismatch between the Go canonical and the C++/Metal/CUDA/WGSL implementations. The audit's normative ask:
Today, `pedersen.go::NewGenerators` and `pedersen.go::DeterministicGenerators` both used a two-DST scheme (`PEDERSEN_G_V1` / `PEDERSEN_H_V1`), which the C++ side does not match. `pedersen_seed.go::NewGeneratorsFromSeed` already had the canonical single-DST + counter-encoded scheme (matching `luxcpp/crypto/pedersen/cpp/pedersen.hpp:47` `DST_SEEDED_GEN`); this PR routes both legacy entry points through that path so there is exactly one derivation in the codebase.
What changes
`pedersen.go`
`pedersen_test.go`
`pedersen_seed.go` — untouched. It was already canonical; this PR makes the rest of the package agree with it.
Tests
`go vet ./pedersen/...` clean. `go build ./pedersen/...` clean.
Verifying against C++ canonical
The cross-language anchor is `pedersen_seed_test.go::TestNewGeneratorsFromSeed_GoldenVector` (untouched), which freezes `G`'s coordinates derived from `SHA-256("lux-pedersen-seed-test-v1")`. The C++ `luxcpp/crypto/pedersen/test/pedersen_kat.h` uses the same `from_seed` path with a different test seed; mapping the seeds through `pedersen/test/tools/gen_pedersen_kat.go` (referenced by `pedersen_kat.h`) closes the cross-language KAT loop. That tool is not yet present in `luxfi/crypto/pedersen/` — happy to add it as a follow-up so future regenerations are a one-shot in either language.
Backwards compatibility
Risks / scope notes
Authored by kcolbchain (@abhicris). Coordinated with the LP-137 reconciliation track.