Miniscript language vs policy (languague?) #331
-
Can you please explain the difference between miniscript and policy? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
At a high level: Miniscript is an intermediate more structured representation for actual Bitcoin Scripts. It is useful as a toolbox because it simplifies static analysis of scripts, and things like generic signing. The policy language is intended to simplify designing Scripts for humans. In detail:
Following invariants are respected in Miniscript: Let ms be a miniscript, s be bitcoin script, pol be policy decode(encode(ms)) = ms
I think this is question is best answered by an example. Writing an efficient Miniscipt directly from spending conditions is not trivial. Policy language is a more natural way to write the spending conditions. Consider an Hashlock example from Bob to Alice, your requirements are
The compiler would then compile down to a miniscript like the one shown below. Note that it is non-trivial to directly write down this Miniscript and involves complicated fragments like andor. The policy language additionally allows specifying the odds(by using @ as shown below) for a or branch which can help the compiler produce byte efficient script. In the above example, we expect the Hashlock to succeed with high probability and the timelock branch should almost never be taken. We can use the odds in the policy language as follows:
which then compiles down to a different miniscript(note that pk(B) changed to pk_h(B))
|
Beta Was this translation helpful? Give feedback.
At a high level:
Miniscript is an intermediate more structured representation for actual Bitcoin Scripts. It is useful as a toolbox because it simplifies static analysis of scripts, and things like generic signing.
The policy language is intended to simplify designing Scripts for humans.
In detail:
Following invariants are respected in Miniscript: Let ms be a miniscript, s be bitcoin script, pol be policy
decode(encode(ms))…