-
Notifications
You must be signed in to change notification settings - Fork 115
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
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. |
2.3-tapscript.ipynb
Outdated
"\n", | ||
"Construct a `csahasholder` tapscript with the following locking conditions:\n", | ||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
2.3-tapscript.ipynb
Outdated
"\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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK 412196b
Three nits inline
2.3-tapscript.ipynb
Outdated
"\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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be 32B, not 20B
2.3-tapscript.ipynb
Outdated
"* `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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the witness includes [delay]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #141.
2.3-tapscript.ipynb
Outdated
"import util\n", | ||
"from test_framework.address import program_to_witness\n", | ||
"from test_framework.key import generate_key_pair\n", | ||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
pk
pk_delay
pk_hashlock
pk_hashlock_delay
csa
csa_delay
csa_hashlock
csa_hashlock_delay
TapLeaf().construct_csa_hashlock_delay(keys, hash, delay)