mintlayer / mintlayer-core

Mintlayer Core: The central repository housing the essential components to operate a Mintlayer node. It encompasses the node and wallet functionalities necessary for seamless operation, alongside an additional API server designed to facilitate applications.
https://www.mintlayer.org
MIT License
42 stars 24 forks source link

Putting mintscript on chain #1781

Open iljakuklic opened 2 weeks ago

iljakuklic commented 2 weeks ago

The mintscript module is currently only used internally for verifying transactions. It is, however, designed with the possibility of putting it on chain in mind. This allows users of the blockchain to place custom spending conditions on UTXOs.

Here is a rough and probably incomplete outline of steps needed to achieve it.

Make script encodable

Encoding has to be picked. Putting Encode and Decode derive traits on script types should work fine as a starting point. Since script is a recursive data structure, a maximum depth limit should be probably imposed. There seems to be some support for this in SCALE.

Script commitment

It is most likely not a good idea to place script spending conditions directly into outputs. Rather, only a hash-commitment for spending conditions should be in the output. The full script is revealed when spent by placing it into the witness part of the transaction.

The commitment hash contains parts of the script that specify spending conditions:

When spending, the commitment calculated from revealed script must be checked against the one specified in the output.

Threshold

It makes sense to only reveal the threshold conditions the spender wishes to satisfy for threshold conditions. This could be done by reusing the merkle multiproofs currently being used for multisig.

The DissatisfiedScript type is currently a placeholder for conditions the spender does not wish to (or can't) satisfy. With the merkle construction, the dissatisfied conditions are represented simply by the pruned out branches of the merkle tree.

Achieving a degree of compatibility with Bitcoin

The constructs available in mintscript closely follow the ones included in Bitcoin miniscript. It should be possible, with some effort put into the appropriate tooling, to translate miniscript into mintscript which provides a pipeline for translating a well-behaved subset of bitcoin scripts to equivalent spending conditions on Mintlayer.

Remarks

These are just ideas / suggestions, this will sure be a subject of intense subsequent discussion. Just sketching out the initial proposal.