wasm: add TxOut.fromTransaction and rangeproofFromTransaction#160
Open
EvanWinget wants to merge 1 commit into
Open
wasm: add TxOut.fromTransaction and rangeproofFromTransaction#160EvanWinget wants to merge 1 commit into
EvanWinget wants to merge 1 commit into
Conversation
Two helpers for the common pattern of building a PSET input from a known transaction: - TxOut.fromTransaction(tx, vout) — extract TxOut at a given vout, with the witness stripped, suitable for use as witness_utxo. - TxOut.rangeproofFromTransaction(tx, vout) — extract the rangeproof bytes (or undefined for explicit outputs) for use with inUtxoRangeproof(). The witness-strip rule is non-obvious: PSET stores the rangeproof in a separate in_utxo_rangeproof field, so a TxOut used as witness_utxo must have its TxOutWitness cleared. Centralizing the strip in a named helper makes the input flow harder to misuse. The Result/Option asymmetry between the two helpers is deliberate: a missing rangeproof is a legitimate state (explicit outputs), but out-of-range vout is a programming error.
Author
|
Thank you in advance to whoever reviews this - I do have 2 more wasm changes that I'm hoping to propose, but I thought it might make sense to get feedback on this PR and #159 before opening any additional PRs |
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.
Two helpers for building a PSET input from a previously-broadcast or otherwise-known transaction:
TxOut.fromTransaction(tx, vout)to extract theTxOutat a given vout, with witness data stripped, suitable for use aswitness_utxo.TxOut.rangeproofFromTransaction(tx, vout)to extract the rangeproof bytes (Nonefor explicit outputs or out-of-range vout), for use withinUtxoRangeproof().Motivation
The witness section on a
TxOutmust not be carried into PSET'switness_utxofield. PSET stores the rangeproof in a dedicated input field (in_utxo_rangeproof) and the surjection proof is consumed during prior-tx verification and not re-carried. A caller who reaches intotx.outputs()[vout]and passes the result aswitness_utxoproduces a PSET that bloats serialization and may be rejected by strict-mode parsers.This rule is non-obvious because there's nothing on the type itself that hints at it, and the failure mode is silent until a downstream verifier rejects the PSET. Centralizing the strip in a named helper makes it unmissable: if you want a
witness_utxo, you go throughfromTransaction.rangeproofFromTransactionis a smaller convenience for the matching consumer (inUtxoRangeproof) — pullingtx.outputs()[vout].witness.rangeproofand serializing it is boilerplate every PSET-building caller would otherwise repeat.