Skip to content
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

Merged
merged 7 commits into from
Jul 7, 2021
Merged

Conversation

sanket1729
Copy link
Member

No description provided.

@sanket1729 sanket1729 changed the title Implement Taphash Implement Taproot Sighash May 20, 2021
@sanket1729 sanket1729 force-pushed the taphash branch 3 times, most recently from fde71a0 to 4a7685a Compare May 21, 2021 04:04
@sanket1729
Copy link
Member Author

The test seems flaky

Copy link
Member Author

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanket1729
Copy link
Member Author

No diff between 4a7685a 8202d39.

Copy link
Member Author

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the comments

src/script/interpreter.cpp Outdated Show resolved Hide resolved
@sanket1729 sanket1729 force-pushed the taphash branch 3 times, most recently from f2452a3 to afa015d Compare June 7, 2021 22:24
@sanket1729 sanket1729 force-pushed the taphash branch 2 times, most recently from 40f50e8 to f1ac1be Compare June 8, 2021 15:22
@apoelstra
Copy link
Member

I think, as long as our test suite passes, there is no need to add new g_con_elementsmode uses. We should just drop this and always only do Taproot sighashes in Elements mode.

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))
Copy link
Member

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)

Copy link
Member Author

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 :)

@apoelstra
Copy link
Member

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):
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member Author

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.
#
Copy link
Member

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?

Copy link
Member Author

@sanket1729 sanket1729 left a 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

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 14f9357

Ran all tests (including fuzz tests) several times; did some basic mutation testing on the functional tests to check that obscure things were covered; also poked at the extended tests in #1003 which we are unable to merge.

@apoelstra apoelstra merged commit 1ba24fe into ElementsProject:master Jul 7, 2021
stevenroose added a commit that referenced this pull request Jul 12, 2021
…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));
Copy link
Contributor

@roconnor-blockstream roconnor-blockstream Jul 26, 2021

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));
Copy link
Contributor

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;
Copy link
Contributor

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?

@sanket1729
Copy link
Member Author

@roconnor-blockstream Addressed in #1023

apoelstra added a commit that referenced this pull request Aug 17, 2021
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
gwillen pushed a commit that referenced this pull request Jun 1, 2022
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.
gwillen pushed a commit that referenced this pull request Jun 1, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants