Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a composable, yet efficient version of StandardClause #14

Open
bigspider opened this issue Apr 19, 2024 · 0 comments
Open

Make a composable, yet efficient version of StandardClause #14

bigspider opened this issue Apr 19, 2024 · 0 comments
Labels
enhancement New feature or request framework Issues related to the pymatt framework

Comments

@bigspider
Copy link
Collaborator

bigspider commented Apr 19, 2024

Currently, the code of contract is implemented using the StandardClause class, which take (among other things) a CScript. That means that the entire Script of each spending condition is written by hand.

It would be great to experiment with a 'composable' version of a StandardClause, that semantically builds good-quality (ideally, optimal) Scripts from simpler components.

Most such scripts end up being just an AND of smaller spending conditions.

It is easy to compose two Scripts (and the code to generate the witness) if their witnesses are not overlapping: if Script1 is satisfied with witness W1 and Script2 with witness W2, then W2 | W1 is a valid witness for Script1 OP_VERIFY Script2 (where the OP_VERIFY might possibly be merged with the last opcode of Script1, e.g. OP_EQUAL OP_VERIFY => OP_EQUALVERIFY).

However, many scripts might check conditions on the same witness elements; that is, W1 and W2 might contain some of the same elements. Instead of duplicating such elements, the composed Script should be adapted to minimize the waste; that seems substantially harder, but it might simplify a lot the creation of a composable framework for contracts.

A framework for symbolic Script execution might perhaps be used to detect such witness duplication, and automatically transform the Scripts in a way that preserves the semantic meaning. It might also be useful for other Script optimization tricks.

Remark: Care needs to be taken to make sure that the stack limit (or other consensus and standardness limits) are respected in the composed Scripts.

@bigspider bigspider added enhancement New feature or request framework Issues related to the pymatt framework labels Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request framework Issues related to the pymatt framework
Projects
None yet
Development

No branches or pull requests

1 participant