ElementsProject / elements-miniscript

Creative Commons Zero v1.0 Universal
11 stars 14 forks source link

Add support for OutputsPref fragment #4

Closed sanket1729 closed 3 years ago

sanket1729 commented 3 years ago

Adds interpreter support and a generic testing mechanism to test more fragments we will add in the near future.

apoelstra commented 3 years ago

fuzz failure on elc:pk_h() in the roundtrip_descriptor test. i think this isn't related to this PR

apoelstra commented 3 years ago

ok ack 5bc92d309149633798b4fb58c1402cdf38f35096 with the following caveats

This PR is pretty big, I think it's fine to merge and address these in a followup.

sanket1729 commented 3 years ago

should change the itempref stuff to allow a variable number of CATs based on the length of the prefix

I would like to revisit having this. Because it is a significant code change in the decoding logic and complicates it.

1) First off, it is barely saving anything. In most cases, the prefix will be less than 80 bytes, so we will end up with 6 CATs anyways. 2) Secondly, in decode.rs, we would have multiple conditionals depending on the length of the prefix.

Note that these CATs are for suffix and not for prefix. The prefix is always pushed in 1 go, regardless of the size. The policy rule for 80 bytes is only for the initial witness stack and for prefix which is provided in script pubkey.

apoelstra commented 3 years ago

I don't understand your first point -- if the prefix is less than 80 bytes, then we have six CATs but actually none are needed. So we'd save six bytes in this case.

sanket1729 commented 3 years ago

The CATs are for the suffix which the user provides as witness, not the prefix. The prefix (even if > 80 bytes) can be pushed in 1 go, it is the suffix that needs CATs. The witness policy rule only restricts pushes in the initial witness stack. We can push anything we want in the committed witness script.

For example, if we want to fix the first output(say 75 bytes) in a tx with serialized outputs 500 bytes. The user has to provide the suffix (500 -75 = 425) bytes in chunks of 80.

apoelstra commented 3 years ago

Oh! Yes, I see, sorry