fix and make scripts smaller#1
Conversation
06328cb to
43f45e8
Compare
577ab05 to
fe5a289
Compare
fe5a289 to
c696608
Compare
+ script layout and readability
c696608 to
dba17e7
Compare
I wrote a simple program to confirm this: https://go.dev/play/p/ZOo7zkr0Dew. The output is: As expected, things fail due to the clean stack consensus rule. It makes things a bit harder to understand at a glance, but I guess saving that extra byte is worth it (?). |
Roasbeef
left a comment
There was a problem hiding this comment.
Solid PR, thanks for all the heavy lifting!
I wrote a small program to confirm the new (sorta hacky/clever) sequence usage and things check out. I think we might still want to run things thru mini script to further optimize (tho maybe that's what you did in the first place?).
| The final witness to spend a script path output is: | ||
| ``` | ||
| control_block || leaf_script || witness | ||
| <witness1> ... <witnessN> <leaf_script> <control_block> |
There was a problem hiding this comment.
I guess we visualize the stack differently ;)
| <local_delayedpubkey> | ||
| OP_CHECKSIGVERIFY | ||
| <local_delayedpubkey> OP_CHECKSIG | ||
| <to_self_delay> OP_CHECKSEQUENCEVERIFY OP_DROP |
| * where: | ||
| * `taproot_nums_point = 0245b18183a06ee58228f07d9716f0f121cd194e4d924b037522503a7160432f15` | ||
| * `to_remote_output_key = taproot_nums_point + tagged_hash("TapTweak", taproot_nums_point|| to_remote_script_root` | ||
| * `to_remote_output_key = taproot_nums_point + tagged_hash("TapTweak", taproot_nums_point || to_remote_script_root)` |
There was a problem hiding this comment.
FWIW, the NUMs point here will soon be removed (will just be the multi-sig script).
| ``` | ||
| <remotepubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY | ||
| <remotepubkey> OP_CHECKSIG | ||
| OP_CHECKSEQUENCEVERIFY |
There was a problem hiding this comment.
Clever...but will need to double check the semantics here to ensure this doesn't become an any-one-can-spend...
| (output_key_y_parity | 0xc0) || anchor_internal_key | ||
| ``` | ||
|
|
||
| `nSequence` needs to be set to 16. |
| <local_htlcpubkey> OP_CHECKSIGADD <remote_htlcpubkey> OP_CHECKSIGADD 2 OP_EQUALVERIFY | ||
| 1 OP_CHECKSEQUENCEVERIFY | ||
| <local_htlcpubkey> OP_CHECKSIGVERIFY | ||
| <remote_htlcpubkey> OP_CHECKSIG |
There was a problem hiding this comment.
This isn't correct, the sequence is still need here as we want to make sure all spends need to wait a block.
| <remote_htlcpubkey> OP_CHECKSIG | ||
| ``` | ||
|
|
||
| Note that there is no `OP_CHECKSEQUENCEVERIFY` in the offered HTLC's timeout path |
There was a problem hiding this comment.
Thanks for this note, makes sense, and isn't too big of a departure w.r.t how things work today.
no problem :)
havent used miniscript |
lightning#995
fixed some tapscripts, made some smaller and fixed witness stack order (bip 341)