Skip to content

Commit 43e9680

Browse files
committed
Merge #858: fix: include varints for Taproot script and control block sizes
9483366 fix: include varints for Taproot script and control block sizes (Michael Mallan) Pull request description: This is a simple fix for #771. ACKs for top commit: apoelstra: ACK 9483366; successfully ran local tests; thanks!! Tree-SHA512: 329406258b83fd0f6e68d1b6f7ea04d3d37b9dacc47809517c584086fb16f74bb4b5f262dd42fc2cc855c298503d681b294bcb9beb263362fa72cb682b4fded1
2 parents 946901e + 9483366 commit 43e9680

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/plan.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -984,23 +984,29 @@ mod test {
984984
// expected weight: 4 (scriptSig len) + 1 (witness len) + 1 (OP_PUSH) + 64 (sig)
985985
let internal_key_sat_weight = Some(70);
986986
// expected weight: 4 (scriptSig len) + 1 (witness len) + 1 (OP_PUSH) + 64 (sig)
987+
// + 1 (script len)
987988
// + 34 [script: 1 (OP_PUSHBYTES_32) + 32 (key) + 1 (OP_CHECKSIG)]
989+
// + 1 (control block len)
988990
// + 65 [control block: 1 (control byte) + 32 (internal key) + 32 (hash BC)]
989-
let first_leaf_sat_weight = Some(169);
991+
let first_leaf_sat_weight = Some(171);
990992
// expected weight: 4 (scriptSig len) + 1 (witness len) + 1 (OP_PUSH) + 64 (sig)
991993
// + 1 (OP_ZERO)
994+
// + 1 (script len)
992995
// + 70 [script: 1 (OP_PUSHBYTES_32) + 32 (key) + 1 (OP_CHECKSIG)
993996
// + 1 (OP_PUSHBYTES_32) + 32 (key) + 1 (OP_CHECKSIGADD)
994997
// + 1 (OP_PUSHNUM1) + 1 (OP_NUMEQUAL)]
998+
// + 1 (control block len)
995999
// + 97 [control block: 1 (control byte) + 32 (internal key) + 32 (hash C) + 32 (hash
9961000
// A)]
997-
let second_leaf_sat_weight = Some(238);
1001+
let second_leaf_sat_weight = Some(240);
9981002
// expected weight: 4 (scriptSig len) + 1 (witness len) + 1 (OP_PUSH) + 64 (sig)
1003+
// + 1 (script len)
9991004
// + 36 [script: 1 (OP_PUSHBYTES_32) + 32 (key) + 1 (OP_CHECKSIGVERIFY)
10001005
// + 1 (OP_PUSHNUM_10) + 1 (OP_CLTV)]
1006+
// + 1 (control block len)
10011007
// + 97 [control block: 1 (control byte) + 32 (internal key) + 32 (hash B) + 32 (hash
10021008
// A)]
1003-
let third_leaf_sat_weight = Some(203);
1009+
let third_leaf_sat_weight = Some(205);
10041010

10051011
let tests = vec![
10061012
// Don't give assets

src/util.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ impl<Pk: MiniscriptKey> ItemSize for Placeholder<Pk> {
3333
| Placeholder::Hash160Preimage(_) => 33,
3434
Placeholder::PushOne => 2, // On legacy this should be 1 ?
3535
Placeholder::PushZero => 1,
36-
Placeholder::TapScript(s) => s.len(),
37-
Placeholder::TapControlBlock(cb) => cb.serialize().len(),
36+
Placeholder::TapScript(s) => s.len() + varint_len(s.len()),
37+
Placeholder::TapControlBlock(cb) => {
38+
let block_len = cb.serialize().len();
39+
block_len + varint_len(block_len)
40+
}
3841
}
3942
}
4043
}

0 commit comments

Comments
 (0)