-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DKG verification pre-key-rotation (#1301)
* update for wsts 11 * use wsts 11.0.0 from crates * fix rebase * use wsts-12.0.0 from crates * add FrostCoordinator to wsts_state_machine so we can run signing rounds where all signers must participate * wip * run a dkg signing before deploying contracts * new wsts commit * wip * seems to work * working version * remove dead code * minor wsts logging tweaks * rename wstsmessageid variant * it works, now need to clean up * downgrade wsts * proto backwards compatability fixes * some wsts cleanup/refactor * think that's it * add message support for a specific dkg wstsmessageid * add a dkg wstsmessageid variant * use block hash instead of random data * fmt * remove 100% requirement for stacks signing of rotate keys * bump p256k1 to 7.2.2 * pop stash * wip * working verifications * saving * fixing tests * seems to work * remove const generic, use 0 amount and add test for random keypair * vet bitcoinconsensus * working on cleaning up * fix merge artifacts * tracing fields * migration needs to update block hash/height * storage mut * lovely cascading changes * remove wstsmessage.txid infavor of id * remove save and prefer trait default impls * remove unused trait methods * logging stuff * rename message ids * use tracing constants * remove stale comment * remove box from some types * missed dkg_begin_pause * leftover dbg!() * refactor some validation * various pr comments * mut thing * remove unneeded allow(deprecated) * import some changes manually from parent branch to help a confused merge tool * more diff-reducing imports * confused merge tool * reduce diff * add validation for nonceresponse + signatureshareresponse * newline * pr comments * pr comments utxo * utxo comments * remove error conversion method * Squashed commit of the following: commit 2168f58 Author: Cyle Witruk <[email protected]> Date: Thu Feb 6 16:08:22 2025 +0100 feat: consensus on successful DKG prior to rotate-keys submission (#1285) * update for wsts 11 * use wsts 11.0.0 from crates * fix rebase * use wsts-12.0.0 from crates * add FrostCoordinator to wsts_state_machine so we can run signing rounds where all signers must participate * wip * run a dkg signing before deploying contracts * new wsts commit * wip * seems to work * working version * remove dead code * minor wsts logging tweaks * rename wstsmessageid variant * it works, now need to clean up * downgrade wsts * proto backwards compatability fixes * some wsts cleanup/refactor * think that's it * add message support for a specific dkg wstsmessageid * add a dkg wstsmessageid variant * use block hash instead of random data * fmt * remove 100% requirement for stacks signing of rotate keys * bump p256k1 to 7.2.2 * fix merge artifacts * tracing fields * storage mut * lovely cascading changes * remove wstsmessage.txid infavor of id * remove save and prefer trait default impls * remove unused trait methods * logging stuff * rename message ids * use tracing constants * remove stale comment * remove box from some types * missed dkg_begin_pause * leftover dbg!() * refactor some validation * various pr comments * mut thing * remove unneeded allow(deprecated) * confused merge tool --------- Co-authored-by: Joey Yandle <[email protected]> * Change the DKG shares status type. Lots of small follow-up modifications * Update the migration query * Fix up remaining queries * Oops forgot this one * Forgot this rename * Rename the new status field to match the new column * Fix up the tests and add a new one * Change the return value of some of the queries and simplify the validation check. Also add a test. * Change it back * Update the tests * Clean up the comments in the shares enum * rename the rotate keys error variant * Use a better error variant when extracting the started_at from the state machine Id * Remove some of our unused error variants * Match the behavior in the in memory store with the postgres implementation * We do not need these errors anymore either * address nits --------- Co-authored-by: Joey Yandle <[email protected]> Co-authored-by: djordon <[email protected]> Co-authored-by: Francesco Leacche <[email protected]>
- Loading branch information
1 parent
2168f58
commit dc241cf
Showing
25 changed files
with
1,074 additions
and
223 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
CREATE TYPE sbtc_signer.dkg_shares_status AS ENUM ( | ||
'unverified', | ||
'verified', | ||
'failed' | ||
); | ||
|
||
-- Add the new columns to the `dkg_shares` table. We're not adding indexes for | ||
-- now because the table is so small that the overhead likely outweighs the | ||
-- benefits. | ||
ALTER TABLE sbtc_signer.dkg_shares | ||
ADD COLUMN dkg_shares_status sbtc_signer.dkg_shares_status, | ||
ADD COLUMN started_at_bitcoin_block_hash BYTEA, | ||
ADD COLUMN started_at_bitcoin_block_height BIGINT; | ||
|
||
|
||
UPDATE sbtc_signer.dkg_shares | ||
SET dkg_shares_status = 'unverified'; | ||
|
||
-- These are all DKG shares associated scriptPubKeys that have been successfully spent | ||
UPDATE sbtc_signer.dkg_shares | ||
SET dkg_shares_status = 'verified' | ||
FROM sbtc_signer.bitcoin_tx_inputs | ||
WHERE sbtc_signer.dkg_shares.script_pubkey = sbtc_signer.bitcoin_tx_inputs.script_pubkey; | ||
|
||
|
||
-- Fill in the started at bitcoin blockhash and block height. The timestamp | ||
-- of when we write the DKG shares row to the database should correspond | ||
-- with the tenure of the block that started the DKG round. | ||
WITH block_times AS ( | ||
SELECT | ||
bb1.block_hash | ||
, bb1.block_height | ||
, bb1.created_at | ||
, bb2.created_at AS ended_at | ||
FROM sbtc_signer.bitcoin_blocks AS bb2 | ||
JOIN sbtc_signer.bitcoin_blocks AS bb1 | ||
ON bb2.parent_hash = bb1.block_hash | ||
) | ||
UPDATE sbtc_signer.dkg_shares | ||
SET | ||
started_at_bitcoin_block_hash = block_times.block_hash | ||
, started_at_bitcoin_block_height = block_times.block_height | ||
FROM block_times | ||
WHERE sbtc_signer.dkg_shares.created_at >= block_times.created_at | ||
AND sbtc_signer.dkg_shares.created_at < block_times.ended_at; | ||
|
||
-- Make the new column `NOT NULL` now that they should all have a value. | ||
ALTER TABLE sbtc_signer.dkg_shares | ||
ALTER COLUMN dkg_shares_status SET NOT NULL, | ||
ALTER COLUMN started_at_bitcoin_block_hash SET NOT NULL, | ||
ALTER COLUMN started_at_bitcoin_block_height SET NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.