Skip to content

Commit 51cadfc

Browse files
committed
Merge #743: feat: actually check push data bytes
e2e9281 feat: check max script sig push (ChrisCho-H) Pull request description: Miniscript witness item can be maximum 72 bytes(except length prefix), but it only throws error when it's >= 4294967296 bytes as only dependant on `PushBytesError` from bitcoin crate. I've changed the logic to check the maximum length internally so that actual check can be done. ACKs for top commit: apoelstra: ACK e2e9281 successfully ran local tests; thanks for iterating! Tree-SHA512: 7b75bc3c72c29377d0f188d6d3826f740554075b5cdc73e2a7addb1b41bf74b695cc2f97a4c025dea4176f90b0eef54577a94a032c80ec5e9bdbcb23ef98493e
2 parents b11cdc2 + e2e9281 commit 51cadfc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/util.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use core::convert::TryFrom;
44

5+
use bitcoin::constants::MAX_SCRIPT_ELEMENT_SIZE;
56
use bitcoin::hashes::Hash;
67
use bitcoin::script::{self, PushBytes, ScriptBuf};
78
use bitcoin::PubkeyHash;
@@ -49,12 +50,16 @@ pub(crate) fn witness_size<T: ItemSize>(wit: &[T]) -> usize {
4950

5051
pub(crate) fn witness_to_scriptsig(witness: &[Vec<u8>]) -> ScriptBuf {
5152
let mut b = script::Builder::new();
52-
for wit in witness {
53+
for (i, wit) in witness.iter().enumerate() {
5354
if let Ok(n) = script::read_scriptint(wit) {
5455
b = b.push_int(n);
5556
} else {
56-
let push = <&PushBytes>::try_from(wit.as_slice())
57-
.expect("All pushes in miniscript are <73 bytes");
57+
if i != witness.len() - 1 {
58+
assert!(wit.len() < 73, "All pushes in miniscript are < 73 bytes");
59+
} else {
60+
assert!(wit.len() <= MAX_SCRIPT_ELEMENT_SIZE, "P2SH redeem script is <= 520 bytes");
61+
}
62+
let push = <&PushBytes>::try_from(wit.as_slice()).expect("checked above");
5863
b = b.push_slice(push)
5964
}
6065
}

0 commit comments

Comments
 (0)