-
Notifications
You must be signed in to change notification settings - Fork 0
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
ETF MILESTONE 2 #1
Conversation
initial_authorities.iter().enumerate().map(|(idx, auth)| { | ||
let pok = &genesis_resharing[idx].1; | ||
let mut bytes = Vec::new(); | ||
pok.serialize_compressed(&mut bytes).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to unwrap this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do. It could be an expect instead, but it's fine if this panics since it's a critical failure if the pok can't be serialized on genesis anyway.
@@ -342,6 +343,7 @@ where | |||
let mut sessions = VecDeque::new(); | |||
let mut header = best_grandpa.clone(); | |||
let state = loop { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a nit, but in general, we should avoid unnecessary diff changes
@@ -76,13 +83,13 @@ pub(crate) enum RoundAction { | |||
pub(crate) struct VoterOracle<B: Block> { | |||
/// Queue of known sessions. Keeps track of voting rounds (block numbers) within each session. | |||
/// | |||
/// There are three voter states corresponding to three queue states: | |||
/// There are three voter states coresponding to three queue states: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double r is correct
@@ -444,6 +419,52 @@ impl<T: Config> Pallet<T> { | |||
|
|||
Ok(()) | |||
} | |||
|
|||
fn initialize_genesis_shares( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is fine for this fn to panic?
// EB::SignatureGroup::deserialize_compressed( | ||
// // [48 bytes for SigGroup][96 bytes for PubKeyGroup] | ||
// &authority.to_raw_vec()[..48] | ||
// ).unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// EB::SignatureGroup::deserialize_compressed( | |
// // [48 bytes for SigGroup][96 bytes for PubKeyGroup] | |
// &authority.to_raw_vec()[..48] | |
// ).unwrap() |
// authority_keys_from_seed("Bob"), | ||
// authority_keys_from_seed("Charlie") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// authority_keys_from_seed("Bob"), | |
// authority_keys_from_seed("Charlie") |
sp-mmr-primitives = { path = "../../../primitives/merkle-mountain-range" } | ||
sp-runtime = { path = "../../../primitives/runtime" } | ||
tokio = "1.22.0" | ||
# etf-crypto-primitives = { git = "https://github.com/ideal-lab5/etf-sdk.git", branch = "w3fbls-migration" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleanup
@@ -118,6 +118,15 @@ node-inspect = { package = "staging-node-inspect", path = "../inspect", optional | |||
try-runtime-cli = { path = "../../../utils/frame/try-runtime/cli", optional = true } | |||
serde_json = { workspace = true, default-features = true } | |||
|
|||
# etf dependencies | |||
etf-crypto-primitives = { git = "https://github.com/ideal-lab5/etf-sdk.git", branch = "w3fbls-migration" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice :)
|
||
// recover the signature bytes from the payload | ||
let raw_etf_payload = vote.commitment.payload.get_raw(&sp_consensus_beefy::known_payloads::ETF_SIGNATURE) | ||
.unwrap_or({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noice!
|
||
if BeefyKeystore::verify(&vote.id, &vote.signature, &vote.commitment.encode()) { | ||
if BeefyKeystore::verify(&vote.id, &vote.signature, &vote.commitment.encode()) | ||
// && BeefyKeystore::verify(&vote.id, &etf_sig, &round.to_string().as_bytes()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// && BeefyKeystore::verify(&vote.id, &etf_sig, &round.to_string().as_bytes()) |
let sig = store | ||
.bls377_sign(BEEFY_KEY_TYPE, &public, &message) | ||
.map_err(|e| error::Error::Keystore(e.to_string()))? | ||
.ok_or_else(|| error::Error::Signature("bls377_sign() failed".to_string()))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.ok_or_else(|| error::Error::Signature("bls377_sign() failed".to_string()))?; | |
.ok_or_else(|| error::Error::Signature("bls377_sign() failed".to_string()))?; |
// // `target` is guaranteed > `best_beefy` since `min_block_delta` is at least `1`. | ||
// let target = | ||
// vote_target(best_grandpa, best_beefy, rounds.session_start(), self.min_block_delta); | ||
// info!( | ||
// target: LOG_TARGET, | ||
// "🥩 best beefy: #{:?}, best finalized: #{:?}, current_vote_target: {:?}", | ||
// best_beefy, | ||
// best_grandpa, | ||
// target | ||
// ); | ||
// target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleanup
// // `target` is guaranteed > `best_beefy` since `min_block_delta` is at least `1`. | |
// let target = | |
// vote_target(best_grandpa, best_beefy, rounds.session_start(), self.min_block_delta); | |
// info!( | |
// target: LOG_TARGET, | |
// "🥩 best beefy: #{:?}, best finalized: #{:?}, current_vote_target: {:?}", | |
// best_beefy, | |
// best_grandpa, | |
// target | |
// ); | |
// target |
if let Some(Some(validator_set)) = runtime_api.validator_set(hash).ok() { | ||
if let Some(Some(pok_bytes)) = runtime_api.read_share(hash, id.clone()).ok() { | ||
if let Ok(sig) = self.key_store.etf_sign( | ||
&id, | ||
&pok_bytes, | ||
&message, validator_set.len() as u8 | ||
) { | ||
return Some(sig); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: I usually find match
statements easier to read than nested if
s
if let Some(Some(validator_set)) = runtime_api.validator_set(hash).ok() { | |
if let Some(Some(pok_bytes)) = runtime_api.read_share(hash, id.clone()).ok() { | |
if let Ok(sig) = self.key_store.etf_sign( | |
&id, | |
&pok_bytes, | |
&message, validator_set.len() as u8 | |
) { | |
return Some(sig); | |
} | |
} | |
} | |
match (runtime_api.validator_set(hash), runtime_api.read_share(hash, id.clone()) { | |
(Some(validator_set), Some(pok_bytes)) if let Ok(sig) = self.key_store.etf_sign( | |
&id, | |
&pok_bytes, | |
&message, validator_set.len() as u8 | |
) => return Some(sig); | |
_ => return None; | |
} |
.map(|pair| pair.acss_recover(pok_bytes, threshold)) { | ||
// "IBE.Extract" Q = s*H(message) + DLEQ Proof | ||
let extract = etf_pair.sign(&message); | ||
// let pk = etf_pair.public(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleanup
// let pk = etf_pair.public(); |
# w3f-bls = { path = "../../../../../bls", features = ["std"] } | ||
# w3f-bls = { git = "https://github.com/driemworks/bls.git", branch = "etf", features = ["std"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# w3f-bls = { path = "../../../../../bls", features = ["std"] } | |
# w3f-bls = { git = "https://github.com/driemworks/bls.git", branch = "etf", features = ["std"] } |
@@ -200,16 +200,23 @@ pub mod ecdsa_bls_crypto { | |||
fn verify(&self, signature: &<Self as RuntimeAppPublic>::Signature, msg: &[u8]) -> bool { | |||
// We can not simply call | |||
// `EcdsaBlsPair::verify(signature.as_inner_ref(), msg, self.as_inner_ref())` | |||
// because that invokes ECDSA default verification which performs Blake2b hash | |||
// because that invokes ECDSA default verification which perfoms Blake2b hash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// because that invokes ECDSA default verification which perfoms Blake2b hash | |
// because that invokes ECDSA default verification which performs Blake2b hash |
// EcdsaBlsPair::verify::<H>( | ||
// signature.as_inner_ref(), | ||
// msg, | ||
// ) | ||
// EcdsaBlsPair::verify_with_hasher::<H>( | ||
// signature.as_inner_ref(), | ||
// msg, | ||
// self.as_inner_ref(), | ||
// ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// EcdsaBlsPair::verify::<H>( | |
// signature.as_inner_ref(), | |
// msg, | |
// ) | |
// EcdsaBlsPair::verify_with_hasher::<H>( | |
// signature.as_inner_ref(), | |
// msg, | |
// self.as_inner_ref(), | |
// ) |
@@ -538,7 +551,8 @@ mod tests { | |||
} | |||
|
|||
#[test] | |||
#[cfg(feature = "bls-experimental")] | |||
// #[cfg(feature = "bls-experimental")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// #[cfg(feature = "bls-experimental")] |
substrate/primitives/core/Cargo.toml
Outdated
# etf algs | ||
# etf-crypto-primitives = { path = "../../../../etf-sdk/etf-crypto-primitives", default-features = false, optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# etf algs | |
# etf-crypto-primitives = { path = "../../../../etf-sdk/etf-crypto-primitives", default-features = false, optional = true } |
substrate/primitives/core/src/bls.rs
Outdated
|
||
#[test] | ||
fn acss_recover_works() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we need a test here? 😄
substrate/primitives/core/src/bls.rs
Outdated
@@ -157,7 +182,7 @@ impl<T: BlsBound> TraitPair for Pair<T> { | |||
|
|||
fn derive<Iter: Iterator<Item = DeriveJunction>>( | |||
&self, | |||
path: Iter, | |||
path: Iter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path: Iter, | |
path: Iter, |
@@ -3,7 +3,7 @@ | |||
// Copyright (C) Parity Technologies (UK) Ltd. | |||
// SPDX-License-Identifier: Apache-2.0 | |||
|
|||
// Licensed under the Apache License, Version 2.0 (the "License"); | |||
// Licensed under the Apache License, version 2.0 (the "License"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Licensed under the Apache License, version 2.0 (the "License"); | |
// Licensed under the Apache License, Version 2.0 (the "License"); |
substrate/frame/beefy-mmr/src/lib.rs
Outdated
@@ -76,6 +76,7 @@ where | |||
pub struct BeefyEcdsaToEthereum; | |||
impl Convert<sp_consensus_beefy::ecdsa_crypto::AuthorityId, Vec<u8>> for BeefyEcdsaToEthereum { | |||
fn convert(beefy_id: sp_consensus_beefy::ecdsa_crypto::AuthorityId) -> Vec<u8> { | |||
// Vec::new() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Vec::new() |
// sp_core::ecdsa::Public::from(beefy_id) | ||
// .to_eth_address() | ||
// .map(|v| v.to_vec()) | ||
// .map_err(|_| { | ||
// log::debug!(target: "runtime::beefy", "Failed to convert BEEFY PublicKey to ETH address!"); | ||
// }) | ||
// .unwrap_or_default() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// sp_core::ecdsa::Public::from(beefy_id) | |
// .to_eth_address() | |
// .map(|v| v.to_vec()) | |
// .map_err(|_| { | |
// log::debug!(target: "runtime::beefy", "Failed to convert BEEFY PublicKey to ETH address!"); | |
// }) | |
// .unwrap_or_default() |
pub struct BeefyBlsToEthereum; | ||
impl Convert<sp_consensus_beefy::bls_crypto::AuthorityId, Vec<u8>> for BeefyBlsToEthereum { | ||
fn convert(_beefy_id: sp_consensus_beefy::bls_crypto::AuthorityId) -> Vec<u8> { | ||
Vec::new() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? We aren't using it as far as I can see
substrate/frame/beefy/src/lib.rs
Outdated
@@ -55,10 +54,11 @@ mod tests; | |||
pub use crate::equivocation::{EquivocationOffence, EquivocationReportSystem, TimeSlot}; | |||
pub use pallet::*; | |||
|
|||
use crate::equivocation::EquivocationEvidenceFor; | |||
use crate::equivocation::{EquivocationEvidenceFor}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use crate::equivocation::{EquivocationEvidenceFor}; | |
use crate::equivocation::EquivocationEvidenceFor; |
substrate/frame/beefy/src/lib.rs
Outdated
|
||
const LOG_TARGET: &str = "runtime::beefy"; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
genesis_resharing: &Vec<(T::BeefyId, T::BeefyId, Vec<u8>)>, | ||
round_key: Vec<u8>, | ||
) -> Result<(), ()> { | ||
// TODO: define 96 as a const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and BoundedVec<u8, ConstU32<1024>>
as a type?
// let commitments = pallet_beefy::Commitments::<Runtime>::get(); | ||
// if at as usize >= commitments.len() { | ||
// return None; | ||
// } | ||
// Some(commitments[at as usize].clone().into_inner()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// let commitments = pallet_beefy::Commitments::<Runtime>::get(); | |
// if at as usize >= commitments.len() { | |
// return None; | |
// } | |
// Some(commitments[at as usize].clone().into_inner()) |
#[cfg(feature = "bls-experimental")] | ||
use sp_core::bls377; | ||
#[cfg(feature = "bls-experimental")] | ||
use sp_core::ecdsa_bls377; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[cfg(feature = "bls-experimental")] | |
use sp_core::bls377; | |
#[cfg(feature = "bls-experimental")] | |
use sp_core::ecdsa_bls377; | |
#[cfg(feature = "bls-experimental")] | |
use sp_core::{bls377, ecdsa_bls377}; |
@@ -397,6 +401,7 @@ where | |||
.ok_or_else(|| Error::Backend("Invalid BEEFY chain".into()))? | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.unwrap() | ||
.expect("todo"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to return an Error here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good, just some small comments
Outdated. |
No description provided.