Skip to content

Commit 98a78ca

Browse files
committed
update rust-bitcoin to 0.24.0
1 parent deab3c2 commit 98a78ca

File tree

5 files changed

+43
-29
lines changed

5 files changed

+43
-29
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ unstable = []
1414
default = []
1515

1616
[dependencies]
17-
bitcoin = "0.23"
17+
bitcoin = "0.24"
1818

1919
[dependencies.serde]
2020
version = "1.0"

src/descriptor/create_descriptor.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ use ToPublicKey;
2323
///
2424
/// NOTE: Miniscript pushes should only be either boolean, 1 or 0, signatures, and hash preimages.
2525
/// As per the current implementation, PUSH_NUM2 results in an error
26-
fn instr_to_stackelem<'txin>(ins: &Instruction<'txin>) -> Result<StackElement<'txin>, Error> {
26+
fn instr_to_stackelem<'txin>(
27+
ins: &Result<Instruction<'txin>,
28+
bitcoin::blockdata::script::Error>,
29+
) -> Result<StackElement<'txin>, Error> {
2730
match *ins {
2831
//Also covers the dissatisfied case as PushBytes0
29-
Instruction::PushBytes(v) => Ok(StackElement::from(v)),
30-
Instruction::Op(opcodes::all::OP_PUSHNUM_1) => Ok(StackElement::Satisfied),
32+
Ok(Instruction::PushBytes(v)) => Ok(StackElement::from(v)),
33+
Ok(Instruction::Op(opcodes::all::OP_PUSHNUM_1)) => Ok(StackElement::Satisfied),
3134
_ => Err(Error::BadScriptSig),
3235
}
3336
}
@@ -39,7 +42,7 @@ fn parse_scriptsig_top<'txin>(
3942
script_sig: &'txin bitcoin::Script,
4043
) -> Result<(Vec<u8>, Stack<'txin>), Error> {
4144
let stack: Result<Vec<StackElement>, Error> = script_sig
42-
.iter(true)
45+
.instructions_minimal()
4346
.map(|instr| instr_to_stackelem(&instr))
4447
.collect();
4548
let mut stack = stack?;
@@ -61,7 +64,7 @@ fn verify_p2pk<'txin>(
6164
let pk_bytes = &script_pubkey.to_bytes();
6265
if let Ok(pk) = bitcoin::PublicKey::from_slice(&pk_bytes[1..script_pubkey_len - 1]) {
6366
let stack: Result<Vec<StackElement>, Error> = script_sig
64-
.iter(true)
67+
.instructions_minimal()
6568
.map(|instr| instr_to_stackelem(&instr))
6669
.collect();
6770
if !witness.is_empty() {
@@ -87,7 +90,8 @@ fn verify_p2wpkh<'txin>(
8790
}
8891
if let Some((pk_bytes, witness)) = witness.split_last() {
8992
if let Ok(pk) = bitcoin::PublicKey::from_slice(pk_bytes) {
90-
let addr = bitcoin::Address::p2wpkh(&pk.to_public_key(), bitcoin::Network::Bitcoin);
93+
let addr = bitcoin::Address::p2wpkh(&pk.to_public_key(), bitcoin::Network::Bitcoin)
94+
.map_err(|_| Error::InterpreterError(IntError::UncompressedPubkey))?;
9195
if addr.script_pubkey() != *script_pubkey {
9296
return Err(Error::InterpreterError(IntError::PkEvaluationError(pk)));
9397
}
@@ -224,7 +228,7 @@ pub fn from_txin_with_witness_stack<'txin>(
224228
} else {
225229
//bare
226230
let stack: Result<Vec<StackElement>, Error> = script_sig
227-
.iter(true)
231+
.instructions_minimal()
228232
.map(|instr| instr_to_stackelem(&instr))
229233
.collect();
230234
if !witness.is_empty() {
@@ -319,7 +323,7 @@ mod tests {
319323

320324
//test wpkh
321325
let script_pubkey =
322-
bitcoin::Address::p2wpkh(&pks[1], bitcoin::Network::Bitcoin).script_pubkey();
326+
bitcoin::Address::p2wpkh(&pks[1], bitcoin::Network::Bitcoin).unwrap().script_pubkey();
323327
let script_sig = script::Builder::new().into_script();
324328
let witness = vec![sigs[1].clone(), pks[1].clone().to_bytes()];
325329
let (des, stack) = from_txin_with_witness_stack(&script_pubkey, &script_sig, &witness)
@@ -382,9 +386,9 @@ mod tests {
382386

383387
//test shwpkh
384388
let script_pubkey =
385-
bitcoin::Address::p2shwpkh(&pks[2], bitcoin::Network::Bitcoin).script_pubkey();
389+
bitcoin::Address::p2shwpkh(&pks[2], bitcoin::Network::Bitcoin).unwrap().script_pubkey();
386390
let redeem_script =
387-
bitcoin::Address::p2wpkh(&pks[2], bitcoin::Network::Bitcoin).script_pubkey();
391+
bitcoin::Address::p2wpkh(&pks[2], bitcoin::Network::Bitcoin).unwrap().script_pubkey();
388392
let script_sig = script::Builder::new()
389393
.push_slice(&redeem_script.to_bytes())
390394
.into_script();

src/descriptor/mod.rs

+22-15
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,14 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
121121
Descriptor::Bare(..) => None,
122122
Descriptor::Pk(..) => None,
123123
Descriptor::Pkh(ref pk) => Some(bitcoin::Address::p2pkh(&pk.to_public_key(), network)),
124-
Descriptor::Wpkh(ref pk) => {
125-
Some(bitcoin::Address::p2wpkh(&pk.to_public_key(), network))
126-
}
127-
Descriptor::ShWpkh(ref pk) => {
128-
Some(bitcoin::Address::p2shwpkh(&pk.to_public_key(), network))
129-
}
124+
Descriptor::Wpkh(ref pk) => Some(
125+
bitcoin::Address::p2wpkh(&pk.to_public_key(), network)
126+
.expect("wpkh descriptors have compressed keys"),
127+
),
128+
Descriptor::ShWpkh(ref pk) => Some(
129+
bitcoin::Address::p2shwpkh(&pk.to_public_key(), network)
130+
.expect("shwpkh descriptors have compressed keys"),
131+
),
130132
Descriptor::Sh(ref miniscript) => {
131133
Some(bitcoin::Address::p2sh(&miniscript.encode(), network))
132134
}
@@ -152,12 +154,14 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
152154
addr.script_pubkey()
153155
}
154156
Descriptor::Wpkh(ref pk) => {
155-
let addr = bitcoin::Address::p2wpkh(&pk.to_public_key(), bitcoin::Network::Bitcoin);
157+
let addr = bitcoin::Address::p2wpkh(&pk.to_public_key(), bitcoin::Network::Bitcoin)
158+
.expect("wpkh descriptors have compressed keys");
156159
addr.script_pubkey()
157160
}
158161
Descriptor::ShWpkh(ref pk) => {
159162
let addr =
160-
bitcoin::Address::p2shwpkh(&pk.to_public_key(), bitcoin::Network::Bitcoin);
163+
bitcoin::Address::p2shwpkh(&pk.to_public_key(), bitcoin::Network::Bitcoin)
164+
.expect("shwpkh descriptors have compressed keys");
161165
addr.script_pubkey()
162166
}
163167
Descriptor::Sh(ref miniscript) => miniscript.encode().to_p2sh(),
@@ -185,7 +189,8 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
185189
Descriptor::Wsh(..) | Descriptor::Wpkh(..) => Script::new(),
186190
// segwit+p2sh
187191
Descriptor::ShWpkh(ref pk) => {
188-
let addr = bitcoin::Address::p2wpkh(&pk.to_public_key(), bitcoin::Network::Bitcoin);
192+
let addr = bitcoin::Address::p2wpkh(&pk.to_public_key(), bitcoin::Network::Bitcoin)
193+
.expect("wpkh descriptors have compressed keys");
189194
let redeem_script = addr.script_pubkey();
190195
script::Builder::new()
191196
.push_slice(&redeem_script[..])
@@ -211,7 +216,8 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
211216
| Descriptor::Pkh(..)
212217
| Descriptor::Wpkh(..) => self.script_pubkey(),
213218
Descriptor::ShWpkh(ref pk) => {
214-
let addr = bitcoin::Address::p2wpkh(&pk.to_public_key(), bitcoin::Network::Bitcoin);
219+
let addr = bitcoin::Address::p2wpkh(&pk.to_public_key(), bitcoin::Network::Bitcoin)
220+
.expect("shwpkh descriptors have compressed keys");
215221
addr.script_pubkey()
216222
}
217223
Descriptor::Sh(ref d) => d.encode(),
@@ -292,7 +298,8 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
292298
let mut sig_vec = sig.0.serialize_der().to_vec();
293299
sig_vec.push(sig.1.as_u32() as u8);
294300
let addr =
295-
bitcoin::Address::p2wpkh(&pk.to_public_key(), bitcoin::Network::Bitcoin);
301+
bitcoin::Address::p2wpkh(&pk.to_public_key(), bitcoin::Network::Bitcoin)
302+
.expect("wpkh descriptors have compressed keys");
296303
let redeem_script = addr.script_pubkey();
297304

298305
txin.script_sig = script::Builder::new()
@@ -926,21 +933,21 @@ mod tests {
926933
let descriptor = Descriptor::<bitcoin::PublicKey>::from_str("wsh(after(1000))").unwrap();
927934
let script = descriptor.witness_script();
928935

929-
let actual_instructions: Vec<_> = script.iter(false).collect();
936+
let actual_instructions: Vec<_> = script.instructions().collect();
930937
let check = actual_instructions.last().unwrap();
931938

932-
assert_eq!(check, &Instruction::Op(OP_CLTV))
939+
assert_eq!(check, &Ok(Instruction::Op(OP_CLTV)))
933940
}
934941

935942
#[test]
936943
fn older_is_csv() {
937944
let descriptor = Descriptor::<bitcoin::PublicKey>::from_str("wsh(older(1000))").unwrap();
938945
let script = descriptor.witness_script();
939946

940-
let actual_instructions: Vec<_> = script.iter(false).collect();
947+
let actual_instructions: Vec<_> = script.instructions().collect();
941948
let check = actual_instructions.last().unwrap();
942949

943-
assert_eq!(check, &Instruction::Op(OP_CSV))
950+
assert_eq!(check, &Ok(Instruction::Op(OP_CSV)))
944951
}
945952

946953
#[test]

src/descriptor/satisfied_constraints.rs

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ use {BitcoinSig, ToPublicKey};
2525
/// Detailed Error type for Interpreter
2626
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
2727
pub enum Error {
28+
/// An uncompressed public key was encountered in a context where it is
29+
/// disallowed (e.g. in a Segwit script or p2wpkh output)
30+
UncompressedPubkey,
2831
/// Unexpected Stack End, caused by popping extra elements from stack
2932
UnexpectedStackEnd,
3033
/// Unexpected Stack Push `StackElement::Push` element when the interpreter
@@ -95,6 +98,7 @@ impl error::Error for Error {
9598
impl fmt::Display for Error {
9699
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
97100
match *self {
101+
Error::UncompressedPubkey => f.write_str("Illegal use of uncompressed pubkey"),
98102
Error::UnexpectedStackEnd => f.write_str("Unexpected Stack End"),
99103
Error::UnexpectedStackElementPush => write!(f, "Got {}, expected Stack Boolean", 1),
100104
Error::VerifyFailed => {

src/miniscript/lex.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ impl Iterator for TokenIter {
116116
pub fn lex(script: &script::Script) -> Result<Vec<Token>, Error> {
117117
let mut ret = Vec::with_capacity(script.len());
118118

119-
for ins in script.iter(true) {
120-
match ins {
121-
script::Instruction::Error(e) => return Err(Error::Script(e)),
119+
for ins in script.instructions_minimal() {
120+
match ins.map_err(Error::Script)? {
122121
script::Instruction::Op(opcodes::all::OP_BOOLAND) => {
123122
ret.push(Token::BoolAnd);
124123
}

0 commit comments

Comments
 (0)