Skip to content

Add test vectors for ZIP 316 Revision 2 addresses, UFVKs and UIVKs#119

Merged
nuttycom merged 14 commits into
masterfrom
zip316_r2
Apr 7, 2026
Merged

Add test vectors for ZIP 316 Revision 2 addresses, UFVKs and UIVKs#119
nuttycom merged 14 commits into
masterfrom
zip316_r2

Conversation

@nuttycom
Copy link
Copy Markdown
Contributor

@nuttycom nuttycom commented Mar 31, 2026

Fixes #117

@nuttycom nuttycom force-pushed the zip316_r2 branch 5 times, most recently from 956c76e to ae912df Compare April 1, 2026 16:50
@nuttycom nuttycom marked this pull request as ready for review April 1, 2026 16:59
@nuttycom nuttycom requested review from daira and nullcopy April 1, 2026 16:59
Comment thread test-vectors/rust/unified_address_r2.rs Outdated
Comment thread test-vectors/json/unified_address_r2.json Outdated
Comment thread test-vectors/zcash/unified_address_r2.json Outdated
Comment thread zcash_test_vectors/unified_address_r2.py
… unknown items

Add EXPIRY_HEIGHT_ITEM (0xE0) and EXPIRY_TIME_ITEM (0xE1) constants.
Change decode_unified to accumulate unknown items as a list instead
of asserting on duplicates, since R2 encodings can contain multiple
metadata typecodes. Update R0 generator assertions accordingly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
nuttycom and others added 5 commits April 3, 2026 09:42
Generate test vectors for R2 Unified Addresses with zu (shielded-only)
and tu (transparent-enabled) HRPs, and optional address expiry metadata
(typecodes 0xE0 and 0xE1). Produces 60 vectors covering Sapling-only,
Orchard-only, mixed shielded, and transparent+shielded combinations
with various expiry configurations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Generate test vectors demonstrating the full UFVK (uvf) -> UIVK (uvi)
-> UA (zu/tu) derivation chain for Revision 2 unified viewing keys.

Each of the 20 vectors includes:
- R2 UFVK with P2PKH, P2SH (ZIP 48 2-of-3 sortedmulti), Sapling,
  and Orchard FVK items, plus optional expiry metadata
- Derived R2 UIVK with template transformation (/** -> /*), key
  derivation at non-hardened index 0, and metadata retention
- Derived R2 UA with P2SH address computation via BIP 67 sorted
  redeem script and expiry propagation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extract derive_sapling_fvk, derive_sapling_ivk, derive_orchard_fvk,
and derive_orchard_ivk into viewing_key_derivation.py. These were
duplicated across unified_full_viewing_keys.py,
unified_incoming_viewing_keys.py, and unified_viewing_keys_r2.py.

Each function returns the serialized bytes along with intermediate
key objects needed by callers for further derivation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The UFVK and UIVK bech32m strings were being stored via .encode()
as hex-encoded UTF-8 bytes (Vec<u8>), while unified addresses were
already stored as plain strings (&'static str). Change all viewing
key generators to store the bech32m string directly, consistent with
how addresses are stored.

Affects: unified_full_viewing_keys, unified_incoming_viewing_keys,
unified_viewing_keys_r2.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nuttycom nuttycom requested review from daira and nullcopy and removed request for daira April 3, 2026 15:43
Copy link
Copy Markdown
Contributor Author

@nuttycom nuttycom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK of 32316b6 and the previous commit, which I paired with @daira on.

@daira daira force-pushed the zip316_r2 branch 2 times, most recently from 8e129c7 to 9d8a3b1 Compare April 3, 2026 21:18
Comment thread zcash_test_vectors/unified_viewing_keys_r2.py Outdated
Comment thread zcash_test_vectors/unified_viewing_keys_r2.py Outdated
Comment thread zcash_test_vectors/viewing_key_derivation.py
Comment thread zcash_test_vectors/viewing_key_derivation.py
daira and others added 2 commits April 4, 2026 01:26
Per ZIP 316: "A Unified Address or Unified Viewing Key MUST contain
at least one non-metadata Item." Metadata is typecodes 0xC0..=0xFC.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Verify that expiry height and time metadata survive encode/decode
in the R2 viewing key generator, matching the existing assertions
in the R2 address generator.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
daira and others added 3 commits April 4, 2026 01:26
Generate the random bool before checking the condition, so that
changes to the condition don't disrupt the RNG stream for subsequent
test vectors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sapling needs the account_key for diversifier derivation (find_j,
diversifier, pk_d), unlike Orchard where the FVK has those methods.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update each generator's filename argument to render_tv to use the
correct path relative to the repo root, so the URLs in generated
test vectors point to the actual source files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
daira and others added 2 commits April 4, 2026 02:41
The parameter now holds a module path (e.g.
zcash_test_vectors/orchard/key_components) rather than a bare
filename.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
As suggested by @vivek-arte in #112. This does not change the
output with the current version of rustfmt but is good practice
for forward compatibility.

Co-Authored-By: Vivek Arte <46618816+vivek-arte@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor Author

@nuttycom nuttycom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

@nullcopy nullcopy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 934d70b

@nuttycom nuttycom merged commit 667c929 into master Apr 7, 2026
7 checks passed
@nuttycom nuttycom deleted the zip316_r2 branch April 7, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create test vectors for ZIP 316 Revision 2 addresses, UIVKs and UFVKs

3 participants