rust-bitcoin / rust-bitcoin/rust-miniscript

Fix and actually test the sat stack elements calculation

Open
#347 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
426
Forks
200
Avg merge
7d 17h
Merged PRs (30d)
8

Description

There are unit tests to exerce the calculation of the maximum number of elements of a satisfaction:
https://github.com/rust-bitcoin/rust-miniscript/blob/a2d6fff55a6b4a81a92fe740ee4dea86746875cc/src/miniscript/mod.rs#L586-L631

However they are not executed...
https://github.com/rust-bitcoin/rust-miniscript/blob/a2d6fff55a6b4a81a92fe740ee4dea86746875cc/src/miniscript/mod.rs#L570

Actually executing them makes the test fail. It looks like most vectors were taken from the C++ implem and therefore the Rust implem of the calculation is not on par with the C++ one.

diff --git a/src/miniscript/mod.rs b/src/miniscript/mod.rs
index c20ed89..2b4d0da 100644
--- a/src/miniscript/mod.rs
+++ b/src/miniscript/mod.rs
@@ -567,7 +567,7 @@ mod tests {
         non_mal: bool,
         need_sig: bool,
         ops: usize,
-        _stack: usize,
+        stack: usize,
     ) {
         let ms: Result<Segwitv0Script, _> = Miniscript::from_str_insane(ms);
         match (ms, valid) {
@@ -576,6 +576,7 @@ mod tests {
                 assert_eq!(ms.ty.mall.non_malleable, non_mal);
                 assert_eq!(ms.ty.mall.safe, need_sig);
                 assert_eq!(ms.ext.ops_count_sat.unwrap(), ops);
+                assert_eq!(ms.ext.stack_elem_count_sat.unwrap(), stack);
             }
             (Err(_), false) => return,
             _ => unreachable!(),

A quick look at the first vector failing with the above patch suggests that this is the calculation that needs to be fixed: the vector looks right.
https://github.com/rust-bitcoin/rust-miniscript/blob/a2d6fff55a6b4a81a92fe740ee4dea86746875cc/src/miniscript/mod.rs#L610

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/miniscript/mod.rs around the satisfaction stack-element tests at lines 570-631. Enable the stack count assertion shown in the issue, run the unit tests, and inspect the first failing vector and its calculation. Done means the tests execute and the Rust calculation matches the expected vectors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.