Skip to content

Commit dd4ab1a

Browse files
committed
Merge #199: pset: input: add explicit amount and asset, and their proofs
eb85a23 ci: cargo update cc (Leonardo Comandini) 6320c7c pset: input: add explicit amount and asset, and their proofs (Leonardo Comandini) Pull request description: They were added in ElementsProject/elements#1157 ACKs for top commit: apoelstra: ACK eb85a23 Tree-SHA512: f3126e66f210f0ee13f4d4751325f586ae8e35290791602a2066b3fe2b71914d51f2e012f20fed1ddd0690dc011586a8e1a6d115fc8815a959aff618f826486b
2 parents 40bf7c9 + eb85a23 commit dd4ab1a

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

contrib/test.sh

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if cargo --version | grep "1\.56"; then
88
cargo update -p once_cell --precise 1.13.1
99
cargo update -p which --precise 4.4.0
1010
cargo update -p byteorder --precise 1.4.3
11+
cargo update -p cc --precise 1.0.94
1112
fi
1213

1314
if [ "$DO_FEATURE_MATRIX" = true ]
@@ -53,6 +54,9 @@ if [ "$DO_FUZZ" = true ]
5354
then
5455
(
5556
cd fuzz
57+
if cargo --version | grep "1\.58"; then
58+
cargo update -p cc --precise 1.0.94
59+
fi
5660
cargo test --verbose
5761
./travis-fuzz.sh
5862
)

src/pset/map/input.rs

+53-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::{transaction::SighashTypeParseError, SchnorrSighashType};
3434
use crate::{AssetIssuance, BlockHash, EcdsaSighashType, Script, Transaction, TxIn, TxOut, Txid};
3535
use bitcoin::bip32::KeySource;
3636
use bitcoin::{PublicKey, key::XOnlyPublicKey};
37-
use secp256k1_zkp::{self, RangeProof, Tweak, ZERO_TWEAK};
37+
use secp256k1_zkp::{self, RangeProof, SurjectionProof, Tweak, ZERO_TWEAK};
3838

3939
use crate::{OutPoint, Sequence};
4040

@@ -148,6 +148,21 @@ const PSBT_ELEMENTS_IN_ISSUANCE_BLIND_VALUE_PROOF: u8 = 0x0f;
148148
/// in PSBT_ELEMENTS_IN_ISSUANCE_INFLATION_KEYS. If provided,
149149
/// PSBT_ELEMENTS_IN_ISSUANCE_INFLATION_KEYS_COMMITMENT must be provided too.
150150
const PSBT_ELEMENTS_IN_ISSUANCE_BLIND_INFLATION_KEYS_PROOF: u8 = 0x10;
151+
/// The explicit value for the input being spent. If provided,
152+
/// PSBT_ELEMENTS_IN_VALUE_PROOF must be provided too.
153+
const PSBT_ELEMENTS_IN_EXPLICIT_VALUE: u8 = 0x11;
154+
/// An explicit value rangeproof that proves that the value commitment in this
155+
/// input's UTXO matches the explicit value in PSBT_ELEMENTS_IN_EXPLICIT_VALUE.
156+
/// If provided, PSBT_ELEMENTS_IN_EXPLICIT_VALUE must be provided too.
157+
const PSBT_ELEMENTS_IN_VALUE_PROOF: u8 = 0x12;
158+
/// The explicit asset for the input being spent. If provided,
159+
/// PSBT_ELEMENTS_IN_ASSET_PROOF must be provided too.
160+
const PSBT_ELEMENTS_IN_EXPLICIT_ASSET: u8 = 0x13;
161+
/// An asset surjection proof with this input's asset as the only asset in the
162+
/// input set in order to prove that the asset commitment in the UTXO matches
163+
/// the explicit asset in PSBT_ELEMENTS_IN_EXPLICIT_ASSET. If provided,
164+
/// PSBT_ELEMENTS_IN_EXPLICIT_ASSET must be provided too.
165+
const PSBT_ELEMENTS_IN_ASSET_PROOF: u8 = 0x14;
151166
/// A key-value map for an input of the corresponding index in the unsigned
152167
/// transaction.
153168
#[derive(Clone, Debug, PartialEq)]
@@ -271,6 +286,14 @@ pub struct Input {
271286
pub in_issuance_blind_value_proof: Option<Box<RangeProof>>,
272287
/// Proof that blinded inflation keys matches the corresponding commitment
273288
pub in_issuance_blind_inflation_keys_proof: Option<Box<RangeProof>>,
289+
/// The explicit amount of the input
290+
pub amount: Option<u64>,
291+
/// The blind value rangeproof
292+
pub blind_value_proof: Option<Box<RangeProof>>,
293+
/// The input explicit asset
294+
pub asset: Option<AssetId>,
295+
/// The blind asset surjection proof
296+
pub blind_asset_proof: Option<Box<SurjectionProof>>,
274297
/// Other fields
275298
#[cfg_attr(
276299
feature = "serde",
@@ -287,7 +310,7 @@ pub struct Input {
287310

288311
impl Default for Input {
289312
fn default() -> Self {
290-
Self { non_witness_utxo: Default::default(), witness_utxo: Default::default(), partial_sigs: Default::default(), sighash_type: Default::default(), redeem_script: Default::default(), witness_script: Default::default(), bip32_derivation: Default::default(), final_script_sig: Default::default(), final_script_witness: Default::default(), ripemd160_preimages: Default::default(), sha256_preimages: Default::default(), hash160_preimages: Default::default(), hash256_preimages: Default::default(), previous_txid: Txid::all_zeros(), previous_output_index: Default::default(), sequence: Default::default(), required_time_locktime: Default::default(), required_height_locktime: Default::default(), tap_key_sig: Default::default(), tap_script_sigs: Default::default(), tap_scripts: Default::default(), tap_key_origins: Default::default(), tap_internal_key: Default::default(), tap_merkle_root: Default::default(), issuance_value_amount: Default::default(), issuance_value_comm: Default::default(), issuance_value_rangeproof: Default::default(), issuance_keys_rangeproof: Default::default(), pegin_tx: Default::default(), pegin_txout_proof: Default::default(), pegin_genesis_hash: Default::default(), pegin_claim_script: Default::default(), pegin_value: Default::default(), pegin_witness: Default::default(), issuance_inflation_keys: Default::default(), issuance_inflation_keys_comm: Default::default(), issuance_blinding_nonce: Default::default(), issuance_asset_entropy: Default::default(), in_utxo_rangeproof: Default::default(), in_issuance_blind_value_proof: Default::default(), in_issuance_blind_inflation_keys_proof: Default::default(), proprietary: Default::default(), unknown: Default::default() }
313+
Self { non_witness_utxo: Default::default(), witness_utxo: Default::default(), partial_sigs: Default::default(), sighash_type: Default::default(), redeem_script: Default::default(), witness_script: Default::default(), bip32_derivation: Default::default(), final_script_sig: Default::default(), final_script_witness: Default::default(), ripemd160_preimages: Default::default(), sha256_preimages: Default::default(), hash160_preimages: Default::default(), hash256_preimages: Default::default(), previous_txid: Txid::all_zeros(), previous_output_index: Default::default(), sequence: Default::default(), required_time_locktime: Default::default(), required_height_locktime: Default::default(), tap_key_sig: Default::default(), tap_script_sigs: Default::default(), tap_scripts: Default::default(), tap_key_origins: Default::default(), tap_internal_key: Default::default(), tap_merkle_root: Default::default(), issuance_value_amount: Default::default(), issuance_value_comm: Default::default(), issuance_value_rangeproof: Default::default(), issuance_keys_rangeproof: Default::default(), pegin_tx: Default::default(), pegin_txout_proof: Default::default(), pegin_genesis_hash: Default::default(), pegin_claim_script: Default::default(), pegin_value: Default::default(), pegin_witness: Default::default(), issuance_inflation_keys: Default::default(), issuance_inflation_keys_comm: Default::default(), issuance_blinding_nonce: Default::default(), issuance_asset_entropy: Default::default(), in_utxo_rangeproof: Default::default(), in_issuance_blind_value_proof: Default::default(), in_issuance_blind_inflation_keys_proof: Default::default(), amount: Default::default(), blind_value_proof: Default::default(), asset: Default::default(), blind_asset_proof: Default::default(), proprietary: Default::default(), unknown: Default::default() }
291314
}
292315
}
293316

@@ -705,6 +728,18 @@ impl Map for Input {
705728
PSBT_ELEMENTS_IN_ISSUANCE_BLIND_INFLATION_KEYS_PROOF => {
706729
impl_pset_prop_insert_pair!(self.in_issuance_blind_inflation_keys_proof <= <raw_key: _> | <raw_value : Box<RangeProof>>)
707730
}
731+
PSBT_ELEMENTS_IN_EXPLICIT_VALUE => {
732+
impl_pset_prop_insert_pair!(self.amount <= <raw_key: _> | <raw_value : u64>)
733+
}
734+
PSBT_ELEMENTS_IN_VALUE_PROOF => {
735+
impl_pset_prop_insert_pair!(self.blind_value_proof <= <raw_key: _> | <raw_value : Box<RangeProof>>)
736+
}
737+
PSBT_ELEMENTS_IN_EXPLICIT_ASSET => {
738+
impl_pset_prop_insert_pair!(self.asset <= <raw_key: _> | <raw_value : AssetId>)
739+
}
740+
PSBT_ELEMENTS_IN_ASSET_PROOF => {
741+
impl_pset_prop_insert_pair!(self.blind_asset_proof <= <raw_key: _> | <raw_value : Box<SurjectionProof>>)
742+
}
708743
_ => match self.proprietary.entry(prop_key) {
709744
Entry::Vacant(empty_key) => {
710745
empty_key.insert(raw_value);
@@ -903,6 +938,22 @@ impl Map for Input {
903938
rv.push_prop(self.in_issuance_blind_inflation_keys_proof as <PSBT_ELEMENTS_IN_ISSUANCE_BLIND_INFLATION_KEYS_PROOF, _>)
904939
}
905940

941+
impl_pset_get_pair! {
942+
rv.push_prop(self.amount as <PSBT_ELEMENTS_IN_EXPLICIT_VALUE, _>)
943+
}
944+
945+
impl_pset_get_pair! {
946+
rv.push_prop(self.blind_value_proof as <PSBT_ELEMENTS_IN_VALUE_PROOF, _>)
947+
}
948+
949+
impl_pset_get_pair! {
950+
rv.push_prop(self.asset as <PSBT_ELEMENTS_IN_EXPLICIT_ASSET, _>)
951+
}
952+
953+
impl_pset_get_pair! {
954+
rv.push_prop(self.blind_asset_proof as <PSBT_ELEMENTS_IN_ASSET_PROOF, _>)
955+
}
956+
906957
for (key, value) in self.proprietary.iter() {
907958
rv.push(raw::Pair {
908959
key: key.to_key(),

0 commit comments

Comments
 (0)