fix(pivx): compute correct txid for Sapling transactions#1606
Open
pragmaxim wants to merge 1 commit into
Open
Conversation
PIVX Sapling transactions (version >= 3) include shielded fields (valueBalance, vShieldedSpend, vShieldedOutput, bindingSig) after the transparent part. wire.MsgTx.TxHash() only hashes the transparent fields, producing a phantom txid that is stored in the address index. Fix by computing the txid as sha256d of the full raw transaction bytes for Sapling transactions, matching PIVX's consensus definition. Also fix a pre-existing encoding bug in ParseTx: it used WitnessEncoding via Deserialize(), which can misinterpret a Sapling tx with 0 inputs as a segwit transaction (0x00 0x01 marker). Now reads the version first and uses BaseEncoding for version >= 3, matching PivxDecodeTransactions. Fixes trezor#1522
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.
Fixes #1522
Problem
PIVX Sapling transactions (version >= 3) include shielded fields (valueBalance, vShieldedSpend, vShieldedOutput, bindingSig) after the transparent part.
wire.MsgTx.TxHash()only hashes the transparent fields viaSerializeNoWitness, producing a phantom txid that gets written to the address index. Subsequent API queries for that txid return HTTP 500.Also,
ParseTxusedWitnessEncodingviaDeserialize(), which can misinterpret a Sapling tx with 0 inputs as a segwit transaction (bytes0x00 0x01are read as the segwit marker+flags).Fix
For Sapling transactions (version >= 3), compute the txid as
sha256d(full raw transaction bytes), matching PIVX's consensus definition (SerializeHashinsrc/primitives/transaction.cpp). InParseTx, read the version first and useBaseEncodingfor version >= 3, matchingPivxDecodeTransactions.Changes
bchain/coins/pivx/pivxparser.go:PivxDecodeTransactions: track per-tx raw byte offsets in the block buffer, return raw tx dataParseBlock: override txid for Sapling txs withchainhash.DoubleHashH(rawTx)ParseTx: fix encoding selection (BaseEncoding for v>=3), override txid withchainhash.DoubleHashH(rawBytes)Testing
>= 3)Deployment
Existing databases with Sapling-era blocks must be re-indexed (delete data dir and re-sync). The fix only affects newly parsed data.