-
Notifications
You must be signed in to change notification settings - Fork 375
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
Implement Taproot Sighash #1002
Conversation
fde71a0
to
4a7685a
Compare
The test seems flaky |
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.
For reference failed logs: https://cirrus-ci.com/task/6028890096271360?logs=ci#L3628
No diff between |
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 the comments
f2452a3
to
afa015d
Compare
40f50e8
to
f1ac1be
Compare
I think, as long as our test suite passes, there is no need to add new |
ss += struct.pack("<i", txTo.nVersion) | ||
ss += struct.pack("<I", txTo.nLockTime) | ||
if in_type != SIGHASH_ANYONECANPAY: | ||
ss += sha256(b"".join(struct.pack("B", ((not i.assetIssuance.isNull()) >> 7) + (i.m_is_pegin >> 6)) for i in txTo.vin)) |
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 <<
rather than >>
(same below)
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.
One more reason to write tests :)
e7b4bba looks great! Just needs some more tests and we're good to go |
@@ -405,6 +405,14 @@ def serialize(self): | |||
r += self.nInflationKeys.serialize() | |||
return r | |||
|
|||
# serialization used in taproot sighash | |||
def tap_sighash_serialize(self): |
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.
Can you rename this (and change the comment) to indicate that it is specifically for asset issuance data?
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.
It is inside the class CAssetIssuance
, so it is implicit that it is for asset issuance?
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.
edited the name to taphash_asset_issuance_serialize
# | ||
# Test use of assetdir to locally label assets. | ||
# Test listissuances returns a list of all issuances or specific issuances based on asset hex or asset label. | ||
# |
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 looks great! Can you add it to test_runner.py
so it gets run in CI?
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.
Changed the function name and added test to test_runner.py
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.
…ash_pegins_issuances.py 1c883db test: update `createrawtransaction` call in feature_taphash_pegins_issuances.py (Andrew Poelstra) Pull request description: Should describe the outputs as an array rather than as an object. (The old behavior has long been deprecated but was eliminated entirely in #900.) Fixes functional tests which were broken in master by simultaneous merge of #1002 and #900. ACKs for top commit: stevenroose: utACK 1c883db Tree-SHA512: f7963c34e7006a25ac5515e30966ef46777fa22d6125d219345731aef603e5f3179fc316134d59694af8e753f7cb48c825ad3434f2bceda0a10b8d5a52c32cd3
{ | ||
CHashWriter ss(SER_GETHASH, 0); | ||
for (const auto& txin : txTo.vin) { | ||
ss << (unsigned char) ((!txin.assetIssuance.IsNull() << 7) + (txin.m_is_pegin << 6)); |
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.
Consider instead using (COutPoint::OUTPOINT_ISSUANCE_FLAG >> 24)
and (COutPoint::OUTPOINT_PEGIN_FLAG >> 24)
(you can compose the flags and shift the result if you prefer).
I believe |
is prefered over +
for flag composition.
// Data about the input/prevout being spent | ||
assert(execdata.m_annex_init); | ||
const bool have_annex = execdata.m_annex_present; | ||
const uint8_t spend_type = (ext_flag << 1) + (have_annex ? 1 : 0); // The low bit indicates whether an annex is present. | ||
ss << spend_type; | ||
if (input_type == SIGHASH_ANYONECANPAY) { | ||
ss << (unsigned char) ((!tx_to.vin[in_pos].assetIssuance.IsNull() << 7) + (tx_to.vin[in_pos].m_is_pegin << 6)); |
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.
We should probably abstract this flag composition into its own function as it occurs in two places.
ss << tx_to.vin[in_pos].prevout; | ||
ss << cache.m_spent_outputs[in_pos]; | ||
ss << cache.m_spent_outputs[in_pos].nAsset; | ||
ss << cache.m_spent_outputs[in_pos].nValue; |
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.
Maybe comment here that we are not using the nonce and maybe even why we aren't?
@roconnor-blockstream Addressed in #1023 |
2612017 Address post merge feedback for Taphash (sanket1729) Pull request description: Addressing the review by @roconnor-blockstream on #1002 . ACKs for top commit: apoelstra: ACK 2612017 Tree-SHA512: 62121ba33cf1fccda75cd2402c22799ccee437ba64575e6f5561b0aa1c571b6d94f3981fb4c1260a8c2848a26e1790d770364ade2af3edb5a98be29c23d6e0a2
This introduces Taproot wallet support. I fixed all the merge conflicts and ensured that the tests pass, but this is still using the old sighash (before Russell/Sanket/I redid it) so is not actually production ready. Will be fixed when we bring Elements #1002 in.
This forward-ports the new Taproot sighash but does not fix a couple 22-blocked TODOs related to the MissingDataBehavior enum. Should be fixed in a followup commit. One nontrivial change I had to make was feeding the genesis hash to SignTransaction (the "global" one in script/sign.cpp) so that it could correctly compute the sighash at signing time.
No description provided.