Skip to content

Commit

Permalink
Merge branch 'master' into peg/four-node-docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
HCastano committed Oct 2, 2024
2 parents 093f9bd + d1f2c96 commit 51f0bab
Show file tree
Hide file tree
Showing 84 changed files with 951 additions and 189 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ At the moment this project **does not** adhere to
As such, `UserSignatureRequest` no longer requires the `validators_info` field since the the
relayer adds that in after. The response received from the validator is now a `Vec<Responses>`
from the signers.
- In ([#1063](https://github.com/entropyxyz/entropy-core/pull/1063)) the
`pallet_staking_extension::validate()` extrinsic was changed so that in order to populate certain
data structures related to a candidates state (namely `ThresholdToStash` and `ThresholdServer`) an
attestation from the Attestation pallet must have been received. Success of the `validate()`
extrinsic **does not** mean the caller is a candidate or validator.
- In [#1086](https://github.com/entropyxyz/entropy-core/pull/1086) `Eve` was removed as a validator
from the `devnet-local` chainspec and replaced with `Charlie`.

Expand All @@ -54,9 +59,9 @@ At the moment this project **does not** adhere to
- Fix TSS `AccountId` keys in chainspec ([#993](https://github.com/entropyxyz/entropy-core/pull/993))
- No unbonding when signer or next signer ([#1031](https://github.com/entropyxyz/entropy-core/pull/1031))
- Add relay tx endpoint ([#1050](https://github.com/entropyxyz/entropy-core/pull/1050))
- Trigger attestation check during validate ([#1063](https://github.com/entropyxyz/entropy-core/pull/1063))
- Add fourth node to `devnet-local` configuration ([#1086](https://github.com/entropyxyz/entropy-core/pull/1086))


### Removed
- Remove `prune_registration` extrinsic ([#1022](https://github.com/entropyxyz/entropy-core/pull/1022))
- Remove `confirm_registered` extrinsic ([#1025](https://github.com/entropyxyz/entropy-core/pull/1025))
Expand Down
19 changes: 12 additions & 7 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ It is however only intended for use with test networks and has no secure private

Everytime a change to the chain's interface happens, metadata needs to be pulled. You'll need to install Subxt using `cargo install subxt-cli`. Then [run a development chain](#getting-started-with-docker) and then invoke [the `./scripts/pull_entropy_metadata.sh` script](./scripts/pull_entropy_metadata.sh).

## Regenerating test keyshares

To speed up running tests, some tests use pre-generated keyshares rather than running a distributed key generation during the test. If you need to regenerate these keyshares because something has changed in either Synedrion or the identities of the test TS servers, you can run:

```sh
./scripts/create-test-keyshares.sh`
```
from the project root. For an explanation of how the test keyshare sets are structured, see [`create-test-keyshares`](./scripts/create-test-keyshares).
## Support
Need help with something not necessarily related to `entropy-core`?
Expand Down
3 changes: 3 additions & 0 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ pub async fn sign(
let message_hash = Hasher::keccak(&message);

let validators_info = get_validators_not_signer_for_relay(api, rpc).await?;
if validators_info.is_empty() {
return Err(ClientError::NoNonSigningValidators);
}

tracing::debug!("Validators info {:?}", validators_info);
let block_number = rpc.chain_get_header(None).await?.ok_or(ClientError::BlockNumber)?.number;
Expand Down
4 changes: 2 additions & 2 deletions crates/client/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ pub enum ClientError {
TryFromSlice(#[from] std::array::TryFromSliceError),
#[error("User is not registered on-chain")]
NotRegistered,
#[error("No synced validators")]
NoSyncedValidators,
#[error("Cannot confirm program was created")]
CannotConfirmProgramCreated,
#[error("Cannot confirm program was removed")]
Expand All @@ -108,4 +106,6 @@ pub enum ClientError {
CannotQuerySynced,
#[error("Verifying key has incorrect length")]
BadVerifyingKeyLength,
#[error("There are no validators which can act as a relay node for signature requests")]
NoNonSigningValidators,
}
2 changes: 1 addition & 1 deletion crates/shared/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub const MAX_SIGNERS: u8 = 15;
pub const SIGNER_THRESHOLD: u8 = 2;

/// For testing to line up chain mock data and reshare_test
pub const TEST_RESHARE_BLOCK_NUMBER: u32 = 7;
pub const TEST_RESHARE_BLOCK_NUMBER: u32 = 9;

/// Program version number, must be incremented if version number changes
pub const PROGRAM_VERSION_NUMBER: u8 = 0;
31 changes: 31 additions & 0 deletions crates/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,34 @@ impl QuoteInputData {
Self(hasher.finalize().into())
}
}

/// A trait used to get different stored keys for a given account ID.
///
/// Not every account ID will have an given key, in which case the implementer is expected to
/// return `None`.
pub trait KeyProvider<T> {
/// Get an X25519 public key, if any, for the given account ID.
fn x25519_public_key(account_id: &T) -> Option<X25519PublicKey>;

/// Get a provisioning certification key, if any, for the given account ID.
fn provisioning_key(account_id: &T) -> Option<EncodedVerifyingKey>;
}

/// A trait used to describe a queue of attestations.
pub trait AttestationQueue<T> {
/// Indicate that a given attestation is ready to be moved from a pending state to a confirmed
/// state.
fn confirm_attestation(account_id: &T);

/// Request that an attestation get added to the queue for later processing.
fn push_pending_attestation(
signer: T,
tss_account: T,
x25519_public_key: X25519PublicKey,
endpoint: Vec<u8>,
provisioning_certification_key: EncodedVerifyingKey,
);

/// The list of pending (not processed) attestations.
fn pending_attestations() -> Vec<T>;
}
2 changes: 1 addition & 1 deletion crates/test-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition ='2021'

[dependencies]
entropy-client={ version="0.2.0", path="../client" }
clap ={ version="4.5.18", features=["derive"] }
clap ={ version="4.5.19", features=["derive"] }
colored ="2.0.4"
subxt ="0.35.3"
sp-core ="31.0.0"
Expand Down
7 changes: 4 additions & 3 deletions crates/test-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ enum CliCommand {
/// interface.
programs: Vec<String>,
/// Option of version numbers to go with the programs, will default to 0 if None
#[arg(short, long)]
program_version_numbers: Option<Vec<u8>>,
/// A name or mnemonic from which to derive a program modification keypair.
/// This is used to send the register extrinsic so it must be funded
Expand Down Expand Up @@ -311,7 +312,7 @@ pub async fn run_command(
program_version_number,
)
.await?;
Ok(format!("Program stored {hash}"))
Ok(format!("Program stored: {}", hex::encode(hash)))
},
CliCommand::RemoveProgram { mnemonic_option, hash } => {
let mnemonic = if let Some(mnemonic_option) = mnemonic_option {
Expand Down Expand Up @@ -409,7 +410,7 @@ pub async fn run_command(

if !programs.is_empty() {
println!(
"{:<11} {:<48} {:<11} {:<14} {} {}",
"{:<64} {:<48} {:<11} {:<14} {} {}",
"Hash".blue(),
"Stored by:".green(),
"Times used:".purple(),
Expand All @@ -420,7 +421,7 @@ pub async fn run_command(
for (hash, program_info) in programs {
println!(
"{} {} {:>11} {:>14} {:<13} {}",
hash,
hex::encode(hash),
program_info.deployer,
program_info.ref_counter,
program_info.bytecode.len(),
Expand Down
2 changes: 2 additions & 0 deletions crates/testing-utils/keyshares/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
See [`create-test-keyshares`](../../../scripts/create-test-keyshares) for an explanation of how
these are generated and what the different keyshare sets represent.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 8 additions & 12 deletions crates/testing-utils/src/create_test_keyshares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,32 @@ use std::collections::BTreeSet;
/// threshold keyshares with auxiliary info
pub async fn create_test_keyshares<Params>(
distributed_secret_key_bytes: [u8; 32],
alice: sr25519::Pair,
bob: sr25519::Pair,
charlie: sr25519::Pair,
signers: [sr25519::Pair; 3],
) -> Vec<(ThresholdKeyShare<Params, PartyId>, AuxInfo<Params, PartyId>)>
where
Params: SchemeParams,
{
let signing_key = SigningKey::from_bytes(&(distributed_secret_key_bytes).into()).unwrap();
let signers = vec![alice.clone(), bob.clone(), charlie.clone()];
let session_id = SessionId::from_seed(b"12345".as_slice());
let all_parties =
signers.iter().map(|pair| PartyId::from(pair.public())).collect::<BTreeSet<_>>();

let mut old_holders = all_parties.clone();
old_holders.remove(&PartyId::from(charlie.clone().public()));
// Remove one member as we initially create 2 of 2 keyshares, then reshare to 2 of 3
old_holders.remove(&PartyId::from(signers[2].public()));

let keyshares =
KeyShare::<Params, PartyId>::new_centralized(&mut OsRng, &old_holders, Some(&signing_key));
let aux_infos = AuxInfo::<Params, PartyId>::new_centralized(&mut OsRng, &all_parties);

let alice_id = PartyId::from(bob.public());
let new_holder = NewHolder {
verifying_key: keyshares[&alice_id].verifying_key(),
verifying_key: keyshares.values().next().unwrap().verifying_key(),
old_threshold: 2,
old_holders,
};

let mut sessions = signers
let mut sessions = signers[..2]
.iter()
.filter(|&pair| pair.public() != charlie.public())
.map(|pair| {
let inputs = KeyResharingInputs {
old_holder: Some(OldHolder {
Expand All @@ -82,7 +78,7 @@ where
})
.collect::<Vec<_>>();

let charlie_session = {
let new_holder_session = {
let inputs = KeyResharingInputs {
old_holder: None,
new_holder: Some(new_holder.clone()),
Expand All @@ -92,14 +88,14 @@ where
make_key_resharing_session(
&mut OsRng,
session_id,
PairWrapper(charlie),
PairWrapper(signers[2].clone()),
&all_parties,
inputs,
)
.unwrap()
};

sessions.push(charlie_session);
sessions.push(new_holder_session);

let new_t_key_shares = run_nodes(sessions).await;

Expand Down
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bip32={ version="0.5.2" }
bip39={ version="2.0.0", features=["zeroize"] }
bytes={ version="1.7", default-features=false, features=["serde"] }
base64="0.22.1"
clap={ version="4.5.18", features=["derive"] }
clap={ version="4.5.19", features=["derive"] }
num="0.4.3"
snow="0.9.6"
sha3="0.10.8"
Expand Down
6 changes: 6 additions & 0 deletions crates/threshold-signature-server/src/helpers/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ pub enum ValidatorName {
Eve,
}

impl std::fmt::Display for ValidatorName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", format!("{:?}", self).to_lowercase())
}
}

/// Output for --setup-only flag
#[derive(Deserialize, Debug, Clone)]
pub struct SetupOnlyOutput {
Expand Down
Loading

0 comments on commit 51f0bab

Please sign in to comment.