Rename tapscript descriptors#138
Conversation
|
Thanks for this, @jachiang ! The changes look mostly good, but you can help reviewers a lot by:
Those things are slightly less important in this repo because there are only a couple of us working on it, we don't have automated tests, but it's best to get into good habits for when you're contributing to Bitcoin Core or other projects. It's also just good practice to make things as easy as possible for your reviewers. |
| "Construct a `csa_hashlock_delay` tapscript with the following locking conditions:\n", | ||
| "\n", | ||
| "* 2-of-2 public keys\n", | ||
| "* Hashlock with the preimage `sha256(b'secret')`\n", |
There was a problem hiding this comment.
This is strange. You change the comment in the first commit and then revert it in a later commit.
Do you use the preimage sha256(b'secret') to enforce that the preimage provided in the witness is 32 bytes? If so, is that explained somewhere?
There was a problem hiding this comment.
Do you use the preimage sha256(b'secret') to enforce that the preimage provided in the witness is 32 bytes? If so, is that explained somewhere?
Yes there's a 32B size guard in the output script - I will add explainer that the hashlock does this to protect against unfeasibly large pre-images at spending time (e.g. atomic swap between two chains with different data push size limits, where correlating pre-image size is only valid on one-chain).
| "\n", | ||
| "# Method: 32B preimage - sha256(bytes)\n", | ||
| "# Method: 20B digest - hashlib.new('ripemd160', bytes).digest()\n", | ||
| "# Method: 20B digest - hashlib.new('ripemd160', sha256(bytes)).digest()\n", |
There was a problem hiding this comment.
Just use hash160 from script.py and then remove the direct import of hashlib.
|
Can you restructure this PR as follows:
etc. Run the script and then paste it into the commit log so reviewers can verify the script. |
@jnewbery Many thanks for the tips, much appreciated and will happily apply them here and in future PR's! |
4a5d1f7 to
412196b
Compare
|
@jnewbery Thanks for the review. I have applied most of the suggested fixes. Typos are split into #140 and this PR now builds on top of that. It was easier to fix the typos first, since they affect the subsitution of tapscript descriptors. Remaining TODO:
Do you mean dedicating a PR to the renaming of the constructors to match the descriptor update? The tapscript-specific constructor methods should be renamed together with the descriptors, or I am missing something? |
412196b to
ae0b2eb
Compare
|
Rebased after merging of #140. |
| "\n", | ||
| "**A hashlock consumes a 32B preimage and checks the hash digest for correctness:**\n", | ||
| "\n", | ||
| "1. A 20B size guard checks that the spending preimage size is exactly 20B.\n", |
There was a problem hiding this comment.
These should be 32B, not 20B
| "* `ts(csahasholder(k, [key0, key1, ...], hash, time))`\n", | ||
| " * Witness: `[signature], [signature], ..., [32B pre-image], [delay]`" | ||
| "* `ts(csa_hashlock_delay(k, [key0, key1, ...], hash, time))`\n", | ||
| " * Witness: `[signature], [signature], ..., [32B pre-image], [delay]`\n", |
There was a problem hiding this comment.
I don't think the witness includes [delay]
| "from test_framework.messages import CTxInWitness, ser_string, sha256\n", | ||
| "from test_framework.musig import generate_musig_key\n", | ||
| "from test_framework.script import TapLeaf, TapTree, TaprootSignatureHash, SIGHASH_ALL_TAPROOT" | ||
| "from test_framework.script import TapLeaf, TapTree, TaprootSignatureHash, SIGHASH_ALL_TAPROOT, hash160" |
There was a problem hiding this comment.
nit: sort import names alphabetically
Sorry. I wasn't clear. Your original branch had changes like this, which constructed the tapleaf objects on a single line: which I was trying to say should be in their own commit or PR. |
|
sorry. Needs a rebase (at least the scripted name change should be easy!) |
Changed hashlock to hash160 function. Also added usage of convenience method hash160 to chapter 2.3.
Ran the following shell script to subsitute old/new descriptors in repository. Order of sed invocations matter. sed -i -e 's/pkhasholder/pk_hashlock_delay/g' $(git grep -l pkhasholder) sed -i -e 's/pkhash/pk_hashlock/g' $(git grep -l pkhash) sed -i -e 's/pkolder/pk_delay/g' $(git grep -l pkolder) sed -i -e 's/csahasholder/csa_hashlock_delay/g' $(git grep -l \ csahasholder) sed -i -e 's/csahash/csa_hashlock/g' $(git grep -l csahash) sed -i -e 's/csaolder/csa_delay/g' $(git grep -l csaolder)
ae0b2eb to
92c783f
Compare
|
Oops. Didn't mean to close this. Spotty Internet. |
Modified code to chain tapscript constructor to initializer in chapters 2.3, 2.4 and 3.1.
ba1399f to
ced902d
Compare
|
Ok, I have addressed nits, added back the init/constructor chaining as separate commit and rebased on master :) |
|
Tested ACK ced902d Great stuff. Thanks James! |
As discussed in #123
Tapscripts updated to use hash160 as a hashlock
Tapscripts updated to have the following descriptors:
pkpk_delaypk_hashlockpk_hashlock_delaycsacsa_delaycsa_hashlockcsa_hashlock_delayTapLeaf().construct_csa_hashlock_delay(keys, hash, delay)