Skip to content

wasm: add TxOut.fromTransaction and rangeproofFromTransaction#160

Open
EvanWinget wants to merge 1 commit into
Blockstream:masterfrom
EvanWinget:wasm/txout-from-transaction
Open

wasm: add TxOut.fromTransaction and rangeproofFromTransaction#160
EvanWinget wants to merge 1 commit into
Blockstream:masterfrom
EvanWinget:wasm/txout-from-transaction

Conversation

@EvanWinget
Copy link
Copy Markdown

Two helpers for building a PSET input from a previously-broadcast or otherwise-known transaction:

  • TxOut.fromTransaction(tx, vout) to extract the TxOut at a given vout, with witness data stripped, suitable for use as witness_utxo.
  • TxOut.rangeproofFromTransaction(tx, vout) to extract the rangeproof bytes (None for explicit outputs or out-of-range vout), for use with inUtxoRangeproof().

Motivation

The witness section on a TxOut must not be carried into PSET's witness_utxo field. 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 into tx.outputs()[vout] and passes the result as witness_utxo produces 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 through fromTransaction.

rangeproofFromTransaction is a smaller convenience for the matching consumer (inUtxoRangeproof) — pulling tx.outputs()[vout].witness.rangeproof and serializing it is boilerplate every PSET-building caller would otherwise repeat.

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.
@EvanWinget
Copy link
Copy Markdown
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

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.

1 participant