fix(zcash): use S.2 transparent_sig_digest for Orchard sighash in shield txs#247
Merged
Merged
Conversation
…eld txs
ZIP-244 §4.9 requires the S.2 form of the transparent digest when computing
the Orchard sighash for transactions with non-empty transparent inputs (shield
txs). S.2 includes UTXO amounts, scriptPubKeys, and an empty txin_sig_digest;
the T.1 (txid) form omits these.
Previously the firmware computed the T.1 form and verified it against the
sidecar-provided value, then used that digest in the Orchard sighash. This
produced Orchard spend-auth and binding signatures that passed local
BatchValidator checks but were rejected by Zebra ("could not validate orchard
proof") because Zebra uses S.2 when verifying Orchard sigs.
Add zcash_compute_orchard_transparent_sig_digest which:
- Returns T.1 when n_inputs == 0 (deshield / private-send, per §4.10b)
- Returns S.2 with empty txin_sig_digest when n_inputs > 0 (shield tx)
Switch zcash_finalize_transparent_digest to use the new function so both the
firmware verification and the Orchard sighash computation use S.2.
The prior commit included an unrelated clang-format pointer-style change (EthereumSignTx *msg → EthereumSignTx* msg) that breaks CI lint-format. Revert to alpha to keep the PR focused on the Zcash S.2 fix only.
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.
Problem
Shield transactions (transparent input → Orchard output) broadcast with "could not validate orchard proof" from Zebra. Orchard spend-auth and binding signatures were being rejected by the network.
Root Cause
ZIP-244 §4.9 defines two forms of the transparent digest:
prevouts || sequences || outputshash_type || prevouts || amounts || scripts || sequences || outputs || empty_txin_hashThe firmware was computing T.1 to verify the sidecar-provided transparent_digest, then using T.1 in the Orchard sighash. Zebra verifies Orchard sigs with S.2 for any tx with transparent inputs → signatures invalid at the network.
Fix
Add
zcash_compute_orchard_transparent_sig_digest:n_inputs == 0→ delegates to T.1 (deshield / private-send, per §4.10b)n_inputs > 0→ computes S.2:BLAKE2b("ZTxIdTranspaHash", 0x01 || prevouts || amounts || scripts || sequences || outputs || BLAKE2b("Zcash___TxInHash", ""))Switch
zcash_finalize_transparent_digestto use the new function so firmware verifies and signs with the same form Zebra uses.Files
lib/firmware/zcash.c— newzcash_compute_orchard_transparent_sig_digestfunctioninclude/keepkey/firmware/zcash.h— declarationlib/firmware/fsm_msg_zcash.h—zcash_finalize_transparent_digestuses new functionlib/firmware/ethereum_contracts/zxappliquid.c— clang-format cleanup frommake formatTest Plan