Skip to content

Run each generator once when regenerating all formats, and fix source file URLs#126

Draft
daira wants to merge 17 commits into
zcash:masterfrom
daira:optimize-regenerate
Draft

Run each generator once when regenerating all formats, and fix source file URLs#126
daira wants to merge 17 commits into
zcash:masterfrom
daira:optimize-regenerate

Conversation

@daira
Copy link
Copy Markdown
Contributor

@daira daira commented Apr 4, 2026

Summary

  • Add -o/--output-dir and -n/--name options to test vector generators. When -o is given, all three output formats (rust, json, zcash) are written in a single run, avoiding redundant computation.
  • Move rustfmt invocation from regenerate.sh into output.py so it is applied consistently regardless of how generators are invoked.
  • Update regenerate.sh to use the new mode when the first argument is all, reducing total generation time by ~3x.

Fixes #125.

🤖 Generated with Claude Code

nuttycom and others added 14 commits April 2, 2026 14:39
… 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>
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>
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>
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>
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 zcash#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>
@daira daira added the enhancement New feature or request label Apr 4, 2026
@daira
Copy link
Copy Markdown
Contributor Author

daira commented Apr 4, 2026

This needs a change to the repo configuration in order to change the required check to "Verify test vectors". I'll wait until it's been reviewed before doing that.

@daira daira force-pushed the optimize-regenerate branch from 9754803 to b0fac1d Compare April 4, 2026 03:25
@daira daira marked this pull request as draft April 4, 2026 03:26
@daira
Copy link
Copy Markdown
Contributor Author

daira commented Apr 4, 2026

Blocked-by #119.

daira and others added 2 commits April 4, 2026 04:39
Add -o/--output-dir and -n/--name options to the test vector
generators. When -o is given, all three output formats (rust, json,
zcash) are written in a single run, avoiding redundant computation.
The -t and -o flags are mutually exclusive.

Update regenerate.sh to use this mode when the first argument is
"all", reducing total generation time by ~3x.

Fixes zcash#125.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Instead of three parallel jobs each regenerating one format, run a
single job that generates all formats in one pass per generator.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@daira daira force-pushed the optimize-regenerate branch from b0fac1d to 7b9e3a9 Compare April 4, 2026 03:39
Addresses CodeQL warning about unrestricted token permissions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@daira daira changed the title Run each generator once when regenerating all formats Run each generator once when regenerating all formats, and fix source file URLs Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

regenerate.sh runs each generator 3x unnecessarily

2 participants