Skip to content

Commit

Permalink
psbt: remove the psbt argument to pset_check_proof
Browse files Browse the repository at this point in the history
If we want to expose proof checking on inputs and outputs, we can't rely on
having the parent psbt at hand.
  • Loading branch information
jgriffiths committed Dec 21, 2023
1 parent f75a056 commit c4c81e7
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,8 @@ int wally_psbt_output_get_blinding_status(const struct wally_psbt_output *output
/* Verify that unblinded values, their commitment, and commitment proof
* are provided/elided where required, and proofs are valid if provided.
*/
static bool pset_check_proof(const struct wally_psbt *psbt,
const struct wally_psbt_input *in,
static bool pset_check_proof(const struct wally_psbt_input *in,
const struct wally_tx_output *utxo,
const struct wally_psbt_output *out,
uint64_t value_bit,
uint64_t commitment_key, uint64_t proof_key, uint32_t flags)
Expand Down Expand Up @@ -1017,7 +1017,6 @@ static bool pset_check_proof(const struct wally_psbt *psbt,
*/
if (is_utxo_value || is_utxo_asset) {
/* Get explicit value and commitments from the inputs UTXO */
const struct wally_tx_output *utxo = utxo_from_input(psbt, in);
has_value = is_utxo_value && in->has_amount;
value = in->amount;
if (utxo) {
Expand Down Expand Up @@ -2403,18 +2402,18 @@ static int pull_psbt_input(const struct wally_psbt *psbt,
/* Commitment key isn't used for PSET_IN_EXPLICIT_VALUE/ASSET */
const uint64_t unused_key = 0xffffffff;

/* Explicit values are only valid if we have an input UTXO */
#define PSET_UTXO_BITS (PSET_FT(PSBT_IN_NON_WITNESS_UTXO) | PSET_FT(PSBT_IN_WITNESS_UTXO))
/* Explicit values are only valid if we have an input witness UTXO */
const struct wally_tx_output *utxo = result->witness_utxo;

if (!pset_check_proof(psbt, result, NULL, PSET_FT(PSET_IN_ISSUANCE_VALUE),
if (!pset_check_proof(result, utxo, NULL, PSET_FT(PSET_IN_ISSUANCE_VALUE),
PSET_IN_ISSUANCE_VALUE_COMMITMENT,
PSET_IN_ISSUANCE_BLIND_VALUE_PROOF, flags) ||
!pset_check_proof(psbt, result, NULL, PSET_FT(PSET_IN_ISSUANCE_INFLATION_KEYS_AMOUNT),
!pset_check_proof(result, utxo, NULL, PSET_FT(PSET_IN_ISSUANCE_INFLATION_KEYS_AMOUNT),
PSET_IN_ISSUANCE_INFLATION_KEYS_COMMITMENT,
PSET_IN_ISSUANCE_BLIND_INFLATION_KEYS_PROOF, flags) ||
!pset_check_proof(psbt, result, NULL, PSET_FT(PSET_IN_EXPLICIT_VALUE),
!pset_check_proof(result, utxo, NULL, PSET_FT(PSET_IN_EXPLICIT_VALUE),
unused_key, PSET_IN_VALUE_PROOF, strict_flags) ||
!pset_check_proof(psbt, result, NULL, PSET_FT(PSET_IN_EXPLICIT_ASSET),
!pset_check_proof(result, utxo, NULL, PSET_FT(PSET_IN_EXPLICIT_ASSET),
unused_key, PSET_IN_ASSET_PROOF, strict_flags))
ret = WALLY_EINVAL;
}
Expand Down Expand Up @@ -2548,10 +2547,10 @@ static int pull_psbt_output(const struct wally_psbt *psbt,

#ifdef BUILD_ELEMENTS
if (ret == WALLY_OK && is_pset) {
if (!pset_check_proof(psbt, NULL, result, PSBT_FT(PSBT_OUT_AMOUNT),
if (!pset_check_proof(NULL, NULL, result, PSBT_FT(PSBT_OUT_AMOUNT),
PSET_OUT_VALUE_COMMITMENT,
PSET_OUT_BLIND_VALUE_PROOF, flags) ||
!pset_check_proof(psbt, NULL, result, PSET_FT(PSET_OUT_ASSET),
!pset_check_proof(NULL, NULL, result, PSET_FT(PSET_OUT_ASSET),
PSET_OUT_ASSET_COMMITMENT,
PSET_OUT_BLIND_ASSET_PROOF, flags))
ret = WALLY_EINVAL;
Expand Down

0 comments on commit c4c81e7

Please sign in to comment.