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

ETF MILESTONE 2 #1

Closed
wants to merge 19 commits into from
Closed

ETF MILESTONE 2 #1

wants to merge 19 commits into from

Conversation

driemworks
Copy link

No description provided.

initial_authorities.iter().enumerate().map(|(idx, auth)| {
let pok = &genesis_resharing[idx].1;
let mut bytes = Vec::new();
pok.serialize_compressed(&mut bytes).unwrap();

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?

Copy link
Author

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 {

Copy link

@juangirini juangirini Apr 17, 2024

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

Suggested change

@@ -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:

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(

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?

@driemworks driemworks changed the title Etf ETF MILESTONE 2 Apr 18, 2024
Comment on lines 412 to 415
// EB::SignatureGroup::deserialize_compressed(
// // [48 bytes for SigGroup][96 bytes for PubKeyGroup]
// &authority.to_raw_vec()[..48]
// ).unwrap()
Copy link

@juangirini juangirini Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// EB::SignatureGroup::deserialize_compressed(
// // [48 bytes for SigGroup][96 bytes for PubKeyGroup]
// &authority.to_raw_vec()[..48]
// ).unwrap()

Comment on lines +527 to +528
// authority_keys_from_seed("Bob"),
// authority_keys_from_seed("Charlie")
Copy link

@juangirini juangirini Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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" }

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" }

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({

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())
Copy link

@juangirini juangirini Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// && 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()))?;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.ok_or_else(|| error::Error::Signature("bls377_sign() failed".to_string()))?;
.ok_or_else(|| error::Error::Signature("bls377_sign() failed".to_string()))?;

Comment on lines 260 to 270
// // `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
Copy link

@juangirini juangirini Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup

Suggested change
// // `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

Comment on lines +847 to +857
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);
}
}
}

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 ifs

Suggested change
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();
Copy link

@juangirini juangirini Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup

Suggested change
// let pk = etf_pair.public();

Comment on lines 35 to 36
# w3f-bls = { path = "../../../../../bls", features = ["std"] }
# w3f-bls = { git = "https://github.com/driemworks/bls.git", branch = "etf", features = ["std"] }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// because that invokes ECDSA default verification which perfoms Blake2b hash
// because that invokes ECDSA default verification which performs Blake2b hash

Comment on lines 211 to 219
// EcdsaBlsPair::verify::<H>(
// signature.as_inner_ref(),
// msg,
// )
// EcdsaBlsPair::verify_with_hasher::<H>(
// signature.as_inner_ref(),
// msg,
// self.as_inner_ref(),
// )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// #[cfg(feature = "bls-experimental")]

Comment on lines 67 to 68
# etf algs
# etf-crypto-primitives = { path = "../../../../etf-sdk/etf-crypto-primitives", default-features = false, optional = true }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# etf algs
# etf-crypto-primitives = { path = "../../../../etf-sdk/etf-crypto-primitives", default-features = false, optional = true }


#[test]
fn acss_recover_works() {

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? 😄

@@ -157,7 +182,7 @@ impl<T: BlsBound> TraitPair for Pair<T> {

fn derive<Iter: Iterator<Item = DeriveJunction>>(
&self,
path: Iter,
path: Iter,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Licensed under the Apache License, version 2.0 (the "License");
// Licensed under the Apache License, Version 2.0 (the "License");

@@ -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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Vec::new()

Comment on lines +95 to +101
// 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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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()

Comment on lines +91 to +94
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()

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

@@ -55,10 +54,11 @@ mod tests;
pub use crate::equivocation::{EquivocationOffence, EquivocationReportSystem, TimeSlot};
pub use pallet::*;

use crate::equivocation::EquivocationEvidenceFor;
use crate::equivocation::{EquivocationEvidenceFor};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use crate::equivocation::{EquivocationEvidenceFor};
use crate::equivocation::EquivocationEvidenceFor;


const LOG_TARGET: &str = "runtime::beefy";


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

genesis_resharing: &Vec<(T::BeefyId, T::BeefyId, Vec<u8>)>,
round_key: Vec<u8>,
) -> Result<(), ()> {
// TODO: define 96 as a const

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?

Comment on lines 3040 to 3044
// let commitments = pallet_beefy::Commitments::<Runtime>::get();
// if at as usize >= commitments.len() {
// return None;
// }
// Some(commitments[at as usize].clone().into_inner())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// let commitments = pallet_beefy::Commitments::<Runtime>::get();
// if at as usize >= commitments.len() {
// return None;
// }
// Some(commitments[at as usize].clone().into_inner())

Comment on lines 27 to 30
#[cfg(feature = "bls-experimental")]
use sp_core::bls377;
#[cfg(feature = "bls-experimental")]
use sp_core::ecdsa_bls377;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[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()))?
}


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines 776 to 777
.unwrap()
.expect("todo");
Copy link

@juangirini juangirini Apr 22, 2024

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?

Copy link

@juangirini juangirini left a 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

@driemworks
Copy link
Author

Outdated.
We decided to not go this route.

@driemworks driemworks closed this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants