Commit Graph

3555 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
99e4e00345
txscript: add more detailed taproot errors 2022-03-15 18:23:42 -07:00
Olaoluwa Osuntokun
6ab97a3dd8
blockchain: fix IsSpeedy() bug, add more logging in BIP 9 state machine 2022-03-15 18:23:39 -07:00
Olaoluwa Osuntokun
f7f7bb33c1
blockchain/indexers: add P2TR support to the addrindex 2022-03-15 18:23:37 -07:00
Olaoluwa Osuntokun
23cf18b050
blockchain: use taproot script flags for validation after activation 2022-03-15 18:23:34 -07:00
Olaoluwa Osuntokun
ba9fb8ece1
chaincfg: add taproot BIP deployment parameters
In this commit, we add the deployment parameters of taproot as specified
in the deployment section of BIp 341:
https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#deployment.

Take note of the custom activation threshold, as well as the specified
min activation heights for mainnet only.
2022-03-15 18:23:32 -07:00
Olaoluwa Osuntokun
79c314d503
txscript: add taproot JSON success/fail reference tests
In this commit, we add a total of 2760 taproot reference tests generated
by the bitcoind functional tests located at:
https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_taproot.py.
The tests aren't deterministic (fresh private keys are generated), so we
time we go to update the set of tests, we'll end up with fresh hashes
(the file name is the sha1 of the raw json test) and tests.
2022-03-15 18:23:29 -07:00
Olaoluwa Osuntokun
5f8660e5c3
txscript: implement OP_CHECKSIGADD
In this commit, we implement OP_CHECKSIGADD which replaces
OP_CHECKMULTISIG* in the tapscript execution environment.
2022-03-15 18:23:26 -07:00
Olaoluwa Osuntokun
3ce6130ee4
txscript: implement OP_CHECKSIG semantics for tapscript validation
In this commit, we implement the new checksig semantics as part of
tapscript validation. Namely:

  * OP_CHECKSIGVERIFY no longer pops the OP_TRUE off the stack (TODO(roasbeef): verify))

  * the new sig ops semantics are added where each sig deducts 50 from a
    starting budget of 50+the weight of the witness

  * NULLFAIL is always enforced, meaning invalid sigs MUST be an empty sig array
2022-03-15 18:23:23 -07:00
Olaoluwa Osuntokun
a4beed9f72
txscript: add new OpcodePosition method to tokenizer to save code sep position
We'll need this to properly generate the sighash during tapscript
validation later
2022-03-15 18:23:21 -07:00
Olaoluwa Osuntokun
3c6be738ed
txscript: always enforce MINIMAL_IF during tapscript execution 2022-03-15 18:23:18 -07:00
Olaoluwa Osuntokun
a7a8ad7d37
txscript: disable OP_CHECKMULTISIG and OP_CHECKMULTISIGVERIFY for tapscript 2022-03-15 18:23:16 -07:00
Olaoluwa Osuntokun
c1eb15044e
txscript: implement script path verification
In this commit, we use the recently added control block and script tree
verification+generation routines to implement full script path
verification within the VM. This includes verifying the script reveal
commitment, and recursing one layer deeper to execute the revealed
witness script as specified by BIP 342.
2022-03-15 18:23:13 -07:00
Olaoluwa Osuntokun
17e4609494
txscript: add AssembleTaprootScriptTree func for creating input witnesses
In this commit, we add a new AssembleTaprootScriptTree function that
given a list of tapscript leaves, generates a valid tapscript root,
along with the auxiliary proof data needed to spend each output.
2022-03-15 18:23:11 -07:00
Olaoluwa Osuntokun
6fc4199ee4
txscript: add new RawTxInTapscriptSignature to generate tapsript sigs
In this commit, we add a new function `RawTxInTapscriptSignature` that
will be used to generate signatures in the _tapscript_ context. Note
that this differs from top-level taproot as a distinct sighash is used,
and we _always_ accept a root hash to perform the proper tweak.
2022-03-15 18:23:08 -07:00
Olaoluwa Osuntokun
37f8c8ba0a
txscript: add VerifyTaprootLeafCommitment function
In this commit, we add a new function to verify the taproot merkle
commitment of a given tapscript leaf. Along the way we add some helper
functions which can be used to construct a taproot output given the raw
script root.
2022-03-15 18:23:06 -07:00
Olaoluwa Osuntokun
5c4a29b9d1
txscript: introduce new ControlBlock struct along w/ parsing routine
In this commit, we add a new struct to represent the ControlBlock
structure used to feed in the tapscript leaf inclusion proof into the
witness tack. The `ParseControlBlock` parses a would-be control block
and returns an error if it's incorrectly formatted.
2022-03-15 18:23:03 -07:00
Olaoluwa Osuntokun
11dd820740
txscript: add new ScriptHasOpSuccess utility method
We'll use this to examine if a script has any OP_SUCCESS op codes during
pre-processing before we attempt full tapscript execution.
2022-03-15 18:23:01 -07:00
Olaoluwa Osuntokun
a7c3db40af
txscript: use keyBytes instead of ScriptHash for segwit utilities 2022-03-15 18:22:58 -07:00
Olaoluwa Osuntokun
2ac743dc9f
txscript: add VM verification logic for top-level taproot keyspends
In this commit, we add the initial verification logic for top-level
taproot keyspends. Keyspends use the base BIP 341 sighash digest and
don't require any tapscript level functionality for validation.
2022-03-15 18:22:56 -07:00
Olaoluwa Osuntokun
938c1930da
txscript: add new functions for signing a top-level taproot output
In this commit, we add two new functions: one for signing a raw
top-level taproot keyspend, and another for generating a valid witness
for a keyspend.
2022-03-15 18:22:53 -07:00
Olaoluwa Osuntokun
1ac34b75dc
txscript: use new signature verifiers for existing CHECKSIG ops
In this commit, we use the recently added checksig verifiers to validate
signatures for pre-segwit, and segwit v0 scripts.
2022-03-15 18:22:51 -07:00
Olaoluwa Osuntokun
abeaf4e334
txscript: introduce new signatureVerifier interface to abstract over schnorr/ecdsa
In this commit, we add a new signatureVerifier interface that will allow
us to consolidate a lot of code as we'll now have 4 distinct sig+sighash
types to verify:
  1. pre-segwit
  2. segwit v0
  3. segwit v1 (taproot key spend)
  4. tapscript spends

We'll need to be able to handle 3 of the cases for the modified
OP_CHECKSIG operator. This new abstraction allows us to keep the
implementation of the function somewhat succinct.

In this commit we implement a verifier for #3 which is needed to verify
the top-level taproot keyspend. We expose the verifier using a new
VerifyTaprootKeySpend function.
2022-03-15 18:22:48 -07:00
Olaoluwa Osuntokun
1cd509d9a5
txscript: update SigCache to cache both ECDSA and Schnorr signatures
In this commit, we make the sigCache slightly more general in order to
be able to cache both ECDSA and Schnorr signatures. The cache is now
based off of byte slices (the values) rather than the direct objects. We
rely on the fact that the sighash for ecdsa and the schnorr types are
distinct, so we can keep using the same top-level sighash key.

In the future with Go type params, we can use a type param here instead
as they all have an `IsEqual` method.
2022-03-15 18:22:45 -07:00
Olaoluwa Osuntokun
e781b66e2f
txscript: implement BIP 341+342 segwit v1 taproot+tapscript
In this commit, we implement the new BIP 341+342 taproot sighash digest
computation. The digest is similar, but re-orders some fragments and
also starts to commit to the input values of all the transactions in the
SIGHASH_ALL case. A new implicit sighash flag, SIGHASH_DEFAULT has been
added that allows signatures to always be 64-bytes for the common case.

The hashcache has been updated as well to store both the v0 and v1 mid
state hashes. The v0 hashes are a double-sha of the contents, while the
v1 hash is a single sha. As a result, if a transaction spends both v0
and v1 inputs, then we 're able to re-use all the intermediate hashes.

As the sighash computation needs the input values and scripts, we create
an abstraction: the PrevOutFetcher to give the caller flexibility w.r.t
how this is done. We also create a `CannedPrevOutputFetcher` that holds
the information in a map for a single input.

A series of function options are also added to allow re-use of the same
base sig hash calculation for both BIP 341 and 342.
2022-03-15 18:22:43 -07:00
Olaoluwa Osuntokun
6ecc72e5e6
txscript: move sighash computations to new file 2022-03-15 18:22:40 -07:00
Olaoluwa Osuntokun
30d93272a8
txscript: add new IsPayToTaproot utility func 2022-03-15 18:22:38 -07:00
Olaoluwa Osuntokun
81a546bded
wire: export WriteOutPoint to public module 2022-03-15 18:22:35 -07:00
Olaoluwa Osuntokun
cfe801fe2e
txscript: move hash cache mid-state computation to hashcache.go file 2022-03-15 18:22:32 -07:00
Brian Stafford
3ddf1b51a6
txscript: add taproot support to PayToAddrScript
Add taproot address handling in PayToAddrScript. Adds a test and
also some missing tests for p2wsh and p2wpkh addresses.
2022-03-15 18:22:30 -07:00
Brian Stafford
37964e550b
txscript: add some txscript support for parsing taproot scripts 2022-03-15 18:22:27 -07:00
Brian Stafford
bfd0f4a492
txscript: add taproot script type
Add the WitnessV1TaprootTy script class and return it from
GetScriptClass / typeOfScript.

Bump the btcutil dep to leverage new taproot address type.
2022-03-15 18:22:25 -07:00
Olaoluwa Osuntokun
74e9690d0e
Merge pull request #1824 from Roasbeef/update-btcecv2-no-dep
build: update to btcec/v2.1.1 and chaincfg/chainhash/v1.00
2022-03-11 17:04:59 -08:00
Marnix
6aac863a25 Update LICENSE
Update LICENSE to 2022
2022-03-10 10:48:37 -05:00
vpereira01
10cff8777a Fixes coveralls coverage report
With PR #1785 multiple coverage reports are sent to coveralls. This
makes coveralls only consider the last report sent. This fix treat all
reports has parallel reports so they can all be compiled later by coveralls.
2022-03-10 10:44:09 -05:00
Olaoluwa Osuntokun
3baa09f33e
build: update to btcec/v2.1.1 and chaincfg/chainhash/v1.00 2022-03-09 18:54:03 -08:00
Olaoluwa Osuntokun
425ed7c987
Merge pull request #1823 from guggero/go-mod-pain-relief
Remove circular dependency issue between `btcec/v2` and main package
2022-03-09 16:49:17 -08:00
Oliver Gugger
999514c1fe
mod: add TODOs for removing local replaces 2022-03-09 11:58:43 +01:00
Oliver Gugger
46f5eec021
mod: bump btcec/v2 module version 2022-03-09 11:58:43 +01:00
Oliver Gugger
56dfa0f7e2
mod: add temporary replace 2022-03-09 11:58:42 +01:00
Oliver Gugger
4ad74cd4c2
mod: use chaincfg/chainhash module 2022-03-09 11:58:39 +01:00
Oliver Gugger
7cc824e9b5
chainhash: make module 2022-03-09 11:57:23 +01:00
Olaoluwa Osuntokun
21b37c0bd0
Merge pull request #1780 from anupcshan/replace-imports
Replace github.com/btcsuite/goleveldb imports with github.com/syndtr/goleveldb
2022-03-08 15:31:08 -08:00
Anup Chenthamarakshan
87e3d7e278 Replace github.com/btcsuite/goleveldb with github.com/syndtr/goleveldb 2022-03-08 10:07:52 -08:00
Olaoluwa Osuntokun
0c6dbfc3ea
Merge pull request #1813 from kcalvinalvin/fix-mempool-estimatefee-bug
mempool/estimatefee: Fix negative index bug
2022-02-24 17:17:38 -08:00
Calvin Kim
2ce1c60ee4 mempool/estimatefee: Fix negative index bug
Fixes a negative index bug that makes the node crash on chain
reorganizations.  The bug is detailed in
github.com/btcsuite/btcd/issues/1660.

A better design than just skipping the transaction would make
the fee estimator more accurate and that should implemented
at a later date.
2022-02-21 15:43:32 +09:00
Olaoluwa Osuntokun
4dc4ff7963
Merge pull request #1805 from Roasbeef/bchd-retract
build: retract bogus tags from btcd fork
2022-02-07 11:10:57 -08:00
Olaoluwa Osuntokun
7572beb481
build: retract bogus tags from btcd fork
Fixes https://github.com/btcsuite/btcd/issues/1791.
2022-02-04 15:54:43 -08:00
Olaoluwa Osuntokun
eaf0459ff8
Merge pull request #1801 from Roasbeef/btcec-v2-1-0
build: update to btcec v2.1.0
2022-02-04 13:30:55 -08:00
Olaoluwa Osuntokun
0847f7a476
build: update to btcec v2.1.0
This was the version tagged that created the new `ecdsa` and `schnorr`
packages. Updating these pinned version lets importers properly use
these packages and build. Things build as is since we use replace
directive to point to the latest version _in the repo_ when we build.
2022-02-01 12:52:14 -08:00
Olaoluwa Osuntokun
81fbd9b67e
Merge pull request #1777 from Roasbeef/bip340
btcec/v2: create new schnorr package for BIP-340, move existing ecdsa implementation into new ecdsa package
2022-02-01 12:44:04 -08:00