Skip to content

Commit

Permalink
Merge branch 'master' into subxt-client
Browse files Browse the repository at this point in the history
* master:
  Remove `subxt-signer` from `server` and `entropy-protocol` (#526)
  Add `bunyan` JSON formatter (#524)
  Get all benchmarks from our own benchmarks (#519)
  • Loading branch information
ameba23 committed Nov 28, 2023
2 parents f793eb1 + 2a79249 commit 725ed31
Show file tree
Hide file tree
Showing 58 changed files with 6,205 additions and 370 deletions.
78 changes: 11 additions & 67 deletions .maintain/frame-weight-template.hbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{{header}}
//! Autogenerated weights for {{pallet}}
//! Autogenerated weights for `{{pallet}}`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}}
//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: `{{cmd.repeat}}`, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}`
//! WORST CASE MAP SIZE: `{{cmd.worst_case_map_values}}`
//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}`
//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}}
//! WASM-EXECUTION: `{{cmd.wasm_execution}}`, CHAIN: `{{cmd.chain}}`, DB CACHE: {{cmd.db_cache}}

// Executed Command:
{{#each args as |arg|}}
Expand All @@ -17,27 +17,12 @@
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use frame_support::{traits::Get, weights::Weight};
use core::marker::PhantomData;

/// Weight functions needed for {{pallet}}.
pub trait WeightInfo {
{{#each benchmarks as |benchmark|}}
fn {{benchmark.name~}}
(
{{~#each benchmark.components as |c| ~}}
{{c.name}}: u32, {{/each~}}
) -> Weight;
{{/each}}
}

/// Weights for {{pallet}} using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
{{#if (eq pallet "frame_system")}}
impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
{{else}}
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
{{/if}}
/// Weight functions for `{{pallet}}`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> {{pallet}}::WeightInfo for WeightInfo<T> {
{{#each benchmarks as |benchmark|}}
{{#each benchmark.comments as |comment|}}
/// {{comment}}
Expand All @@ -54,19 +39,20 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds.
Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}})
Weight::from_parts({{underscore benchmark.base_weight}}, 0)
.saturating_add(Weight::from_parts(0, {{benchmark.base_calculated_proof_size}}))
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{underscore cw.error}}
.saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into()))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}_u64))
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
{{/each}}
{{#if (ne benchmark.base_writes "0")}}
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}_u64))
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
Expand All @@ -76,46 +62,4 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
{{/each}}
}
{{/each}}
}

// For backwards compatibility and tests
impl WeightInfo for () {
{{#each benchmarks as |benchmark|}}
{{#each benchmark.comments as |comment|}}
/// {{comment}}
{{/each}}
{{#each benchmark.component_ranges as |range|}}
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
{{/each}}
fn {{benchmark.name~}}
(
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
// Proof Size summary in bytes:
// Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}`
// Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds.
Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}})
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{underscore cw.error}}
.saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into()))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}}_u64))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into())))
{{/each}}
{{#if (ne benchmark.base_writes "0")}}
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}}_u64))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into())))
{{/each}}
{{#each benchmark.component_calculated_proof_size as |cp|}}
.saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into()))
{{/each}}
}
{{/each}}
}
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ At the moment this project **does not** adhere to
- Auxiliary data for program evaluation ([#475](https://github.com/entropyxyz/entropy-core/pull/475/))
- Add versioning to server ([#516](https://github.com/entropyxyz/entropy-core/pull/516/))
- Allow logger to be configured from CLI ([#520](https://github.com/entropyxyz/entropy-core/pull/520/))
- Add `bunyan` JSON formatter ([#524](https://github.com/entropyxyz/entropy-core/pull/524/))

### Changed
- Change SocketAddr type for String ([#496](https://github.com/entropyxyz/entropy-core/pull/496/))
- Add `#[tracing::instrument]` macro to routes ([#515](https://github.com/entropyxyz/entropy-core/pull/515/))
- Remove subxt-signer from server and entropy-protocol ([#526](https://github.com/entropyxyz/entropy-core/pull/526/))

### Fixed
- Return package version instead of rustc version ([#523](https://github.com/entropyxyz/entropy-core/pull/523/))
Expand Down
34 changes: 21 additions & 13 deletions Cargo.lock

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

41 changes: 22 additions & 19 deletions crypto/protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,27 @@ repository ='https://github.com/entropyxyz/entropy-core'
edition ='2021'

[dependencies]
async-trait ="0.1.73"
entropy-shared ={ path="../shared", default-features=false }
synedrion ={ git="ssh://git@github.com/entropyxyz/synedrion.git", branch="fix-32bit" }
serde ={ version="1.0", features=["derive"], default-features=false }
serde-big-array="0.5.1"
subxt ={ package="subxt", git="https://github.com/paritytech/subxt.git", tag="v0.32.1", default-features=false }
subxt-signer ={ version="0.31.0", features=["sr25519"], default-features=false }
tokio ={ version="1.16", features=["sync", "rt", "macros"] }
x25519-dalek ={ version="2.0.0", features=["static_secrets"] }
futures ="0.3"
hex ="*"
blake2 ="0.10.4"
thiserror ="1.0.48"
snow ="0.9.2"
getrandom ={ version="0.2", features=["js"] }
rand_core ={ version="0.6.4", features=["getrandom"] }
tracing ="0.1.37"
bincode ="1.3.3"
async-trait="0.1.73"
entropy-shared={ path="../shared", default-features=false }
synedrion={ git="ssh://git@github.com/entropyxyz/synedrion.git", branch="fix-32bit" }
serde={ version="1.0", features=["derive"], default-features=false }
subxt={ package="subxt", git="https://github.com/paritytech/subxt.git", tag="v0.32.1", default-features=false }
sp-core={ version="21.0.0", default-features=false, features=["full_crypto", "serde"] }
tokio={ version="1.16", features=["sync", "rt", "macros"] }
x25519-dalek={ version="2.0.0", features=["static_secrets"] }
futures="0.3"
hex="*"
blake2="0.10.4"
thiserror="1.0.48"
snow="0.9.2"
getrandom={ version="0.2", features=["js"] }
rand_core={ version="0.6.4", features=["getrandom"] }
tracing="0.1.37"
bincode="1.3.3"
schnorrkel={ version="0.9.1", default-features=false, features=[
"std",
"wasm-bindgen",
], optional=true }

# Used only with the `server` feature to implement the WsConnection trait
axum ={ version="0.6.18", features=["ws"], optional=true }
Expand All @@ -53,7 +56,6 @@ server=[
]
wasm=[
"entropy-shared/wasm",
"subxt-signer/web",
"dep:gloo-net",
"dep:wasm-bindgen-futures",
"dep:wasm-bindgen",
Expand All @@ -62,6 +64,7 @@ wasm=[
"dep:base64",
"subxt/web",
"dep:serde_json",
"dep:schnorrkel",
]

[lib]
Expand Down
47 changes: 17 additions & 30 deletions crypto/protocol/src/execute_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
use std::collections::HashMap;

use rand_core::{CryptoRngCore, OsRng};
use serde::{Deserialize, Serialize};
use serde_big_array::BigArray;
use sp_core::{sr25519, Pair};
use subxt::utils::AccountId32;
use subxt_signer::sr25519;
use synedrion::{
sessions::{
make_interactive_signing_session, make_key_refresh_session, make_keygen_and_aux_session,
Expand All @@ -30,40 +28,29 @@ pub type ChannelOut = Broadcaster;
/// Thin wrapper broadcasting channel out and messages from other nodes in
pub struct Channels(pub ChannelOut, pub ChannelIn);

struct SignerWrapper(sr25519::Keypair);
struct SignerWrapper(sr25519::Pair);

struct VerifierWrapper(sr25519::PublicKey);
#[derive(Clone)]
struct VerifierWrapper(sr25519::Public);

impl Clone for VerifierWrapper {
fn clone(&self) -> Self {
VerifierWrapper(sr25519::PublicKey(self.0 .0))
}
}

/// This is a raw signature from [sr25519::Signature]
// we cannot use Signature directly because it doesn't implement Serialize
#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
pub struct SignatureWrapper(#[serde(with = "BigArray")] [u8; 64]);

impl RandomizedPrehashSigner<SignatureWrapper> for SignerWrapper {
impl RandomizedPrehashSigner<sr25519::Signature> for SignerWrapper {
fn sign_prehash_with_rng(
&self,
_rng: &mut impl CryptoRngCore,
prehash: &[u8],
) -> Result<SignatureWrapper, signature::Error> {
) -> Result<sr25519::Signature, signature::Error> {
// TODO: doesn't seem like there's a way to randomize signing?
Ok(SignatureWrapper(self.0.sign(prehash).0))
Ok(self.0.sign(prehash))
}
}

impl PrehashVerifier<SignatureWrapper> for VerifierWrapper {
impl PrehashVerifier<sr25519::Signature> for VerifierWrapper {
fn verify_prehash(
&self,
prehash: &[u8],
signature: &SignatureWrapper,
signature: &sr25519::Signature,
) -> Result<(), signature::Error> {
let sig = sr25519::Signature(signature.0);
if sr25519::verify(&sig, prehash, &self.0) {
if sr25519::Pair::verify(signature, prehash, &self.0) {
Ok(())
} else {
Err(signature::Error::new())
Expand All @@ -81,7 +68,7 @@ pub async fn execute_signing_protocol(
mut chans: Channels,
key_share: &KeyShare<KeyParams>,
prehashed_message: &PrehashedMessage,
threshold_signer: &sr25519::Keypair,
threshold_signer: &sr25519::Pair,
threshold_accounts: Vec<AccountId32>,
) -> Result<RecoverableSignature, ProtocolExecutionErr> {
tracing::debug!("Executing signing protocol");
Expand All @@ -108,7 +95,7 @@ pub async fn execute_signing_protocol(
// We should have `Public` objects at this point, not `AccountId32`.
let verifiers = threshold_accounts
.into_iter()
.map(|acc| VerifierWrapper(sr25519::PublicKey(acc.0)))
.map(|acc| VerifierWrapper(sr25519::Public(acc.0)))
.collect::<Vec<_>>();

// TODO (#375): this should come from whoever initiates the signing process,
Expand Down Expand Up @@ -179,7 +166,7 @@ pub async fn execute_signing_protocol(
)]
pub async fn execute_dkg(
mut chans: Channels,
threshold_signer: &sr25519::Keypair,
threshold_signer: &sr25519::Pair,
threshold_accounts: Vec<AccountId32>,
my_idx: &u8,
) -> Result<KeyShare<KeyParams>, ProtocolExecutionErr> {
Expand All @@ -203,7 +190,7 @@ pub async fn execute_dkg(
// We should have `Public` objects at this point, not `AccountId32`.
let verifiers = threshold_accounts
.into_iter()
.map(|acc| VerifierWrapper(sr25519::PublicKey(acc.0)))
.map(|acc| VerifierWrapper(sr25519::Public(acc.0)))
.collect::<Vec<_>>();

// TODO (#375): this should come from whoever initiates the signing process,
Expand Down Expand Up @@ -273,13 +260,13 @@ pub async fn execute_dkg(
)]
pub async fn execute_proactive_refresh(
mut chans: Channels,
threshold_signer: &sr25519::Keypair,
threshold_signer: &sr25519::Pair,
threshold_accounts: Vec<AccountId32>,
my_idx: &u8,
old_key: KeyShare<KeyParams>,
) -> Result<KeyShare<KeyParams>, ProtocolExecutionErr> {
tracing::debug!("Executing proactive refresh");
tracing::trace!("Signing with {:?}", &threshold_signer);
tracing::debug!("Signing with {:?}", &threshold_signer.public());
tracing::trace!("Previous key {:?}", &old_key);

let party_ids: Vec<PartyId> =
Expand All @@ -299,7 +286,7 @@ pub async fn execute_proactive_refresh(
// We should have `Public` objects at this point, not `AccountId32`.
let verifiers = threshold_accounts
.into_iter()
.map(|acc| VerifierWrapper(sr25519::PublicKey(acc.0)))
.map(|acc| VerifierWrapper(sr25519::Public(acc.0)))
.collect::<Vec<_>>();

// TODO (#375): this should come from whoever initiates the signing process,
Expand Down
Loading

0 comments on commit 725ed31

Please sign in to comment.