Skip to content

Commit ae0ce13

Browse files
committed
Simplify algorithm for opcode counting
Instead of explicitly counting all opcodes required while satisfaction, we explicitly track only additional opcodes while satisfaction and dissatisfaction. Double-checked and compared with the c++ codebase
1 parent 239efd5 commit ae0ce13

File tree

4 files changed

+120
-210
lines changed

4 files changed

+120
-210
lines changed

src/miniscript/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl ScriptContext for Legacy {
381381
fn check_local_consensus_validity<Pk: MiniscriptKey>(
382382
ms: &Miniscript<Pk, Self>,
383383
) -> Result<(), ScriptContextError> {
384-
match ms.ext.ops_count_sat {
384+
match ms.ext.ops.op_count() {
385385
None => Err(ScriptContextError::MaxOpCountExceeded),
386386
Some(op_count) if op_count > MAX_OPS_PER_SCRIPT => {
387387
Err(ScriptContextError::MaxOpCountExceeded)
@@ -494,7 +494,7 @@ impl ScriptContext for Segwitv0 {
494494
fn check_local_consensus_validity<Pk: MiniscriptKey>(
495495
ms: &Miniscript<Pk, Self>,
496496
) -> Result<(), ScriptContextError> {
497-
match ms.ext.ops_count_sat {
497+
match ms.ext.ops.op_count() {
498498
None => Err(ScriptContextError::MaxOpCountExceeded),
499499
Some(op_count) if op_count > MAX_OPS_PER_SCRIPT => {
500500
Err(ScriptContextError::MaxOpCountExceeded)
@@ -711,7 +711,7 @@ impl ScriptContext for BareCtx {
711711
fn check_local_consensus_validity<Pk: MiniscriptKey>(
712712
ms: &Miniscript<Pk, Self>,
713713
) -> Result<(), ScriptContextError> {
714-
match ms.ext.ops_count_sat {
714+
match ms.ext.ops.op_count() {
715715
None => Err(ScriptContextError::MaxOpCountExceeded),
716716
Some(op_count) if op_count > MAX_OPS_PER_SCRIPT => {
717717
Err(ScriptContextError::MaxOpCountExceeded)

src/miniscript/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ mod tests {
575575
assert_eq!(format!("{:x}", ms.encode()), expected_hex);
576576
assert_eq!(ms.ty.mall.non_malleable, non_mal);
577577
assert_eq!(ms.ty.mall.safe, need_sig);
578-
assert_eq!(ms.ext.ops_count_sat.unwrap(), ops);
578+
assert_eq!(ms.ext.ops.op_count().unwrap(), ops);
579579
}
580580
(Err(_), false) => return,
581581
_ => unreachable!(),

0 commit comments

Comments
 (0)