Skip to content

Comments

Compute v5 transaction IDs locally per ZIP 244#547

Open
zmanian wants to merge 1 commit intozcash:masterfrom
zmanian:zip244-txid-computation
Open

Compute v5 transaction IDs locally per ZIP 244#547
zmanian wants to merge 1 commit intozcash:masterfrom
zmanian:zip244-txid-computation

Conversation

@zmanian
Copy link

@zmanian zmanian commented Feb 11, 2026

Summary

  • Implements ZIP 244 BLAKE2b-256 hash tree for computing non-malleable v5 transaction IDs during parsing, resolving the core of issue Implement ZIP 244 txid logic for v5 transactions #392 (filed May 2022)
  • Vendors the pure-Go BLAKE2b implementation from golang.org/x/crypto@v0.45.0 into parser/internal/blake2b/, adding personalization parameter support (~3 lines of modification to the digest struct and Reset())
  • Re-parses Transaction.rawBytes in computeV5TxID() to feed fields into 18 personalized BLAKE2b-256 digests matching the ZIP 244 hash tree, including correct handling of the v5 shared sapling anchor (buffered and replayed per-spend in the noncompact digest)
  • All 10 test vectors from testdata/tx_v5.json now validate txids (previously skipped with a TODO comment)

Motivation

lightwalletd returns incorrect txids for v5 transactions. The workaround (PR #393) fetches txids from zcashd/zebrad via a verbose getblock RPC call instead of computing them locally. This creates a trust dependency on the backing node for txid correctness. The core blocker was that Go's golang.org/x/crypto/blake2b package doesn't support the personalization parameter required by ZIP 244.

Changes

File Action Description
parser/internal/blake2b/blake2b.go New Vendored BLAKE2b-256 with personalization support
parser/internal/blake2b/compress.go New Vendored pure-Go compression function (unmodified)
parser/internal/blake2b/LICENSE New BSD license from golang.org/x/crypto
parser/internal/blake2b/blake2b_test.go New Standard + personalized test vectors (verified with Python hashlib)
parser/zip244.go New ZIP 244 hash tree: computeV5TxID + sub-functions for header, transparent, sapling, orchard digests
parser/zip244_test.go New Tests against all 10 tx_v5.json vectors, both standalone and via ParseFromSlice
parser/transaction.go Modified 7 lines added to ParseFromSlice to call computeV5TxID for v5 transactions
parser/transaction_test.go Modified Replaced "can't check txid" comment with actual txid validation

Deferred to follow-up PRs

  • Remove the verbose RPC workaround in common.go:getBlockFromRPC (simplify to single getblock verbose=0 call)
  • Pre-v5 txid computation (double-SHA256 of rawBytes for v1-v4)

Test plan

  • go test ./parser/internal/blake2b/... -- blake2b unit tests pass (standard + personalized vectors)
  • go test ./parser/... -- all parser tests pass including new txid validation against 10 test vectors
  • go vet ./parser/... ./parser/internal/blake2b/ -- clean
  • go build ./... -- clean build
  • Manual verification: compare computed txids against a block explorer for a sample of real mainnet v5 transactions

Closes #392

Generated with Claude Code

lightwalletd has returned incorrect txids for v5 transactions since
NU5 activation (issue zcash#392). The workaround fetches txids from zcashd
via a verbose getblock RPC call. This commit implements the ZIP 244
BLAKE2b-256 hash tree so v5 txids are computed during parsing.

The core blocker was that Go's golang.org/x/crypto/blake2b package
lacks personalization support. This is resolved by vendoring the
pure-Go BLAKE2b implementation into an internal package and adding
the ~3 lines needed for personalization parameter injection.

The ZIP 244 hash tree re-parses Transaction.rawBytes to feed fields
into 18 personalized BLAKE2b-256 digests. The v5 shared sapling
anchor is buffered and replayed per-spend in the noncompact digest.

All 10 test vectors from testdata/tx_v5.json now validate txids.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Implement ZIP 244 txid logic for v5 transactions

1 participant