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

More fixes #348

Merged
merged 9 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 7 additions & 6 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,17 @@ grandpa-prover = { path = "./modules/consensus/grandpa/prover" }

# consensus clients
ismp-bsc = { path = "./modules/ismp/clients/bsc", default-features = false }
ismp-grandpa = { version = "1.15.1", path = "./modules/ismp/clients/grandpa", default-features = false }
ismp-parachain = { version = "1.15.1", path = "./modules/ismp/clients/parachain/client", default-features = false }
ismp-parachain-inherent = { version = "1.15.1", path = "./modules/ismp/clients/parachain/inherent" }
ismp-grandpa = { version = "1.15.2", path = "./modules/ismp/clients/grandpa", default-features = false }
ismp-parachain = { version = "1.15.2", path = "./modules/ismp/clients/parachain/client", default-features = false }
ismp-parachain-inherent = { version = "1.15.2", path = "./modules/ismp/clients/parachain/inherent" }
ismp-parachain-runtime-api = { version = "1.15.1", path = "./modules/ismp/clients/parachain/runtime-api", default-features = false }
ismp-sync-committee = { path = "./modules/ismp/clients/sync-committee", default-features = false }
arbitrum-verifier = { path = "./modules/ismp/clients/arbitrum", default-features = false }
op-verifier = { path = "./modules/ismp/clients/optimism", default-features = false }

# state machine clients
evm-state-machine = { path = "./modules/ismp/state-machines/evm", default-features = false }
substrate-state-machine = { version = "1.15.1", path = "modules/ismp/state-machines/substrate", default-features = false }
substrate-state-machine = { version = "1.15.2", path = "modules/ismp/state-machines/substrate", default-features = false }
hyperbridge-client-machine = { path = "modules/ismp/state-machines/hyperbridge", default-features = false }

# published pallets
Expand All @@ -324,7 +324,7 @@ pallet-token-gateway-inspector = { path = "modules/ismp/pallets/token-gateway-in
pallet-mmr-runtime-api = { path = "modules/trees/mmr/pallet/runtime-api", default-features = false }
mmr-gadget = { path = "modules/trees/mmr/gadget" }
ethereum-triedb = { version = "0.1.1", path = "./modules/trees/ethereum", default-features = false }
mmr-primitives = { version = "1.15.1", path = "modules/trees/mmr/primitives", default-features = false }
mmr-primitives = { version = "1.15.2", path = "modules/trees/mmr/primitives", default-features = false }

# runtimes
gargantua-runtime = { path = "./parachain/runtimes/gargantua", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/developers/polkadot/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ cargo add pallet-token-gateway

## Versioning

The versioning of these crates track the LTS releases of Polkadot SDK and are only updated when new LTS versions are released. For instance the `stable2407` version is available for all crates as **v1.15.x**. Subsequent LTS releases will see a minor version bump. eg `stable2409` will be supportted by **v1.16.x** and so on.
The versioning of these crates track the LTS releases of Polkadot SDK and are only updated when new LTS versions are released. For instance the `stable2407` version is available for all crates as **v1.15.x**. Subsequent LTS releases will see a minor version bump. eg `stable2409` will be supported by **v1.16.x** and so on.
58 changes: 37 additions & 21 deletions modules/consensus/beefy/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@ pub mod relay;
/// Helper functions and types
pub mod util;

/// Some consensus related constants
pub mod constants {

/// Block at which BEEFY was activated on rococo
pub const ROCOCO_BEEFY_ACTIVATION_BLOCK: u32 = 3_804_028;
}

use anyhow::anyhow;
use beefy_verifier_primitives::{
ConsensusMessage, ConsensusState, MmrProof, ParachainHeader, ParachainProof, SignedCommitment,
ConsensusMessage, ConsensusState, MmrProof, ParachainHeader, ParachainProof,
SignatureWithAuthorityIndex, SignedCommitment,
};
use codec::{Decode, Encode};
use hex_literal::hex;
Expand All @@ -46,7 +40,7 @@ use sp_consensus_beefy::{
use sp_io::hashing::keccak_256;
use sp_mmr_primitives::LeafProof;
use subxt::{rpc_params, Config, OnlineClient};
use util::{hash_authority_addresses, prove_authority_set, AuthorityProofWithSignatures};
use util::hash_authority_addresses;

/// This contains methods for fetching BEEFY proofs for parachain headers.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -208,30 +202,49 @@ impl<R: Config, P: Config> Prover<R, P> {
&self,
signed_commitment: sp_consensus_beefy::SignedCommitment<u32, Signature>,
) -> Result<ConsensusMessage, anyhow::Error> {
let subxt_block_number: subxt::rpc::types::BlockNumber =
(signed_commitment.commitment.block_number - 1).into();
let block_number: subxt::rpc::types::NumberOrHex =
signed_commitment.commitment.block_number.into();
let block_hash = self
.relay
.rpc()
.block_hash(Some(subxt_block_number))
.block_hash(Some(block_number.into()))
.await?
.ok_or_else(|| anyhow!("Failed to query blockhash for blocknumber"))?;

let current_authorities = self.beefy_authorities(Some(block_hash)).await?;

// Current LeafIndex
let block_number = signed_commitment.commitment.block_number;
let leaf_proof = fetch_mmr_proof(&self.relay, block_number.into()).await?;
let leaf_proof = fetch_mmr_proof(&self.relay, block_number.try_into()?).await?;
let leaves: Vec<Vec<u8>> = codec::Decode::decode(&mut &*leaf_proof.leaves.0)?;
let latest_leaf: MmrLeaf<u32, H256, H256, H256> = codec::Decode::decode(&mut &*leaves[0])?;
let mmr_proof: LeafProof<H256> = Decode::decode(&mut &*leaf_proof.proof.0)?;

// create authorities proof
let signatures = signed_commitment
.signatures
.iter()
.enumerate()
.map(|(index, x)| {
if let Some(sig) = x {
let mut temp = [0u8; 65];
if sig.len() == 65 {
temp.copy_from_slice(&*sig.encode());
let last = temp.last_mut().unwrap();
*last = *last + 27;
Some(SignatureWithAuthorityIndex { index: index as u32, signature: temp })
} else {
None
}
} else {
None
}
})
.filter_map(|x| x)
.collect::<Vec<_>>();
let current_authorities = self.beefy_authorities(Some(block_hash)).await?;
let authority_address_hashes = hash_authority_addresses(
current_authorities.into_iter().map(|x| x.encode()).collect(),
)?;

let AuthorityProofWithSignatures { authority_proof, signatures } =
prove_authority_set(&signed_commitment, authority_address_hashes)?;
let indices = signatures.iter().map(|x| x.index as usize).collect::<Vec<_>>();
let authority_proof = util::merkle_proof(&authority_address_hashes, &indices);

let mmr = MmrProof {
signed_commitment: SignedCommitment {
Expand All @@ -243,8 +256,11 @@ impl<R: Config, P: Config> Prover<R, P> {
authority_proof,
};

let heads = self.paras_parachains(Some(block_hash)).await?;

let heads = self
.paras_parachains(Some(R::Hash::decode(
&mut &*latest_leaf.parent_number_and_hash.1.encode(),
)?))
.await?;
let (parachains, indices): (Vec<_>, Vec<_>) = self
.para_ids
.iter()
Expand Down
36 changes: 0 additions & 36 deletions modules/consensus/beefy/prover/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,42 +106,6 @@ pub async fn fetch_timestamp_extrinsic_with_proof<T: Config>(
Ok(TimeStampExtWithProof { ext, proof })
}

/// Get the proof for authority set that signed this commitment
pub fn prove_authority_set(
signed_commitment: &sp_consensus_beefy::SignedCommitment<
u32,
sp_consensus_beefy::ecdsa_crypto::Signature,
>,
authority_address_hashes: Vec<Hash>,
) -> Result<AuthorityProofWithSignatures, anyhow::Error> {
let signatures = signed_commitment
.signatures
.iter()
.enumerate()
.map(|(index, x)| {
if let Some(sig) = x {
let mut temp = [0u8; 65];
if sig.len() == 65 {
temp.copy_from_slice(&*sig.encode());
let last = temp.last_mut().unwrap();
*last = *last + 27;
Some(SignatureWithAuthorityIndex { index: index as u32, signature: temp })
} else {
None
}
} else {
None
}
})
.filter_map(|x| x)
.collect::<Vec<_>>();

let signature_indices = signatures.iter().map(|x| x.index as usize).collect::<Vec<_>>();
let authority_proof = merkle_proof(&authority_address_hashes, &signature_indices);

Ok(AuthorityProofWithSignatures { authority_proof, signatures })
}

/// Hash encoded authority public keys
pub fn hash_authority_addresses(
encoded_public_keys: Vec<Vec<u8>>,
Expand Down
3 changes: 1 addition & 2 deletions modules/ismp/clients/grandpa/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ismp-grandpa"
version = "1.15.1"
version = "1.15.2"
edition = "2021"
authors = ["Polytope Labs <[email protected]>"]
license = "Apache-2.0"
Expand All @@ -24,7 +24,6 @@ grandpa-verifier-primitives = { workspace = true }
grandpa-verifier = { workspace = true }
pallet-ismp = { workspace = true }


# substrate
frame-support = { workspace = true }
frame-system = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion modules/ismp/clients/parachain/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ismp-parachain"
version = "1.15.1"
version = "1.15.2"
edition = "2021"
authors = ["Polytope Labs <[email protected]>"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion modules/ismp/clients/parachain/inherent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ismp-parachain-inherent"
version = "1.15.1"
version = "1.15.2"
edition = "2021"
authors = ["Polytope Labs <[email protected]>"]
license = "Apache-2.0"
Expand Down
2 changes: 0 additions & 2 deletions modules/ismp/pallets/pallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ ismp = { workspace = true }
codec = { workspace = true }
scale-info = { workspace = true }
sp-mmr-primitives = { workspace = true }
mmr-primitives = { workspace = true }
anyhow = { workspace = true, default-features = false }

# crates.io
Expand Down Expand Up @@ -55,7 +54,6 @@ std = [
"sp-api/std",
"serde/default",
"sp-mmr-primitives/std",
"mmr-primitives/std",
"anyhow/std"
]
disable-panic-handler = ["sp-io/disable_panic_handler", "sp-io/disable_oom", "sp-io/disable_allocator"]
Expand Down
3 changes: 1 addition & 2 deletions modules/ismp/pallets/pallet/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate::{
child_trie::{RequestCommitments, ResponseCommitments},
dispatcher::{FeeMetadata, RequestMetadata},
offchain::{Leaf, LeafIndexAndPos, Proof, ProofKeys},
offchain::{ForkIdentifier, Leaf, LeafIndexAndPos, OffchainDBProvider, Proof, ProofKeys},
weights::get_weight,
Config, Error, Event, Pallet, Responded, TransparentOffchainDB,
};
Expand All @@ -31,7 +31,6 @@ use ismp::{
messaging::{hash_request, hash_response, Message},
router::{Request, Response},
};
use mmr_primitives::{ForkIdentifier, OffchainDBProvider};
use sp_core::{offchain::StorageKind, H256};

impl<T: Config> Pallet<T> {
Expand Down
2 changes: 1 addition & 1 deletion modules/ismp/pallets/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ mod utils;
pub mod weights;

use crate::offchain::Leaf;
use mmr_primitives::{OffchainDBProvider, PlainOffChainDB};
use offchain::{OffchainDBProvider, PlainOffChainDB};
// Re-export pallet items so that they can be accessed from the crate namespace.
pub use pallet::*;

Expand Down
Loading
Loading