Repository navigation
fix: validate Zcash unified addresses per ZIP-316 (#749) - #999
Open
Anirudh-712 wants to merge 3 commits into
Open
Anirudh-712 wants to merge 3 commits into
Anirudh-712 wants to merge 3 commits into
Conversation
A u1 address passed when it merely decoded as Bech32m with HRP "u", so a well-formed string that is not a valid unified address was accepted (transparent-only, wrong padding, P2PKH with P2SH, items out of order, wrong receiver length, MUST-understand metadata, a non-canonical or oversized CompactSize). Decode it fully instead: Bech32m without the 90-character limit, F4Jumble⁻¹, the 16-byte HRP padding, then the typecode-length items, read as canonical CompactSize of at most 0x02000000 as librustzcash does. Require a Sapling or Orchard receiver, as ZIP-316 Revision 0 does, and reject MUST-understand metadata (0xE0 to 0xFC), which Revision 0 forbids; other unknown typecodes are ignored. No new dependencies: @scure/base and @noble/hashes are already used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Anirudh-712 is attempting to deploy a commit to the Defuse Labs Limed Team on Vercel. A member of the Team first needs to authorize it. |
Docstrings for xor, f4H and f4G, worded after ZIP-316's definitions of H_i and G_i (CodeRabbit's docstring-coverage check). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Closes #749.
validateZcashAddressaccepts anyu1…string that decodes as Bech32m with HRPu(the 128-character rule from #748 was reverted in #756). That lets through strings that are not valid unified addresses. Each of the first eight below is a correct Bech32m string with one rule broken, from ZIP-316 or the CompactSize encoding it specifies, andmainaccepts all eight:main0xE0), which Revision 0 forbids0x02000000utest)This PR decodes the whole address in
addressValidation/zcash.ts, next to the Cardano validator: Bech32m without the 90-character limit, F4Jumble⁻¹, the 16-byte HRP padding check, then the typecode-length items. Typecodes and lengths are read as canonical CompactSize of at most0x02000000, as librustzcash does. Typecodes must strictly increase, known receivers must have their exact lengths, and an address can't hold both P2PKH and P2SH. As ZIP-316 Revision 0 requires, it needs a Sapling or Orchard receiver and rejects MUST-understand metadata (0xE0–0xFC); other unknown typecodes are ignored, as the spec says. No new dependencies: it uses@scure/baseand@noble/hashes, already inpackage.json.Tests:
addressValidation/zcash.test.ts:unified_address.json: Orchard only, Sapling only, P2PKH + Orchard, all three, Orchard + an unknown typecode);0xC0);validateAddress.test.ts, at1address, the empty string);validateAddress.test.ts: an official Orchard-only address passes, and the 69-character transparent-only one fails.@scure/base1.2.6 and@noble/hashes1.8.0 (the versions inbun.lock): all pass, and all 60 official mainnet vectors are accepted. Stricttscis clean on the new module and its tests, andbiome check(1.9.3) is clean on all four changed files. I could not run the whole app's suite locally, so CI is the check forvalidateAddress.test.ts.One note for later: a valid unified address is not always payable by every route. A Sapling-only address has no Orchard or transparent receiver, for example. That is a route check, not part of this PR.
🤖 Generated with Claude Code