shesek / minsc

An highly-specialized DSL scripting language for Bitcoin Script and Miniscript
https://min.sc
MIT License
190 stars 19 forks source link

How to express threshold of thresholds? #6

Closed ChristopherA closed 3 years ago

ChristopherA commented 4 years ago

How do I create a threshold of thresholds? For instance, this special 4 of 9:


$family = 2 of [ pk(A), pk(B), pk(C) ]; 
$colleagues = 2 of [ pk(D), pk(E), pk(F) ];
$friends = 2 of [ pk(G), pk(H), pk(I) ];
$recovery = 2 of [ $family, $colleagues, $friends ];
shesek commented 4 years ago

Hi! Sorry for the slow reply, I somehow missed this.

What you wrote is correct, the only thing missing is that the program needs to end with an expression that represents the main policy.

It'll work if you return the $recovery at the end: (try)

$family = 2 of [ pk(A), pk(B), pk(C) ]; 
$colleagues = 2 of [ pk(D), pk(E), pk(F) ];
$friends = 2 of [ pk(G), pk(H), pk(I) ];
$recovery = 2 of [ $family, $colleagues, $friends ];

$recovery

Or like this: (try)

$family = 2 of [ pk(A), pk(B), pk(C) ]; 
$colleagues = 2 of [ pk(D), pk(E), pk(F) ];
$friends = 2 of [ pk(G), pk(H), pk(I) ];

2 of [ $family, $colleagues, $friends ]

(There's also an optional explicit return keyword that may be used if you don't like the Rust-like final-expression-as-the-return-value syntax.)

Or using the alternative main() function construct, which allows to express the high-level policy first and delve into the details later: (try)

fn main() = 2 of [ $family, $colleagues, $friends ];

$family = 2 of [ pk(A), pk(B), pk(C) ]; 
$colleagues = 2 of [ pk(D), pk(E), pk(F) ];
$friends = 2 of [ pk(G), pk(H), pk(I) ];