feat(merkle): implement Merkle-proof allowlist verification module - #439
Merged
Lakes41 merged 1 commit intoJul 29, 2026
Merged
Conversation
Implement a dependency-free (js-sha3 only) Merkle-proof allowlist verification module for gasless off-chain access checks. New @guildpass/sdk/merkle subpath exports: - buildAllowlistTree(addresses[]) — constructs tree from validated, checksum-normalised, deduplicated addresses - getProof(tree, address) — O(log n) proof generation - verifyProof(root, address, proof[]) — deterministic client-side verification - verifyProofFromLeaf(root, leaf, proof[]) — verify from pre-computed leaf Key design decisions: - Leaf hashing: keccak256 of 20 raw address bytes, matching OpenZeppelin's keccak256(abi.encodePacked(address)) - Internal nodes: sorted-pair hashing keccak256(a || b) where a ≤ b - Odd-leaf-count handling: level promotion (not duplication), avoiding known vulnerability of duplication schemes - Zero new runtime dependencies — reuses js-sha3 (already in tree) - Hex-to-bytes helper reused from src/crypto/secp256k1.ts Includes: - 31 comprehensive tests covering correctness, odd counts, negative cases, and performance at scale (5000 addresses) - docs/merkle-allowlists.md with full workflow documentation and explicit security note about client-side verification - CHANGELOG entry Closes Adamantine-guild#404
Closed
8 tasks
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
Implements a Merkle-proof allowlist verification module for gasless off-chain access checks.
Changes
New
@guildpass/sdk/merklesubpathbuildAllowlistTree(addresses[])— constructs a Merkle tree from validated, checksum-normalised, deduplicated addressesgetProof(tree, address)— O(log n) Merkle proof generation from a pre-built treeverifyProof(root, address, proof[])— deterministic, side-effect-free proof verification suitable for client-side pre-checksverifyProofFromLeaf(root, leaf, proof[])— verify from a pre-computed leaf hashKey design decisions
keccak256of the 20 raw address bytes, matching OpenZeppelin'skeccak256(abi.encodePacked(address))keccak256(a || b)wherea ≤ bjs-sha3already in the dependency treehexToByteshelper reused fromsrc/crypto/secp256k1.ts(no duplication)Tests
Documentation
docs/merkle-allowlists.md— full workflow (build → publish root → distribute proofs → verify client-side / server-side) with explicit security note that client-side proof verification is a UX optimisation, not an authoritative access decisionFiles changed
src/merkle/allowlistTree.tssrc/merkle/index.tstests/merkle.test.tsdocs/merkle-allowlists.mdpackage.json./merklesubpath exporttsup.config.tsmerkleentry pointCHANGELOG.mdCloses #404