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

Add coordinator rotation test #535

Merged
merged 21 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions substrate/abi/src/grandpa.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use sp_core::{ConstU32, bounded::BoundedVec};
use sp_consensus_grandpa::EquivocationProof;

use serai_primitives::{BlockNumber, SeraiAddress};
Expand All @@ -19,7 +18,7 @@ pub enum Call {
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Event {
NewAuthorities { authority_set: BoundedVec<(SeraiAddress, u64), ConstU32<0>> },
NewAuthorities { authority_set: alloc::vec::Vec<(SeraiAddress, u64)> },
// TODO: Remove these
Paused,
Resumed,
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/src/serai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ impl Serai {
}

async fn active_network_validators(&self, network: NetworkId) -> Result<Vec<Public>, SeraiError> {
let hash: String = self
let validators: String = self
.call("state_call", ["SeraiRuntimeApi_validators".to_string(), hex::encode(network.encode())])
.await?;
let bytes = Self::hex_decode(hash)?;
let bytes = Self::hex_decode(validators)?;
let r = Vec::<Public>::decode(&mut bytes.as_slice())
.map_err(|e| SeraiError::ErrorInResponse(e.to_string()))?;
Ok(r)
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/tests/common/in_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub async fn provide_batch(serai: &Serai, batch: Batch) -> [u8; 32] {
keys
} else {
let keys = KeyPair(pair.public(), vec![].try_into().unwrap());
set_keys(serai, set, keys.clone()).await;
set_keys(serai, set, keys.clone(), &[insecure_pair_from_name("Alice")]).await;
keys
};
assert_eq!(keys.0, pair.public());
Expand Down
47 changes: 30 additions & 17 deletions substrate/client/tests/common/validator_sets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use frost::dkg::musig::musig;
use schnorrkel::Schnorrkel;

use serai_client::{
primitives::insecure_pair_from_name,
validator_sets::{
primitives::{ValidatorSet, KeyPair, musig_context, set_keys_message},
ValidatorSetsEvent,
Expand All @@ -25,26 +24,40 @@ use serai_client::{
use crate::common::tx::publish_tx;

#[allow(dead_code)]
pub async fn set_keys(serai: &Serai, set: ValidatorSet, key_pair: KeyPair) -> [u8; 32] {
let pair = insecure_pair_from_name("Alice");
let public = pair.public();
pub async fn set_keys(
serai: &Serai,
set: ValidatorSet,
key_pair: KeyPair,
pairs: &[Pair],
) -> [u8; 32] {
let mut pub_keys = vec![];
for pair in pairs {
let public_key =
<Ristretto as Ciphersuite>::read_G::<&[u8]>(&mut pair.public().0.as_ref()).unwrap();
pub_keys.push(public_key);
}

let public_key = <Ristretto as Ciphersuite>::read_G::<&[u8]>(&mut public.0.as_ref()).unwrap();
let secret_key = <Ristretto as Ciphersuite>::read_F::<&[u8]>(
&mut pair.as_ref().secret.to_bytes()[.. 32].as_ref(),
)
.unwrap();
assert_eq!(Ristretto::generator() * secret_key, public_key);
let threshold_keys =
musig::<Ristretto>(&musig_context(set), &Zeroizing::new(secret_key), &[public_key]).unwrap();
let mut threshold_keys = vec![];
for i in 0 .. pairs.len() {
let secret_key = <Ristretto as Ciphersuite>::read_F::<&[u8]>(
&mut pairs[i].as_ref().secret.to_bytes()[.. 32].as_ref(),
)
.unwrap();
assert_eq!(Ristretto::generator() * secret_key, pub_keys[i]);

threshold_keys.push(
musig::<Ristretto>(&musig_context(set), &Zeroizing::new(secret_key), &pub_keys).unwrap(),
);
}

let mut musig_keys = HashMap::new();
for tk in threshold_keys {
musig_keys.insert(tk.params().i(), tk.into());
}

let sig = frost::tests::sign_without_caching(
&mut OsRng,
frost::tests::algorithm_machines(
&mut OsRng,
&Schnorrkel::new(b"substrate"),
&HashMap::from([(threshold_keys.params().i(), threshold_keys.into())]),
),
frost::tests::algorithm_machines(&mut OsRng, &Schnorrkel::new(b"substrate"), &musig_keys),
&set_keys_message(&set, &[], &key_pair),
);

Expand Down
Loading
Loading