Commit Graph
110 Commits
Author SHA1 Message Date
Olaoluwa Osuntokun 4c7da7df49 input: update all taproot script spends to optionally make the ctrl block
In this commit, we update all the taproot scripts spends to optionally
make the control block. This is useful in cases where we've already
created the control block, or may not have the items needed to construct
it in the first place.

We also add the control block to the sign descriptor itself.
2023-08-22 16:32:46 -07:00
Olaoluwa Osuntokun 405a435a84 input: add weight estimation + tests for all taproot witness gen types 2023-08-22 16:32:44 -07:00
Olaoluwa Osuntokun d3c7c51f7e input: add new witness gen types for all taproot spends 2023-08-22 16:32:42 -07:00
Olaoluwa Osuntokun a5f67b451e input: add new ParseSignature helper func 2023-08-22 16:32:37 -07:00
Olaoluwa Osuntokun 349eee3263 input: ensure sessionOpts is properly threaded through 2023-08-22 16:31:47 -07:00
Olaoluwa Osuntokun 001c5b0e0b input: use multmutex to increase concurrency for musig session manager
By using the multimutex here, we'll no longer rely on a single mutex for
the entire musig session set like we used to. Instead, we can use the
session ID to key into a map of mutexes and use those directly.
2023-08-22 16:30:47 -07:00
Olaoluwa Osuntokun 9a65806c09 input+wallet: extract musig2 session management into new module
In this commit, we extract the musig2 session management into a new
module. This allows us to re-use the session logic elsewhere in unit
tests so we don't need to instantiate the entire wallet.
2023-08-22 16:30:39 -07:00
Olaoluwa Osuntokun 4733da5ccb input: eliminate CSV trick for HTLC outputs 2023-08-22 16:30:36 -07:00
Olaoluwa Osuntokun 6ce7f5d29e input: use explicit CSV 1 script for to remote output
We undo the prior hack here to make the final script more readable. The
difference is just 1 byte between the two.
2023-08-22 16:30:34 -07:00
Olaoluwa Osuntokun 0c74f894c4 input: fix linter errors 2023-08-22 16:30:31 -07:00
Olaoluwa Osuntokun 8fc8640432 input: use script path for revocation clause for to_local output
In this commit, we modify the to_local script to use a script path for
the revocation scenario. With this change, we ensure that the internal
key is always revealed which means the anchor outputs can still always
be swept.
2023-08-22 16:30:28 -07:00
Olaoluwa Osuntokun 7f05c765c3 input: restore usage of NUMS key for to_remote output
In this commit, we restore usage of the NUMS key for the to remote
output, as this allows a remote party to scan the chain in order to find
their remote output that in emergency recovery scenarios.
2023-08-22 16:30:26 -07:00
Olaoluwa Osuntokun 5e921376c4 input: add exhaustive unit tests for new taproot scripts 2023-08-22 16:30:23 -07:00
Olaoluwa Osuntokun b8d1596428 input: add new maybeAppendSighashType helper func 2023-08-22 16:30:20 -07:00
Olaoluwa Osuntokun 3393cc182d input: add spending funcs for second level HTLC tapscript ctrl blocks 2023-08-22 16:30:18 -07:00
Olaoluwa Osuntokun 89a365758a input: add taproot second level HTLC scripts 2023-08-22 16:30:15 -07:00
Olaoluwa Osuntokun d8fa0516e9 input: add spending funcs for taproot receiver HTLC ctrl blocks 2023-08-22 16:30:13 -07:00
Olaoluwa Osuntokun b2d244cf2a input: add taproot script funcs for receiver HTLCs 2023-08-22 16:30:10 -07:00
Olaoluwa Osuntokun 164b60675b input: add spending funcs for taproot sender HTLCs 2023-08-22 16:30:07 -07:00
Olaoluwa Osuntokun 7e7de11cfd input: add tapscript utils for the sender HTLC script
Unlike the old HTLC scripts, we now need to handle the various control
block interactions. As is, we opt to simply re-compute the entire tree
when needed, as the tree only has two leaves.
2023-08-22 16:30:05 -07:00
Olaoluwa Osuntokun 734dc0f085 input: add TaprootOutputKeyAnchor for taproot anchor outputs 2023-08-22 16:30:02 -07:00
Olaoluwa Osuntokun 50bf3b6177 input: add TaprootCommitScriptToRemote for taproot to remote script 2023-08-22 16:30:00 -07:00
Olaoluwa Osuntokun 5f81919284 input: add TaprootCommitScriptToSelf for taproot to self script 2023-08-22 16:29:57 -07:00
Olaoluwa Osuntokun 9d0c04bfa2 input: add GenTaprootFundingScript based on musig2
In this commit, we add GenTaprootFundingScript, which'll return the
taproot pkScript and output for a taproot+musig2 channel. This uses
musig2 key aggregation with sorting activated.

The final key produced uses a bip86 tweak, meaning that the output key
provably doesn't commit to any script path. In the future, we may want
to permit this, as then it allows for a greater degree of
programmability of the funding output.
2023-08-22 16:29:55 -07:00
Olaoluwa Osuntokun 92868cfaa5 input: add PayToTaprootScript helper func
In this commit, we add a helper function to take a taproot output key
and turn it into a v1 witness program.
2023-08-22 16:29:52 -07:00
yyforyongyu aff4320208 multi: improve logging re resolution flow 2023-08-10 13:50:03 +08:00
Olaoluwa Osuntokun 66a85bf9db Merge pull request #7473 from emilioziniades/realign-witness-types
input+lnrpc: realign witness types
2023-04-13 16:09:01 -07:00
Emilio Ziniades d8b9a2d042 input: note to update witness type protobuf 2023-04-12 21:58:12 +02:00
Oliver Gugger 79c275253c input: set initial script allocation size
The default allocation of 500 bytes for the script that is
used in NewScriptBuilder is way too much for most of our scripts.
With the new functional option we can tune the allocation to exactly
what we need.
2023-04-11 11:15:36 +02:00
Oliver Gugger a47345bd6f input: add script size unit and benchmark tests 2023-04-11 11:15:36 +02:00
Oliver Gugger ce5fa2e043 multi: add version to MuSig2 API, bump btcd/btcec to v2.3.2
With this commit we bump the github.com/btcd/btcec/v2 library to v2.3.2
which implements the MuSig2 BIP version v1.0.0rc2. With this the
github.com/btcsuite/btcd/btcec/v2/schnorr/musig2 package becomes
v1.0.0rc2 and the github.com/lightningnetwork/lnd/internal/musig2v040
stays at the old v0.4.0 version.
2023-02-03 18:30:10 +01:00
Oliver Gugger 0e5ce71b33 input+lnwallet: put MuSig2 types behind interface
We put the calls that don't use musig2 package specific types as
parameters or return values behind an interface so we can easily call
those directly in the RPC without needing to know the underlying
implementation version. Some calls can't be used in the interface
because they use the specific package version's types. These calls are
implemented in helper functions in the input package instead that do the
necessary type switches.
2023-02-03 18:30:10 +01:00
Oliver Gugger cb9f2d0398 input+lnrpc: make key sorting optional in input pkg
To allow us to properly test all test vectors, we can't default to true
on key sorting. Instead we add a parameter to the input package and move
the default value to the RPC server.
2023-02-03 18:30:09 +01:00
Oliver Gugger 13789f5d95 input+lnwallet: move some MuSig2 calls to input pkg
As a preparation for making it possible to version switch calls to the
MuSig2 API, we move some of the calls to the input package where in a
future commit we'll call the corresponding code in the correct package.
2023-02-03 18:30:09 +01:00
Oliver Gugger db73e640d9 input: add tapscript full key only helper function 2022-08-25 09:20:24 +02:00
Oliver Gugger 9f47d31681 input: add tapscript root hash helper function 2022-08-25 09:20:23 +02:00
yyforyongyu 0735522194 multi: fix make fmt 2022-08-23 22:10:24 +08:00
Oliver Gugger 7bd19d5cdf signer: fix comment about p2tr in ComputeInputScript 2022-06-29 18:28:59 +02:00
Tommy Volk 9a10c80bcb multi: move many t.Fatalf calls to require.NoError 2022-06-17 04:26:55 +00:00
Oliver Gugger 9f4f0e94f5 multi: avoid direct use of dcrec/secp256k1 library
Because the original dcrec secp256k1 library that is used for the
Schnorr signature primitives uses different hash algorithms than the
btcd secp256k1 library. Therefore pulling in the wrong library can lead
to weird and unexpected errors. We try to make it harder to make the
mistake by not using the library directly in lnd in the first place.
Note that it is still indirectly needed by the btcd secp256k1 library,
therefore the module dependency is still expected to be there, just
moved to the indirect section.
2022-05-11 10:07:52 +02:00
Olaoluwa Osuntokun 630fc36dcf multi: introduce and use new TapTweak and SignMethod fields
In this commit, we add a new field `TapTweak` to be used for key path
spends. Before this commit, we'd overload the existing `WitnessScript`
field to pass this information to the signing context. This was
confusing as for tapscript spends, this was the leaf script, which
mirrors the other script based spending types.

With this new filed, users need to set this to the script root for
keypath spends where the output key commits to a real merkle root, and
nothing when bip 86 spending is being used.

To make the signing even more explicit, we also add a new field called
sign_method with an enum type that differentiates between the different
segwit v0 and v1 signing methods.

Fixes https://github.com/lightningnetwork/lnd/issues/6446.
2022-05-11 10:07:49 +02:00
Oliver Gugger 99cda74f6a input: define new signing method constants 2022-05-11 10:07:48 +02:00
Oliver Gugger 95ff670c0e multi: add MuSig2Cleanup method to MuSig2 signer 2022-05-04 19:23:58 +02:00
Oliver Gugger e31aab5af6 multi: fix inclusion proof size
The inclusion proof field in the TapscriptPartialReveal function was
incorrect. An inclusion proof can be zero or more elements of 32-byte
slices. So an empty inclusion proof can be valid too for a tree that
only consists of a single leaf.
2022-04-29 11:41:09 +02:00
Oliver Gugger f7275c7fc4 multi: implement MuSig2 RPCs and remote signing 2022-04-29 11:41:09 +02:00
Oliver Gugger 8fc99fba00 input+btcwallet: add MuSig2 signing operations
With this commit we add the high-level MuSig2 signing methods to the
btcwallet which will later be exposed through an RPC interface.
2022-04-29 11:41:08 +02:00
Oliver Gugger ef98f2df8a multi: add p2tr tapscript key path signing capabilities 2022-03-24 18:02:39 +01:00
Oliver Gugger 78db46be7e multi: add p2tr tapscript signing capabilities 2022-03-24 18:02:39 +01:00
Oliver Gugger 108f49f23b input+signer: test wallet script import 2022-03-24 18:02:38 +01:00
Oliver Gugger c73cf03a55 multi: add p2tr keyspend wallet support 2022-03-24 18:02:38 +01:00