Skip to content

Commit cc12b8e

Browse files
committed
blind: TxInType -> CtLocation
1 parent e4144e6 commit cc12b8e

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

src/blind.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -916,17 +916,30 @@ impl TxIn {
916916
}
917917
}
918918

919-
/// Data structure for Unifying inputs and pseudo-inputs.
919+
/// Inputs or pseudo-inputs.
920920
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash)]
921-
pub enum TxInType {
921+
pub enum CtLocationType {
922922
/// Regular input
923-
Input(usize),
924-
/// Issuance Pseudo-input
925-
Issuance(usize),
926-
/// Re-issuance pseudo-input
927-
ReIssuance(usize),
923+
Input,
924+
925+
/// Issuance pseudo-input
926+
Issuance,
927+
928+
/// Reissuance pseudo-input
929+
Reissuance,
928930
}
929931

932+
/// Data structure for Unifying inputs and pseudo-inputs.
933+
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash)]
934+
pub struct CtLocation {
935+
/// Input index
936+
pub input_index: usize,
937+
938+
/// Input or pseudo-input type
939+
pub ty: CtLocationType,
940+
}
941+
942+
930943
impl Transaction {
931944
/// Verify that the transaction has correctly calculated blinding
932945
/// factors and they CT verification equation holds.
@@ -1078,7 +1091,7 @@ impl Transaction {
10781091
secp: &Secp256k1<C>,
10791092
spent_utxo_secrets: &[TxOutSecrets],
10801093
blind_issuances: bool,
1081-
) -> Result<BTreeMap<TxInType, (AssetBlindingFactor, ValueBlindingFactor, SecretKey)>, BlindError>
1094+
) -> Result<BTreeMap<CtLocation, (AssetBlindingFactor, ValueBlindingFactor, SecretKey)>, BlindError>
10821095
where
10831096
R: RngCore + CryptoRng,
10841097
C: Signing,
@@ -1090,13 +1103,13 @@ impl Transaction {
10901103
let (iss_vbf, iss_sk, tkn_vbf, tkn_sk) = txin.blind_issuances(secp, rng)?;
10911104
if txin.asset_issuance.amount.is_confidential() {
10921105
blinds.insert(
1093-
TxInType::Issuance(i),
1106+
CtLocation{ input_index: i, ty: CtLocationType::Issuance },
10941107
(AssetBlindingFactor::zero(), iss_vbf, iss_sk),
10951108
);
10961109
}
10971110
if txin.asset_issuance.inflation_keys.is_confidential() {
10981111
blinds.insert(
1099-
TxInType::ReIssuance(i),
1112+
CtLocation{ input_index: i, ty: CtLocationType::Reissuance },
11001113
(AssetBlindingFactor::zero(), tkn_vbf, tkn_sk),
11011114
);
11021115
}
@@ -1144,7 +1157,8 @@ impl Transaction {
11441157
spent_utxo_secrets,
11451158
)?;
11461159

1147-
blinds.insert(TxInType::Input(i), (abf, vbf, ephemeral_sk));
1160+
let location = CtLocation { input_index: i, ty: CtLocationType::Input};
1161+
blinds.insert(location, (abf, vbf, ephemeral_sk));
11481162
out_secrets.push(TxOutSecrets::new(
11491163
out.asset.explicit().unwrap(),
11501164
abf,
@@ -1184,7 +1198,8 @@ impl Transaction {
11841198
&out_secrets,
11851199
)?;
11861200

1187-
blinds.insert(TxInType::Input(last_index), (abf, vbf, ephemeral_sk));
1201+
let location = CtLocation{ input_index: last_index, ty: CtLocationType::Input };
1202+
blinds.insert(location, (abf, vbf, ephemeral_sk));
11881203
self.output[last_index] = conf_out;
11891204
Ok(blinds)
11901205
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub use bitcoin::hashes;
7878
pub use crate::address::{Address, AddressError, AddressParams};
7979
pub use crate::blind::{
8080
BlindAssetProofs, BlindError, BlindValueProofs, ConfidentialTxOutError, RangeProofMessage,
81-
SurjectionInput, TxOutError, TxOutSecrets, UnblindError, VerificationError, TxInType,
81+
SurjectionInput, TxOutError, TxOutSecrets, UnblindError, VerificationError, CtLocation, CtLocationType,
8282
};
8383
pub use crate::block::ExtData as BlockExtData;
8484
pub use crate::block::{Block, BlockHeader};

src/pset/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ use crate::{
4747
TxOutSecrets,
4848
};
4949
use crate::{
50-
LockTime, OutPoint, Sequence, SurjectionInput, Transaction, TxIn, TxInType,
51-
TxInWitness, TxOut, TxOutWitness, Txid,
50+
LockTime, OutPoint, Sequence, SurjectionInput, Transaction, TxIn,
51+
TxInWitness, TxOut, TxOutWitness, Txid, CtLocation, CtLocationType,
5252
};
5353
use secp256k1_zkp::rand::{CryptoRng, RngCore};
5454
use secp256k1_zkp::{self, RangeProof, SecretKey, SurjectionProof};
@@ -481,7 +481,7 @@ impl PartiallySignedTransaction {
481481
rng: &mut R,
482482
secp: &secp256k1_zkp::Secp256k1<C>,
483483
inp_txout_sec: &HashMap<usize, TxOutSecrets>,
484-
) -> Result<BTreeMap<TxInType, (AssetBlindingFactor, ValueBlindingFactor, SecretKey)>, PsetBlindError> {
484+
) -> Result<BTreeMap<CtLocation, (AssetBlindingFactor, ValueBlindingFactor, SecretKey)>, PsetBlindError> {
485485
let (inp_secrets, outs_to_blind) = self.blind_checks(inp_txout_sec)?;
486486

487487
let mut ret = BTreeMap::new(); // return all the random values used
@@ -541,7 +541,8 @@ impl PartiallySignedTransaction {
541541
));
542542
}
543543
// return blinding factors used
544-
ret.insert(TxInType::Input(i), (abf, vbf, ephemeral_sk));
544+
let location = CtLocation{ input_index: i, ty: CtLocationType::Input};
545+
ret.insert(location, (abf, vbf, ephemeral_sk));
545546
}
546547

547548
// safe to unwrap because we have checked that there is atleast one output to blind
@@ -582,7 +583,7 @@ impl PartiallySignedTransaction {
582583
rng: &mut R,
583584
secp: &secp256k1_zkp::Secp256k1<C>,
584585
inp_txout_sec: &HashMap<usize, TxOutSecrets>,
585-
) -> Result<BTreeMap<TxInType, (AssetBlindingFactor, ValueBlindingFactor, SecretKey)>, PsetBlindError> {
586+
) -> Result<BTreeMap<CtLocation, (AssetBlindingFactor, ValueBlindingFactor, SecretKey)>, PsetBlindError> {
586587
let (mut inp_secrets, mut outs_to_blind) = self.blind_checks(inp_txout_sec)?;
587588

588589
let mut ret = BTreeMap::new();
@@ -661,7 +662,8 @@ impl PartiallySignedTransaction {
661662
);
662663
let (value_commitment, nonce, rangeproof) =
663664
blind_res.map_err(|e| PsetBlindError::ConfidentialTxOutError(last_out_index, e))?;
664-
ret.insert(TxInType::Input(last_out_index), (out_abf, final_vbf, ephemeral_sk));
665+
let location = CtLocation{ input_index: last_out_index, ty: CtLocationType::Input};
666+
ret.insert(location, (out_abf, final_vbf, ephemeral_sk));
665667

666668
// mutate the pset
667669
{

0 commit comments

Comments
 (0)