Skip to content

Commit

Permalink
psbt: verify that commitments are the correct type
Browse files Browse the repository at this point in the history
Remove the get logic attempting to check lengths with the validation
function, since a) its not needed and b) validation now requires correct
values for some fields rather than just the correct length.
  • Loading branch information
jgriffiths committed Jul 5, 2022
1 parent 238964f commit f8dac44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
13 changes: 5 additions & 8 deletions src/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static int pset_input_field_verify(uint32_t field_type,
case PSET_IN_ISSUANCE_VALUE_COMMITMENT:
case PSET_IN_ISSUANCE_INFLATION_KEYS_COMMITMENT:
/* 33 byte commitments */
if (val_len != ASSET_COMMITMENT_LEN)
if (confidential_value_length_from_bytes(val) != WALLY_TX_ASSET_CT_LEN)
return WALLY_EINVAL;
break;
case PSET_IN_ISSUANCE_VALUE_RANGEPROOF:
Expand Down Expand Up @@ -343,9 +343,12 @@ static int pset_output_field_verify(uint32_t field_type,
return WALLY_EINVAL;
break;
case PSET_OUT_VALUE_COMMITMENT:
if (confidential_value_length_from_bytes(val) != WALLY_TX_ASSET_CT_LEN)
return WALLY_EINVAL;
break;
case PSET_OUT_ASSET_COMMITMENT:
/* 33 byte commitments */
if (val_len != ASSET_COMMITMENT_LEN)
if (confidential_asset_length_from_bytes(val) != WALLY_TX_ASSET_CT_LEN)
return WALLY_EINVAL;
break;
case PSET_OUT_BLINDING_PUBKEY:
Expand Down Expand Up @@ -401,12 +404,6 @@ static int pset_field_get(const struct wally_map *map_in, uint32_t type,
*written = 0;
if (!map_in || !bytes_out || !map_in->verify_fn || !written)
return WALLY_EINVAL;
if (map_in->verify_fn == pset_map_output_field_verify &&
(type == PSET_OUT_BLINDING_PUBKEY || type == PSET_OUT_ECDH_PUBKEY)) {
if (len != EC_PUBLIC_KEY_LEN)
return WALLY_EINVAL; /* Pubkey: check length only, not content */
} else if (map_in->verify_fn(NULL, type, bytes_out, len) != WALLY_OK)
return WALLY_EINVAL;
ret = wally_map_find_integer(map_in, type, &index);
if (ret == WALLY_OK && index) {
/* Found */
Expand Down
20 changes: 11 additions & 9 deletions src/swig_python/contrib/psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ def test_psbt(self):
if is_elements_build():
dummy_nonce = bytearray(b'\x00' * WALLY_TX_ASSET_CT_NONCE_LEN)
dummy_bf = bytearray(b'\x00' * BLINDING_FACTOR_LEN)
dummy_commitment = bytearray(b'\x44' * ASSET_COMMITMENT_LEN)
dummy_asset_commitment = bytearray(b'\x0a' * ASSET_COMMITMENT_LEN)
dummy_value_commitment = bytearray(b'\x08' * WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN)
dummy_nonce_commitment = bytearray(b'\x02' * ASSET_COMMITMENT_LEN)
dummy_asset = bytearray(b'\x00' * ASSET_TAG_LEN)
dummy_nonce = bytearray(b'\x77' * ASSET_TAG_LEN)

Expand Down Expand Up @@ -430,18 +432,18 @@ def test_psbt(self):
# PSET: blinded issuance amount (issuance amount commitment)
(psbt_set_input_issuance_amount_commitment,
psbt_get_input_issuance_amount_commitment,
psbt_clear_input_issuance_amount_commitment, dummy_commitment, dummy_txid),
psbt_clear_input_issuance_amount_commitment, dummy_value_commitment, dummy_txid),
# PSET: blinded issuance amount rangeproof
(psbt_set_input_issuance_amount_rangeproof, psbt_get_input_issuance_amount_rangeproof,
psbt_clear_input_issuance_amount_rangeproof, dummy_bytes, None),
# PSET: issuance blinding nonce
(psbt_set_input_issuance_blinding_nonce,
psbt_get_input_issuance_blinding_nonce,
psbt_clear_input_issuance_blinding_nonce, dummy_nonce, dummy_commitment),
psbt_clear_input_issuance_blinding_nonce, dummy_nonce, dummy_nonce_commitment),
# PSET: issuance blinding entropy
(psbt_set_input_issuance_asset_entropy,
psbt_get_input_issuance_asset_entropy,
psbt_clear_input_issuance_asset_entropy, dummy_nonce, dummy_commitment),
psbt_clear_input_issuance_asset_entropy, dummy_nonce, dummy_asset_commitment),
# PSET: blinded issuance amount value rangeproof
# (Confusing: this proves the blinded issuance amount matches
# the unblinded amount, for constructors/blinders use)
Expand All @@ -453,13 +455,13 @@ def test_psbt(self):
psbt_clear_input_pegin_claim_script, dummy_bytes, None),
# PSET: peg-in genesis blockhash
(psbt_set_input_pegin_genesis_blockhash, psbt_get_input_pegin_genesis_blockhash,
psbt_clear_input_pegin_genesis_blockhash, dummy_txid, dummy_commitment),
psbt_clear_input_pegin_genesis_blockhash, dummy_txid, dummy_asset_commitment),
# PSET: peg-in txout proof
(psbt_set_input_pegin_txout_proof, psbt_get_input_pegin_txout_proof,
psbt_clear_input_pegin_txout_proof, dummy_bytes, None),
# PSET: blinded number of inflation keys (issuance keys commitment)
(psbt_set_input_inflation_keys_commitment, psbt_get_input_inflation_keys_commitment,
psbt_clear_input_inflation_keys_commitment, dummy_commitment, dummy_txid),
psbt_clear_input_inflation_keys_commitment, dummy_value_commitment, dummy_txid),
# PSET: blinded inflation keys rangeproof
(psbt_set_input_inflation_keys_rangeproof, psbt_get_input_inflation_keys_rangeproof,
psbt_clear_input_inflation_keys_rangeproof, dummy_bytes, None),
Expand Down Expand Up @@ -542,11 +544,11 @@ def test_psbt(self):
cases = [
# PSET: blinded issuance amount (issuance amount commitment)
(psbt_set_output_value_commitment, psbt_get_output_value_commitment,
psbt_clear_output_value_commitment, dummy_commitment, dummy_txid),
psbt_clear_output_value_commitment, dummy_value_commitment, dummy_txid),
(psbt_set_output_asset, psbt_get_output_asset,
psbt_clear_output_asset, dummy_asset, dummy_commitment),
psbt_clear_output_asset, dummy_asset, dummy_asset_commitment),
(psbt_set_output_asset_commitment, psbt_get_output_asset_commitment,
psbt_clear_output_asset_commitment, dummy_commitment, dummy_txid),
psbt_clear_output_asset_commitment, dummy_asset_commitment, dummy_txid),
(psbt_set_output_value_rangeproof, psbt_get_output_value_rangeproof,
psbt_clear_output_value_rangeproof, dummy_bytes, None),
(psbt_set_output_asset_surjectionproof,
Expand Down

0 comments on commit f8dac44

Please sign in to comment.