Skip to content

Commit 6f19281

Browse files
committed
Merge commit 'cddc22df7f678563d0314437c2ab88acfa154200' into update_2022_10
cddc22d Merge rust-bitcoin/rust-miniscript#450: Upgrade bitcoin dependency to v0.29.0 (Change satisfier locktime)
2 parents cb90aa7 + cddc22d commit 6f19281

35 files changed

+519
-370
lines changed

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ edition = "2018"
1010
[features]
1111
compiler = []
1212
trace = []
13+
1314
unstable = []
14-
serde = ["actual-serde", "bitcoin/use-serde"]
15+
serde = ["actual-serde", "bitcoin/serde"]
1516
rand = ["bitcoin/rand"]
1617

1718
[dependencies]
18-
bitcoin = "0.28.1"
19-
elements = "0.19.0"
20-
bitcoin-miniscript = {package = "miniscript", git = "https://github.com/rust-bitcoin/rust-miniscript", rev = "c7c39f1e9d1b8da9e2c9318a61fb508553619e6c"}
19+
bitcoin = "0.29.1"
20+
elements = "0.21.0"
21+
bitcoin-miniscript = {package = "miniscript", git = "https://github.com/rust-bitcoin/rust-miniscript", rev = "cddc22df7f678563d0314437c2ab88acfa154200"}
2122

2223
# Do NOT use this as a feature! Use the `serde` feature instead.
2324
actual-serde = { package = "serde", version = "1.0", optional = true }
2425

25-
2626
[dev-dependencies]
2727
serde_json = "1.0"
28-
elementsd = {version = "0.5.0", features=["0_21_0","bitcoind_22_0"]}
28+
elementsd = {version = "0.6.0", features=["0_21_0","bitcoind_22_0"]}
2929
actual-rand = { package = "rand", version = "0.8.4"}
30-
secp256k1 = {version = "0.22.1", features = ["rand-std"]}
30+
secp256k1 = {version = "0.24.0", features = ["rand-std"]}
3131

3232
[[example]]
3333
name = "htlc"

examples/sign_multisig.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern crate elements_miniscript as miniscript;
1919
use std::collections::HashMap;
2020
use std::str::FromStr;
2121

22-
use elements::secp256k1_zkp;
22+
use elements::{secp256k1_zkp, PackedLockTime, Sequence};
2323

2424
fn main() {
2525
// Avoid repeatedly typing a pretty-common descriptor type
@@ -28,13 +28,12 @@ fn main() {
2828
// Transaction which spends some output
2929
let mut tx = elements::Transaction {
3030
version: 2,
31-
lock_time: 0,
31+
lock_time: PackedLockTime::ZERO,
3232
input: vec![elements::TxIn {
3333
previous_output: elements::OutPoint::default(),
3434
script_sig: elements::Script::new(),
35-
sequence: 0xffffffff,
35+
sequence: Sequence::MAX,
3636
is_pegin: false,
37-
has_issuance: false,
3837
asset_issuance: elements::AssetIssuance::default(),
3938
witness: elements::TxInWitness::default(),
4039
}],

examples/taproot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn main() {
103103
let secp = secp256k1::Secp256k1::new();
104104
let key_pair = KeyPair::new(&secp, &mut rand::thread_rng());
105105
// Random unspendable XOnlyPublicKey provided for compilation to Taproot Descriptor
106-
let unspendable_pubkey = bitcoin::XOnlyPublicKey::from_keypair(&key_pair);
106+
let (unspendable_pubkey, _parity) = bitcoin::XOnlyPublicKey::from_keypair(&key_pair);
107107

108108
pk_map.insert("UNSPENDABLE_KEY".to_string(), unspendable_pubkey);
109109
let pubkeys = hardcoded_xonlypubkeys();

examples/verify_tx.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ extern crate elements_miniscript as miniscript;
1919
use std::str::FromStr;
2020

2121
use elements::encode::Decodable;
22-
use elements::{confidential, secp256k1_zkp};
22+
use elements::hashes::Hash;
23+
use elements::{confidential, secp256k1_zkp, LockTime, Sequence};
2324
use miniscript::TxEnv;
2425

2526
use crate::miniscript::interpreter::KeySigPair; // secp256k1 re-exported from rust-bitcoin
@@ -40,8 +41,8 @@ fn main() {
4041
&spk_input_1,
4142
&transaction.input[0].script_sig,
4243
&transaction.input[0].witness.script_witness,
43-
0,
44-
0,
44+
Sequence::ZERO,
45+
LockTime::ZERO,
4546
)
4647
.unwrap();
4748

@@ -79,8 +80,8 @@ fn main() {
7980
&spk_input_1,
8081
&transaction.input[0].script_sig,
8182
&transaction.input[0].witness.script_witness,
82-
0,
83-
0,
83+
Sequence::ZERO,
84+
LockTime::ZERO,
8485
)
8586
.unwrap();
8687

@@ -99,7 +100,7 @@ fn main() {
99100
let utxos = [spent_utxo, elements::TxOut::default()];
100101
let env = TxEnv::new(&transaction, &utxos, 0).expect("Input len == witness utxo len");
101102
// segwit spends don't require genesis hash
102-
let genesis_hash = elements::BlockHash::default();
103+
let genesis_hash = elements::BlockHash::all_zeros();
103104

104105
println!("\nExample two");
105106
for elem in interpreter.iter(&secp, &env, genesis_hash) {
@@ -120,8 +121,8 @@ fn main() {
120121
&spk_input_1,
121122
&transaction.input[0].script_sig,
122123
&transaction.input[0].witness.script_witness,
123-
0,
124-
0,
124+
Sequence::ZERO,
125+
LockTime::ZERO,
125126
)
126127
.unwrap();
127128

src/descriptor/csfs_cov/mod.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ mod tests {
6464
use elements::secp256k1_zkp::ZERO_TWEAK;
6565
use elements::{
6666
self, confidential, opcodes, script, secp256k1_zkp, AssetId, AssetIssuance,
67-
EcdsaSigHashType, OutPoint, Script, Transaction, TxIn, TxInWitness, TxOut, Txid,
67+
EcdsaSigHashType, LockTime, OutPoint, PackedLockTime, Script, Sequence, Transaction, TxIn,
68+
TxInWitness, TxOut, Txid,
6869
};
6970

7071
use super::cov::*;
@@ -190,7 +191,7 @@ mod tests {
190191
// Now create a transaction spending this.
191192
let mut spend_tx = Transaction {
192193
version: 2,
193-
lock_time: 0,
194+
lock_time: PackedLockTime::ZERO,
194195
input: vec![txin_from_txid_vout(
195196
"141f79c7c254ee3a9a9bc76b4f60564385b784bdfc1882b25154617801fe2237",
196197
1,
@@ -260,7 +261,14 @@ mod tests {
260261

261262
// A pair of satisfiers is also a satisfier
262263
let (wit, ss) = desc.get_satisfaction((cov_sat, pk_sat))?;
263-
let interpreter = Interpreter::from_txdata(&desc.script_pubkey(), &ss, &wit, 0, 0).unwrap();
264+
let interpreter = Interpreter::from_txdata(
265+
&desc.script_pubkey(),
266+
&ss,
267+
&wit,
268+
Sequence::ZERO,
269+
LockTime::ZERO,
270+
)
271+
.unwrap();
264272

265273
assert!(wit[0].len() <= 73);
266274
assert!(wit[1].len() == 4); // version
@@ -385,7 +393,7 @@ mod tests {
385393
// Now create a transaction spending this.
386394
let mut spend_tx = Transaction {
387395
version: 2,
388-
lock_time: 0,
396+
lock_time: PackedLockTime::ZERO,
389397
input: vec![txin_from_txid_vout(
390398
"7c8e615c8da947fefd2d9b6f83f313a9b59d249c93a5f232287633195b461cb7",
391399
0,
@@ -450,15 +458,22 @@ mod tests {
450458

451459
// A pair of satisfiers is also a satisfier
452460
let (wit, ss) = desc.get_satisfaction((cov_sat, pk_sat)).unwrap();
453-
let interpreter = Interpreter::from_txdata(&desc.script_pubkey(), &ss, &wit, 0, 0).unwrap();
461+
let interpreter = Interpreter::from_txdata(
462+
&desc.script_pubkey(),
463+
&ss,
464+
&wit,
465+
Sequence::ZERO,
466+
LockTime::ZERO,
467+
)
468+
.unwrap();
454469
// Check that everything is executed correctly with dummysigs
455470
let constraints: Result<Vec<_>, _> = interpreter.iter_assume_sigs().collect();
456471
constraints.expect("Covenant incorrect satisfaction");
457472
// Commented Demo test code:
458473
// 1) Send 0.002 btc to above address
459474
// 2) Create a tx by filling up txid
460475
// 3) Send the tx
461-
assert_eq!(witness_size(&wit), 384);
476+
assert_eq!(witness_size(&wit), 385);
462477
assert_eq!(wit.len(), 13);
463478
// spend_tx.input[0].witness.script_witness = wit;
464479
// use elements::encode::serialize_hex;
@@ -472,9 +487,8 @@ mod tests {
472487
txid: Txid::from_str(txid).unwrap(),
473488
vout: vout,
474489
},
475-
sequence: 0xfffffffe,
490+
sequence: Sequence::MAX,
476491
is_pegin: false,
477-
has_issuance: false,
478492
// perhaps make this an option in elements upstream?
479493
asset_issuance: AssetIssuance {
480494
asset_blinding_nonce: secp256k1_zkp::ZERO_TWEAK,

src/descriptor/csfs_cov/satisfy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ impl<'tx, 'ptx, Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for LegacyCovSati
125125
}
126126

127127
fn lookup_nsequence(&self) -> Option<u32> {
128-
Some(self.tx.input[self.idx as usize].sequence)
128+
Some(self.tx.input[self.idx as usize].sequence.to_consensus_u32())
129129
}
130130

131131
fn lookup_outputs(&self) -> Option<&[elements::TxOut]> {
132132
Some(&self.tx.output)
133133
}
134134

135135
fn lookup_nlocktime(&self) -> Option<u32> {
136-
Some(self.tx.lock_time)
136+
Some(self.tx.lock_time.to_u32())
137137
}
138138

139139
fn lookup_sighashu32(&self) -> Option<u32> {

src/descriptor/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ mod tests {
11851185
use elements::hashes::{hash160, sha256};
11861186
use elements::opcodes::all::{OP_CLTV, OP_CSV};
11871187
use elements::script::Instruction;
1188-
use elements::{opcodes, script};
1188+
use elements::{opcodes, script, Sequence};
11891189

11901190
use super::checksum::desc_checksum;
11911191
use super::tr::Tr;
@@ -1239,9 +1239,8 @@ mod tests {
12391239
elements::TxIn {
12401240
previous_output: elements::OutPoint::default(),
12411241
script_sig: script_sig,
1242-
sequence: 100,
1242+
sequence: Sequence::from_height(100),
12431243
is_pegin: false,
1244-
has_issuance: false,
12451244
asset_issuance: elements::AssetIssuance::default(),
12461245
witness: txin_witness,
12471246
}
@@ -1514,9 +1513,8 @@ mod tests {
15141513
let mut txin = elements::TxIn {
15151514
previous_output: elements::OutPoint::default(),
15161515
script_sig: Script::new(),
1517-
sequence: 100,
1516+
sequence: Sequence::from_height(100),
15181517
is_pegin: false,
1519-
has_issuance: false,
15201518
asset_issuance: elements::AssetIssuance::default(),
15211519
witness: elements::TxInWitness::default(),
15221520
};

src/descriptor/pegin/legacy_pegin.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub struct LegacyPegin<Pk: MiniscriptKey> {
126126
/// The emergency threshold
127127
pub emer_k: usize,
128128
/// csv timelock
129-
pub timelock: u32,
129+
pub timelock: bitcoin::Sequence,
130130
/// The elements descriptor required to redeem
131131
///
132132
/// TODO: Allow extension user descriptors when claiming pegins
@@ -143,7 +143,7 @@ impl<Pk: MiniscriptKey> LegacyPegin<Pk> {
143143
fed_k: usize,
144144
emer_pks: Vec<LegacyPeginKey>,
145145
emer_k: usize,
146-
timelock: u32,
146+
timelock: bitcoin::Sequence,
147147
desc: Descriptor<Pk, CovenantExt<CovExtArgs>>,
148148
) -> Self {
149149
let fed_ms = BtcMiniscript::from_ast(BtcTerminal::Multi(fed_k, fed_pks.clone()))
@@ -268,8 +268,8 @@ impl<Pk: MiniscriptKey> LegacyPegin<Pk> {
268268
let mut rser = right.encode().into_bytes();
269269
// ...and we have an OP_VERIFY style checksequenceverify, which in
270270
// Liquid production was encoded with OP_DROP instead...
271-
assert_eq!(rser[4], opcodes::all::OP_VERIFY.into_u8());
272-
rser[4] = opcodes::all::OP_DROP.into_u8();
271+
assert_eq!(rser[4], opcodes::all::OP_VERIFY.to_u8());
272+
rser[4] = opcodes::all::OP_DROP.to_u8();
273273
// ...then we should serialize it by sharing the OP_CMS across
274274
// both branches, and add an OP_DEPTH check to distinguish the
275275
// branches rather than doing the normal cascade construction
@@ -315,7 +315,14 @@ impl<Pk: MiniscriptKey> LegacyPegin<Pk> {
315315
.map(|pk| LegacyPeginKey::Functionary(bitcoin::PublicKey::from_str(pk).unwrap()))
316316
.collect();
317317

318-
Self::new(fed_pks, 11, emer_pks, 2, 4032, user_desc)
318+
Self::new(
319+
fed_pks,
320+
11,
321+
emer_pks,
322+
2,
323+
bitcoin::Sequence::from_consensus(4032),
324+
user_desc,
325+
)
319326
}
320327
}
321328

src/descriptor/tr.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::{Arc, Mutex};
66
use std::{fmt, hash};
77

88
use elements::taproot::{
9-
LeafVersion, TaprootBuilder, TaprootBuilderError, TaprootSpendInfo, TAPROOT_CONTROL_BASE_SIZE,
9+
LeafVersion, TaprootBuilder, TaprootSpendInfo, TAPROOT_CONTROL_BASE_SIZE,
1010
TAPROOT_CONTROL_MAX_NODE_COUNT, TAPROOT_CONTROL_NODE_SIZE,
1111
};
1212
use elements::{self, opcodes, secp256k1_zkp, Script};
@@ -259,26 +259,7 @@ impl<Pk: MiniscriptKey, Ext: Extension> Tr<Pk, Ext> {
259259
// Assert builder cannot error here because we have a well formed descriptor
260260
match builder.finalize(&secp, self.internal_key.to_x_only_pubkey()) {
261261
Ok(data) => data,
262-
Err(e) => match e {
263-
TaprootBuilderError::InvalidMerkleTreeDepth(_) => {
264-
unreachable!("Depth checked in struct construction")
265-
}
266-
TaprootBuilderError::NodeNotInDfsOrder => {
267-
unreachable!("Insertion is called in DFS order")
268-
}
269-
TaprootBuilderError::OverCompleteTree => {
270-
unreachable!("Taptree is a well formed tree")
271-
}
272-
TaprootBuilderError::InvalidInternalKey(_) => {
273-
unreachable!("Internal key checked for validity")
274-
}
275-
TaprootBuilderError::IncompleteTree => {
276-
unreachable!("Taptree is a well formed tree")
277-
}
278-
TaprootBuilderError::EmptyTree => {
279-
unreachable!("Taptree is a well formed tree with atleast 1 element")
280-
}
281-
},
262+
Err(_) => unreachable!("We know the builder can be finalized"),
282263
}
283264
};
284265
let spend_info = Arc::new(data);

src/interpreter/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ use crate::extensions::EvalError;
2727
pub enum Error {
2828
/// Could not satisfy, absolute locktime not met
2929
AbsoluteLocktimeNotMet(u32),
30+
/// Could not satisfy, lock time values are different units
31+
AbsoluteLocktimeComparisonInvalid(u32, u32),
3032
/// Cannot Infer a taproot descriptor
3133
/// Key spends cannot infer the internal key of the descriptor
3234
/// Inferring script spends is possible, but is hidden nodes are currently
@@ -142,6 +144,11 @@ impl fmt::Display for Error {
142144
"required absolute locktime CLTV of {} blocks, not met",
143145
n
144146
),
147+
Error::AbsoluteLocktimeComparisonInvalid(n, lock_time) => write!(
148+
f,
149+
"could not satisfy, lock time values are different units n: {} lock_time: {}",
150+
n, lock_time
151+
),
145152
Error::CannotInferTrDescriptors => write!(f, "Cannot infer taproot descriptors"),
146153
Error::ControlBlockParse(ref e) => write!(f, "Control block parse error {}", e),
147154
Error::ControlBlockVerificationError => {
@@ -224,6 +231,7 @@ impl error::Error for Error {
224231

225232
match self {
226233
AbsoluteLocktimeNotMet(_)
234+
| AbsoluteLocktimeComparisonInvalid(_, _)
227235
| CannotInferTrDescriptors
228236
| ControlBlockVerificationError
229237
| CouldNotEvaluate

0 commit comments

Comments
 (0)