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: DKG verification pre-key-rotation #1301

Merged
merged 98 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
9306dfa
update for wsts 11
xoloki Jan 15, 2025
c986d2a
use wsts 11.0.0 from crates
xoloki Jan 15, 2025
25ac3be
fix rebase
xoloki Jan 24, 2025
cf13953
use wsts-12.0.0 from crates
xoloki Jan 24, 2025
6cb670a
add FrostCoordinator to wsts_state_machine so we can run signing roun…
xoloki Jan 27, 2025
31726ee
wip
cylewitruk Jan 27, 2025
63731bb
Merge branch 'feat/frost-coordinator' into feat/require-all-signature…
cylewitruk Jan 27, 2025
105d9a7
run a dkg signing before deploying contracts
cylewitruk Jan 28, 2025
4d406ee
new wsts commit
cylewitruk Jan 28, 2025
1218eb6
wip
cylewitruk Jan 28, 2025
4179cd6
Merge branch 'main' into feat/require-all-signatures-for-rotate-keys
cylewitruk Jan 28, 2025
be05f5e
seems to work
cylewitruk Jan 28, 2025
43501cb
working version
cylewitruk Jan 29, 2025
a0ce153
Merge branch 'main' into feat/require-all-signatures-for-rotate-keys
cylewitruk Jan 29, 2025
a75f5a5
remove dead code
cylewitruk Jan 29, 2025
2214427
minor wsts logging tweaks
cylewitruk Jan 29, 2025
1511969
Merge branch 'main' into feat/require-all-signatures-for-rotate-keys
cylewitruk Jan 29, 2025
25d214a
rename wstsmessageid variant
cylewitruk Jan 29, 2025
18b69d2
it works, now need to clean up
cylewitruk Jan 30, 2025
7412f87
downgrade wsts
cylewitruk Jan 30, 2025
5a16608
proto backwards compatability fixes
cylewitruk Jan 30, 2025
0e624e6
Merge branch 'main' into feat/require-all-signatures-for-rotate-keys
cylewitruk Jan 30, 2025
e867b72
some wsts cleanup/refactor
cylewitruk Jan 30, 2025
c742af2
think that's it
cylewitruk Jan 30, 2025
347db71
add message support for a specific dkg wstsmessageid
cylewitruk Jan 30, 2025
df5111f
add a dkg wstsmessageid variant
cylewitruk Jan 30, 2025
e1173f6
merge changes from the refactor branch
cylewitruk Jan 31, 2025
758c6c2
use block hash instead of random data
cylewitruk Jan 31, 2025
8acccaf
fmt
cylewitruk Jan 31, 2025
00537be
remove 100% requirement for stacks signing of rotate keys
cylewitruk Jan 31, 2025
3049863
Merge branch 'main' into feat/require-all-signatures-for-rotate-keys
cylewitruk Jan 31, 2025
7a23839
bump p256k1 to 7.2.2
cylewitruk Jan 31, 2025
b0cf9a2
pop stash
cylewitruk Jan 31, 2025
623bda8
wip
cylewitruk Feb 2, 2025
1526b83
working verifications
cylewitruk Feb 2, 2025
dc4da30
saving
cylewitruk Feb 3, 2025
2c3b83d
fixing tests
cylewitruk Feb 3, 2025
b7bddbf
seems to work
cylewitruk Feb 4, 2025
6a7073e
remove const generic, use 0 amount and add test for random keypair
cylewitruk Feb 4, 2025
3af03bb
vet bitcoinconsensus
cylewitruk Feb 4, 2025
15bc545
working on cleaning up
cylewitruk Feb 4, 2025
1ceb947
audit log
cylewitruk Feb 4, 2025
8f84016
fix merge artifacts
cylewitruk Feb 4, 2025
8cdb739
tracing fields
cylewitruk Feb 4, 2025
328ecb0
Merge branch 'refactor/wsts-cleanup' into feat/require-all-signatures…
cylewitruk Feb 4, 2025
3349fba
Merge branch 'feat/require-all-signatures-for-rotate-keys' into feat/…
cylewitruk Feb 4, 2025
2742370
migration needs to update block hash/height
cylewitruk Feb 4, 2025
267c5a4
storage mut
cylewitruk Feb 4, 2025
716e5c2
lovely cascading changes
cylewitruk Feb 4, 2025
f3587e0
Merge branch 'main' into refactor/wsts-cleanup
cylewitruk Feb 5, 2025
d22ed61
remove wstsmessage.txid infavor of id
cylewitruk Feb 5, 2025
76b9b49
remove save and prefer trait default impls
cylewitruk Feb 5, 2025
cb95417
remove unused trait methods
cylewitruk Feb 5, 2025
a38d1c9
logging stuff
cylewitruk Feb 5, 2025
5f99a29
rename message ids
cylewitruk Feb 5, 2025
b31f6f7
Merge branch 'refactor/wsts-cleanup' into feat/require-all-signatures…
cylewitruk Feb 5, 2025
92dbf17
use tracing constants
cylewitruk Feb 5, 2025
51a39d3
remove stale comment
cylewitruk Feb 5, 2025
2fe82e6
remove box from some types
cylewitruk Feb 5, 2025
6598b11
missed dkg_begin_pause
cylewitruk Feb 5, 2025
576a004
leftover dbg!()
cylewitruk Feb 5, 2025
5c0304b
refactor some validation
cylewitruk Feb 5, 2025
5d2f807
various pr comments
cylewitruk Feb 5, 2025
1e74dbf
mut thing
cylewitruk Feb 5, 2025
68bf8f5
remove unneeded allow(deprecated)
cylewitruk Feb 5, 2025
d30a0c7
Merge branch 'refactor/wsts-cleanup' into feat/require-all-signatures…
cylewitruk Feb 5, 2025
978a83e
Merge branch 'refactor/wsts-cleanup' into feat/mock-signing
cylewitruk Feb 5, 2025
abaf93f
import some changes manually from parent branch to help a confused me…
cylewitruk Feb 5, 2025
2aff467
more diff-reducing imports
cylewitruk Feb 5, 2025
f350a7f
Merge branch 'main' into feat/require-all-signatures-for-rotate-keys
cylewitruk Feb 5, 2025
dea3625
confused merge tool
cylewitruk Feb 5, 2025
15ca645
reduce diff
cylewitruk Feb 5, 2025
13595bf
Merge branch 'feat/require-all-signatures-for-rotate-keys' into feat/…
cylewitruk Feb 5, 2025
2c46ea5
add validation for nonceresponse + signatureshareresponse
cylewitruk Feb 5, 2025
3fd47be
newline
cylewitruk Feb 5, 2025
7e621d7
pr comments
cylewitruk Feb 5, 2025
4642e66
pr comments utxo
cylewitruk Feb 5, 2025
372b55d
utxo comments
cylewitruk Feb 6, 2025
3f7b9ad
remove error conversion method
cylewitruk Feb 6, 2025
480b10a
Squashed commit of the following:
cylewitruk Feb 7, 2025
b88100b
Merge branch 'main' into feat/mock-signing
cylewitruk Feb 7, 2025
7878be8
Change the DKG shares status type.
djordon Feb 6, 2025
daf4946
Update the migration query
djordon Feb 6, 2025
83b96b0
Fix up remaining queries
djordon Feb 6, 2025
ee46b3e
Oops forgot this one
djordon Feb 6, 2025
aea867b
Forgot this rename
djordon Feb 6, 2025
27a3bfa
Rename the new status field to
djordon Feb 6, 2025
5b7cc5d
Fix up the tests and add a new one
djordon Feb 6, 2025
d290aa8
Change the return value of some of the
djordon Feb 6, 2025
0ce46d3
Change it back
djordon Feb 6, 2025
3c837d8
Update the tests
djordon Feb 6, 2025
76f6754
Clean up the comments in the shares enum
djordon Feb 7, 2025
e487615
rename the rotate keys error variant
djordon Feb 7, 2025
4ad9835
Use a better error variant when extracting
djordon Feb 7, 2025
21cd44b
Remove some of our unused error variants
djordon Feb 7, 2025
102a3d5
Match the behavior in the in memory store
djordon Feb 7, 2025
45c8299
We do not need these errors anymore either
djordon Feb 7, 2025
ea00224
address nits
Jiloc Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ stackslib = { git = "https://github.com/stacks-network/stacks-core", rev = "4977
stacks-common = { git = "https://github.com/stacks-network/stacks-core", rev = "49777d3fd73a6dbb610be80c376b7d9389c9871a", default-features = false, features = ["canonical"] }

# Trust Machines Dependencies
wsts = { git = "https://github.com/Trust-Machines/wsts.git", rev = "53ae23f5f35def420877ccc8c0fe3662e64e38a1" }
wsts = { git = "https://github.com/Trust-Machines/wsts.git", rev = "a7bf38bd54cddf0b78c0f7c521a5ed1537a684fa" }

# Crates.io
aquamarine = { version = "0.6.0", default-features = false }
Expand All @@ -39,6 +39,7 @@ backoff = { version = "0.4.0", default-features = false, features = ["tokio"] }
base64 = { version = "0.22.1", default-features = false, features = ["alloc"] }
bincode = { version = "1.3.3", default-features = false }
bitcoin = { version = "0.32.5", default-features = false, features = ["serde", "rand-std"] }
bitcoinconsensus = { version = "0.106.0", default-features = false }
bitcoincore-rpc = { version = "0.19.0", default-features = false }
bitcoincore-rpc-json = { version = "0.19.0", default-features = false }
bitcoincore-zmq = { version = "1.5.2", default-features = false, features = ["async"] }
Expand All @@ -52,7 +53,7 @@ lru = { version = "0.12.5", default-features = false }
metrics = { version = "0.24.1", default-features = false }
metrics-exporter-prometheus = { version = "0.16.1", default-features = false, features = ["http-listener"] }
openssl = { version = "0.10.68", default-features = false, features = ["vendored"] }
p256k1 = { version = "7.2.0", default-features = false }
p256k1 = { version = "7.2.2", default-features = false }
prost = { version = "0.13.4", default-features = false, features = ["derive"] }
rand = { version = "0.8.5", default-features = false }
reqwest = { version = "0.11.27", default-features = false, features = ["json"] }
Expand Down Expand Up @@ -108,4 +109,4 @@ split-debuginfo = "unpacked"
[profile.release]
lto = "thin"
codegen-units = 16
overflow-checks = true
overflow-checks = true
xoloki marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ services:
context: stacks-api
args:
GIT_URI: "https://github.com/hirosystems/stacks-blockchain-api.git"
GIT_BRANCH: "v8.0.3"
GIT_BRANCH: "v8.5.0"
ports:
- 3999:3999
- 3700:3700
Expand Down Expand Up @@ -513,7 +513,7 @@ services:
context: stacks-explorer
args:
GIT_URI: "https://github.com/hirosystems/explorer.git"
GIT_BRANCH: "v1.211.2"
GIT_BRANCH: "v1.245.0"
ports:
- 3020:3000
depends_on:
Expand Down
14 changes: 13 additions & 1 deletion protobufs/stacks/signer/v1/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ message SignerMessage {
// A wsts message.
message WstsMessage {
// The transaction ID this message relates to, will be a dummy ID for DKG messages
bitcoin.BitcoinTxid txid = 1;
bitcoin.BitcoinTxid txid = 1 [deprecated = true];
// The wsts message
oneof inner {
// Tell signers to begin DKG by sending DKG public shares
Expand All @@ -60,6 +60,18 @@ message WstsMessage {
// Tell coordinator signature shares
crypto.wsts.SignatureShareResponse signature_share_response = 11;
}
oneof id {
// If this WSTS message is related to a Bitcoin signing round, this field
// will be set to the related Bitcoin transaction ID.
bitcoin.BitcoinTxid id_bitcoin_txid = 12;
// If this WSTS message is related to a rotate-keys transaction, this field
// will be set to the _new_ aggregate public key being verified.
crypto.PublicKey id_rotate_key = 13;
// If this WSTS message is related to a DKG round, this field will be set
// to the 32-byte id determined based on the coordinator public key and
// block hash, set by the coordinator.
crypto.Uint256 id_dkg = 14;
}
}

// Wraps an inner type with a public key and a signature,
Expand Down
1 change: 1 addition & 0 deletions signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ testing = ["fake", "mockall", "sbtc/testing"]
aquamarine.workspace = true
axum.workspace = true
bitcoin.workspace = true
bitcoinconsensus.workspace = true
bitcoincore-rpc.workspace = true
bitcoincore-rpc-json.workspace = true
bitcoincore-zmq.workspace = true
Expand Down
75 changes: 75 additions & 0 deletions signer/migrations/0012__dkg_verification_extensions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
-- Enum table for DKG shares status
CREATE TABLE sbtc_signer.dkg_shares_status (
-- The id of the status, not auto-incremented as we want to control the values.
id INTEGER PRIMARY KEY,
-- The name of the status.
key TEXT NOT NULL,
-- Brief description of what the status means.
description TEXT NOT NULL
);

-- Insert the initial entries.
INSERT INTO sbtc_signer.dkg_shares_status (id, key, description) VALUES
(0, 'PENDING', 'DKG round successful, pending verification via signing round'),
(1, 'VERIFIED', 'Successfully verified via signing round'),
(2, 'KEY_REVOKED', 'The DKG key has been revoked and should not be used');

-- 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
-- Contains the current
ADD COLUMN dkg_shares_status_id INTEGER DEFAULT 0 REFERENCES sbtc_signer.dkg_shares_status (id),
ADD COLUMN verified_at_bitcoin_block_hash BYTEA DEFAULT NULL,
ADD COLUMN verified_at_bitcoin_block_height BIGINT DEFAULT NULL,
ADD CONSTRAINT fk_dkg_shares_bitcoin_block_hash
FOREIGN KEY (verified_at_bitcoin_block_hash)
REFERENCES sbtc_signer.bitcoin_blocks (block_hash),
ADD CONSTRAINT chk_verified_at
CHECK (
(dkg_shares_status_id = 1 AND verified_at_bitcoin_block_hash IS NOT NULL AND verified_at_bitcoin_block_height IS NOT NULL)
OR (dkg_shares_status_id <> 1 AND verified_at_bitcoin_block_hash IS NULL AND verified_at_bitcoin_block_height IS NULL)
);

-- Set all of the current `dkg_shares` to `3` (revoked) to start with. Confirmed
-- DKG shares will be updated to `1` (verified) in the next step.
UPDATE sbtc_signer.dkg_shares
SET dkg_shares_status_id = 3;

-- Update the `dkg_shares` which have been included in a
-- `rotate_keys_transactions` which can also be tied to a bitcoin block to `1`
-- (verified) and set the `verified_at_*` fields to the bitcoin block
-- hash/height corresponding to the block where these were anchored.
--
-- This update is not fork aware, but at the time of writing there is no forks
-- that should be problematic (i.e. we shouldn't have any rotate-keys events
-- that have been orphaned).
WITH updated_shares AS (
SELECT
s.aggregate_key,
bb.block_hash AS verified_at_bitcoin_block_hash,
bb.block_height AS verified_at_bitcoin_block_height
FROM sbtc_signer.dkg_shares s
INNER JOIN sbtc_signer.rotate_keys_transactions rkt
ON s.aggregate_key = rkt.aggregate_key
INNER JOIN sbtc_signer.stacks_transactions stx
ON rkt.txid = stx.txid
INNER JOIN sbtc_signer.stacks_blocks sb
ON stx.block_hash = sb.block_hash
INNER JOIN sbtc_signer.bitcoin_blocks bb
ON sb.bitcoin_anchor = bb.block_hash
ORDER BY bb.block_height DESC
LIMIT 1
)
UPDATE sbtc_signer.dkg_shares
SET
dkg_shares_status_id = 1,
verified_at_bitcoin_block_hash = updated_shares.verified_at_bitcoin_block_hash,
verified_at_bitcoin_block_height = updated_shares.verified_at_bitcoin_block_height
FROM updated_shares
WHERE sbtc_signer.dkg_shares.aggregate_key = updated_shares.aggregate_key;

-- Make the `dkg_shares_status_id` column `NOT NULL` now that they should all
-- have a value.
ALTER TABLE sbtc_signer.dkg_shares
ALTER COLUMN dkg_shares_status_id SET NOT NULL;
Loading