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

Feat/native segwit #3283

Merged
merged 105 commits into from
Nov 5, 2022
Merged

Feat/native segwit #3283

merged 105 commits into from
Nov 5, 2022

Conversation

jcnelson
Copy link
Member

@jcnelson jcnelson commented Sep 8, 2022

This PR adds support for both stacking and mining with native segwit addresses. The feat/pox-2-unlock branch is merged into this branch, so let's get that reviewed and merged before doing this one.

Highlights:

PoX 2

  • The pox-2 contract will now accept a { version: (buff 1), hashbytes: (buff 32) } tuple for a PoX reward address, which may represent any of the following scriptPubKeys:

    • p2pkh
    • p2sh
    • p2wpkh-p2sh
    • p2wsh-p2sh
    • p2wpkh
    • p2wsh
    • p2tr
  • The PoxAddress type, which represents committed PoX payouts in a LeaderBlockCommitOp, can now represent all legacy address types as well as p2wpkh, p2wsh, and p2tr addresses, as well as their Clarity tuple representations for pox-2.

Burnchain Parser

  • The Bitcoin block downloader and transaction parser are epoch-gated so that at Epoch 2.1, transactions that contain native segwit inputs and outputs will be considered.

  • The Bitcoin address parser can now decode p2wpkh, p2sh, and p2tr scriptPubKeys

  • The vendored Bitcoin transaction parsing library has been patched to generate segwit sighashes for the purposes of mining with segwit.

Burn Operations Processing

  • We no longer care about the contents of a Bitcoin transaction's scriptSig or witness. We never did at the consensus level, but now BurnchainSigner no longer represents this information, and all the code that inadvertently depended on this has been updated to not to so.

  • LeaderKeyRegisterOp no longer has an address field. It was never checked by the consensus rules, and it was only used by the node for matching up a LeaderKeyRegisterOp to the keychain's BurnchainSigner (which has been removed).

  • StackStxOp and TransferStxOp do not support segwit, since the recipient address must decode to a Stacks address (and only legacy Bitcoin addresses do this).

Node

  • Using segwit is a configuration option now, which must be turned on explicitly. It will only take effect in Epoch 2.1.

  • If configured to do so, the miner will spend and create segwit p2wpkh UTXOs instead of legacy UTXOs when mining and registering VRF keys. If a miner has UTXOs for both the legacy and p2wpkh addresses derived from the miner's seed, then the legacy ones will be used prior to Epoch 2.1 and the segwit ones will be used at and after Epoch 2.1. This will permit miners to seamlessly transition to using native segwit at the Epoch 2.1 boundary without a node restart.

  • Leader key registration considers the Bitcoin txid, not the BurnchainSigner or LeaderKeyRegisterOp address field when processing tenures.

Vendored Code

The directory stacks-common/src/deps_common/bech32 was vendored from https://github.com/rust-bitcoin/rust-bech32. It was created by the same folks who created our vendored Bitcoin block and transaction parsing library.

…gwit variant, and implement the segwit variant to represent p2wpkh, p2wsh, and p2tr scriptPubKey outputs
…we parse the former, but do not parse the latter. This is used to support segwit witness scripts and tapscripts, which do not have readily-identifiable public keys or a fixed required number of signers
…at and after epoch 2.1, parse transactions with native segwit outputs and witness-bearing inputs
…parseable) input or a raw input (for segwit and taproot)
…'s just an opaque string that gets logged and reported to prometheus (as had always been the case, but is now made explicit by the type). Also, leader key register txs no longer need to store an identifying address
…ion, since with segwit this is no longer really doable
…output from the miner (which must be the input to the next block-commit from this miner). Also, API sync on the tests with the new bitcoin address types and BurnchainSigner
…sh, and p2tr natively (in addition to p2wpkh-p2sh and p2wsh-p2sh)
@igorsyl
Copy link
Contributor

igorsyl commented Nov 1, 2022

Testing PR #3357

Copy link
Contributor

@igorsyl igorsyl left a comment

Choose a reason for hiding this comment

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

lgtm after approved #3357

Copy link
Contributor

@donpdonp donpdonp left a comment

Choose a reason for hiding this comment

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

Its interesting to see all the places the wider address field gets used (20 => 32 bytes). The test cases look thorough. LGTM.

@jcnelson jcnelson merged commit 729c60e into next Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants