Skip to content

Commit

Permalink
Update wsts version to 7.0
Browse files Browse the repository at this point in the history
Signed-off-by: Jacinta Ferrant <jacinta@trustmachines.co>
  • Loading branch information
jferrant committed Jan 19, 2024
1 parent 5084a33 commit 3094df2
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 38 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ members = [

# Dependencies we want to keep the same between workspace members
[workspace.dependencies]
wsts = "6.1"
wsts = "7.0"
rand_core = "0.6"
rand = "0.8"

Expand Down
20 changes: 11 additions & 9 deletions stacks-signer/src/client/stackerdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@ use crate::config::Config;
/// Temporary placeholder for the number of slots allocated to a stacker-db writer. This will be retrieved from the stacker-db instance in the future
/// See: https://github.com/stacks-network/stacks-blockchain/issues/3921
/// Is equal to the number of message types
pub const SIGNER_SLOTS_PER_USER: u32 = 10;
pub const SIGNER_SLOTS_PER_USER: u32 = 11;

// The slot IDS for each message type
const DKG_BEGIN_SLOT_ID: u32 = 0;
const DKG_PRIVATE_BEGIN_SLOT_ID: u32 = 1;
const DKG_END_SLOT_ID: u32 = 2;
const DKG_PUBLIC_SHARES_SLOT_ID: u32 = 3;
const DKG_PRIVATE_SHARES_SLOT_ID: u32 = 4;
const NONCE_REQUEST_SLOT_ID: u32 = 5;
const NONCE_RESPONSE_SLOT_ID: u32 = 6;
const SIGNATURE_SHARE_REQUEST_SLOT_ID: u32 = 7;
const SIGNATURE_SHARE_RESPONSE_SLOT_ID: u32 = 8;
const BLOCK_SLOT_ID: u32 = 9;
const DKG_END_BEGIN_SLOT_ID: u32 = 2;
const DKG_END_SLOT_ID: u32 = 3;
const DKG_PUBLIC_SHARES_SLOT_ID: u32 = 4;
const DKG_PRIVATE_SHARES_SLOT_ID: u32 = 5;
const NONCE_REQUEST_SLOT_ID: u32 = 6;
const NONCE_RESPONSE_SLOT_ID: u32 = 7;
const SIGNATURE_SHARE_REQUEST_SLOT_ID: u32 = 8;
const SIGNATURE_SHARE_RESPONSE_SLOT_ID: u32 = 9;
const BLOCK_SLOT_ID: u32 = 10;

/// The messages being sent through the stacker db contracts
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -122,6 +123,7 @@ impl SignerMessage {
Self::Packet(packet) => match packet.msg {
Message::DkgBegin(_) => DKG_BEGIN_SLOT_ID,
Message::DkgPrivateBegin(_) => DKG_PRIVATE_BEGIN_SLOT_ID,
Message::DkgEndBegin(_) => DKG_END_BEGIN_SLOT_ID,
Message::DkgEnd(_) => DKG_END_SLOT_ID,
Message::DkgPublicShares(_) => DKG_PUBLIC_SHARES_SLOT_ID,
Message::DkgPrivateShares(_) => DKG_PRIVATE_SHARES_SLOT_ID,
Expand Down
32 changes: 25 additions & 7 deletions stacks-signer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use wsts::state_machine::PublicKeys;
/// List of key_ids for each signer_id
pub type SignerKeyIds = HashMap<u32, Vec<u32>>;

const EVENT_TIMEOUT_MS: u64 = 5000;
const EVENT_TIMEOUT_MS: u64 = 50;

#[derive(thiserror::Error, Debug)]
/// An error occurred parsing the provided configuration
Expand Down Expand Up @@ -119,6 +119,8 @@ pub struct Config {
pub event_timeout: Duration,
/// timeout to gather DkgPublicShares messages
pub dkg_public_timeout: Option<Duration>,
/// timeout to gather DkgPrivateShares messages
pub dkg_private_timeout: Option<Duration>,
/// timeout to gather DkgEnd messages
pub dkg_end_timeout: Option<Duration>,
/// timeout to gather nonces
Expand Down Expand Up @@ -159,7 +161,17 @@ struct RawConfigFile {
/// The signer ID
pub signer_id: u32,
/// The time to wait (in millisecs) for a response from the stacker-db instance
pub event_timeout: Option<u64>,
pub event_timeout_ms: Option<u64>,
/// timeout in (millisecs) to gather DkgPublicShares messages
pub dkg_public_timeout_ms: Option<u64>,
/// timeout in (millisecs) to gather DkgPrivateShares messages
pub dkg_private_timeout_ms: Option<u64>,
/// timeout in (millisecs) to gather DkgEnd messages
pub dkg_end_timeout_ms: Option<u64>,
/// timeout in (millisecs) to gather nonces
pub nonce_timeout_ms: Option<u64>,
/// timeout in (millisecs) to gather signature shares
pub sign_timeout_ms: Option<u64>,
}

impl RawConfigFile {
Expand Down Expand Up @@ -270,7 +282,12 @@ impl TryFrom<RawConfigFile> for Config {
signer_key_ids.insert(signer_key, s.key_ids.clone());
}
let event_timeout =
Duration::from_millis(raw_data.event_timeout.unwrap_or(EVENT_TIMEOUT_MS));
Duration::from_millis(raw_data.event_timeout_ms.unwrap_or(EVENT_TIMEOUT_MS));
let dkg_end_timeout = raw_data.dkg_end_timeout_ms.map(Duration::from_millis);
let dkg_public_timeout = raw_data.dkg_public_timeout_ms.map(Duration::from_millis);
let dkg_private_timeout = raw_data.dkg_private_timeout_ms.map(Duration::from_millis);
let nonce_timeout = raw_data.nonce_timeout_ms.map(Duration::from_millis);
let sign_timeout = raw_data.sign_timeout_ms.map(Duration::from_millis);
Ok(Self {
node_host,
endpoint,
Expand All @@ -283,10 +300,11 @@ impl TryFrom<RawConfigFile> for Config {
signer_id: raw_data.signer_id,
signer_key_ids,
event_timeout,
dkg_end_timeout: None,
dkg_public_timeout: None,
nonce_timeout: None,
sign_timeout: None,
dkg_end_timeout,
dkg_public_timeout,
dkg_private_timeout,
nonce_timeout,
sign_timeout,
})
}
}
Expand Down
7 changes: 3 additions & 4 deletions stacks-signer/src/runloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,12 @@ impl From<&Config> for RunLoop<FireCoordinator<v2::Aggregator>> {
.signer_key_ids
.get(&config.signer_id)
.unwrap()
.iter()
.map(|i| i - 1) // Signer::new (unlike Signer::from) doesn't do this
.collect::<Vec<u32>>();
.clone();
// signer uses a Vec<u32> for its key_ids, but coordinator uses a HashSet for each signer since it needs to do lots of lookups
let signer_key_ids = config
.signer_key_ids
.iter()
.map(|(i, ids)| (*i, ids.iter().map(|id| id - 1).collect::<HashSet<u32>>()))
.map(|(i, ids)| (*i, ids.iter().copied().collect::<HashSet<u32>>()))
.collect::<HashMap<u32, HashSet<u32>>>();

let coordinator_config = CoordinatorConfig {
Expand All @@ -390,6 +388,7 @@ impl From<&Config> for RunLoop<FireCoordinator<v2::Aggregator>> {
num_keys: total_keys,
message_private_key: config.message_private_key,
dkg_public_timeout: config.dkg_public_timeout,
dkg_private_timeout: config.dkg_private_timeout,
dkg_end_timeout: config.dkg_end_timeout,
nonce_timeout: config.nonce_timeout,
sign_timeout: config.sign_timeout,
Expand Down
1 change: 1 addition & 0 deletions stackslib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ libstackerdb = { path = "../libstackerdb" }
siphasher = "0.3.7"
wsts = {workspace = true}
rand_core = {workspace = true}
hashbrown = "0.14"

[target.'cfg(unix)'.dependencies]
nix = "0.23"
Expand Down
18 changes: 10 additions & 8 deletions stackslib/src/chainstate/nakamoto/tests/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use std::cell::RefCell;
use std::collections::{HashMap, HashSet, VecDeque};
use std::collections::{HashSet, VecDeque};
use std::path::{Path, PathBuf};
use std::{fs, io};

use clarity::vm::clarity::ClarityConnection;
use clarity::vm::costs::{ExecutionCost, LimitedCostTracker};
use clarity::vm::types::*;
use hashbrown::HashMap;
use rand::seq::SliceRandom;
use rand::{thread_rng, Rng};
use stacks_common::address::*;
Expand Down Expand Up @@ -70,7 +71,7 @@ pub struct TestSigners {
/// The parties that will sign the blocks
pub signer_parties: Vec<wsts::v2::Party>,
/// The commitments to the polynomials for the aggregate public key
pub poly_commitments: Vec<wsts::common::PolyCommitment>,
pub poly_commitments: HashMap<u32, wsts::common::PolyCommitment>,
/// The aggregate public key
pub aggregate_public_key: Point,
/// The total number of key ids distributed among signer_parties
Expand All @@ -85,7 +86,7 @@ impl Default for TestSigners {
let num_keys = 10;
let threshold = 7;
let party_key_ids: Vec<Vec<u32>> =
vec![vec![0, 1, 2], vec![3, 4], vec![5, 6, 7], vec![8, 9]];
vec![vec![1, 2, 3], vec![4, 5], vec![6, 7, 8], vec![9, 10]];
let num_parties = party_key_ids.len().try_into().unwrap();

// Create the parties
Expand All @@ -111,10 +112,11 @@ impl Default for TestSigners {
panic!("Got secret errors from DKG: {:?}", secret_errors);
}
};
let aggregate_public_key = poly_commitments.iter().fold(
Point::default(),
|s, poly_commitment: &wsts::common::PolyCommitment| s + poly_commitment.poly[0],
);
let mut sig_aggregator = wsts::v2::Aggregator::new(num_keys, threshold);
sig_aggregator
.init(&poly_commitments)
.expect("aggregator init failed");
let aggregate_public_key = sig_aggregator.poly[0];
Self {
signer_parties,
aggregate_public_key,
Expand All @@ -138,7 +140,7 @@ impl TestSigners {

let mut sig_aggregator = wsts::v2::Aggregator::new(self.num_keys, self.threshold);
sig_aggregator
.init(self.poly_commitments.clone())
.init(&self.poly_commitments)
.expect("aggregator init failed");
let signature = sig_aggregator
.sign(msg.as_slice(), &nonces, &sig_shares, &key_ids)
Expand Down
1 change: 1 addition & 0 deletions testnet/stacks-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ libsigner = { path = "../../libsigner" }
wsts = { workspace = true }
rand = { workspace = true }
rand_core = { workspace = true }
hashbrown = "0.14"

[dev-dependencies]
ring = "0.16.19"
Expand Down
16 changes: 9 additions & 7 deletions testnet/stacks-node/src/mockamoto/signer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use hashbrown::HashMap;
use rand::{CryptoRng, RngCore, SeedableRng};
use stacks::chainstate::nakamoto::NakamotoBlock;
use stacks::chainstate::stacks::ThresholdSignature;
Expand All @@ -13,7 +14,7 @@ pub struct SelfSigner {
/// The parties that will sign the blocks
pub signer_parties: Vec<wsts::v2::Party>,
/// The commitments to the polynomials for the aggregate public key
pub poly_commitments: Vec<wsts::common::PolyCommitment>,
pub poly_commitments: HashMap<u32, wsts::common::PolyCommitment>,
/// The aggregate public key
pub aggregate_public_key: Point,
/// The total number of key ids distributed among signer_parties
Expand All @@ -35,7 +36,7 @@ impl SelfSigner {

fn from_rng<RNG: RngCore + CryptoRng>(mut rng: RNG) -> Self {
// Create the parties
let mut signer_parties = [wsts::v2::Party::new(0, &[0], 1, 1, 1, &mut rng)];
let mut signer_parties = [wsts::v2::Party::new(0, &[1], 1, 1, 1, &mut rng)];

// Generate an aggregate public key
let poly_commitments = match wsts::v2::test_helpers::dkg(&mut signer_parties, &mut rng) {
Expand All @@ -48,11 +49,12 @@ impl SelfSigner {
assert_eq!(poly_commitments.len(), 1);
assert_eq!(signer_parties.len(), 1);

let aggregate_public_key = poly_commitments.iter().fold(
Point::default(),
|s, poly_commitment: &wsts::common::PolyCommitment| s + poly_commitment.poly[0],
);
let mut sig_aggregator = wsts::v2::Aggregator::new(1, 1);
sig_aggregator
.init(&poly_commitments)
.expect("aggregator init failed");

let aggregate_public_key = sig_aggregator.poly[0];
Self {
signer_parties: signer_parties.to_vec(),
aggregate_public_key,
Expand All @@ -74,7 +76,7 @@ impl SelfSigner {

let mut sig_aggregator = wsts::v2::Aggregator::new(self.num_keys, self.threshold);
sig_aggregator
.init(self.poly_commitments.clone())
.init(&self.poly_commitments)
.expect("aggregator init failed");
let signature = sig_aggregator
.sign(msg.as_slice(), &nonces, &sig_shares, &key_ids)
Expand Down

0 comments on commit 3094df2

Please sign in to comment.