From da634a84fbe05e662d829d646986275d7e114bd5 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Mon, 2 Dec 2024 23:17:38 +0100 Subject: [PATCH 01/11] fix docs --- docs/pages/developers/polkadot/pallet-ismp.mdx | 4 ---- docs/pages/index.mdx | 2 +- docs/vocs.config.tsx | 1 - 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/docs/pages/developers/polkadot/pallet-ismp.mdx b/docs/pages/developers/polkadot/pallet-ismp.mdx index 2cf56fda7..67b2eff0f 100644 --- a/docs/pages/developers/polkadot/pallet-ismp.mdx +++ b/docs/pages/developers/polkadot/pallet-ismp.mdx @@ -175,10 +175,6 @@ The `pallet_ismp::Pallet` implements the neccessary interfaces for the ISMP f - [`IsmpDispatcher`](/protocol/ismp/dispatcher): It implements `IsmpDispatcher` allowing it to dispatch requests and responses. This is the low-level ISMP framework dispatcher. It can be used to dispatch requests that are not addressed to Hyperbridge and perhaps meant for other state machines. Dispatching requests to be Hyperbridge should be done throught the [`pallet-hyperbridge`](/developers/polkadot/fees#pallet-hyperbridge) module. Which also implements the `IsmpDispatcher` interface but collects the necessary fees. - :::danger[IMPORTANT] - Once the Hyperbridge token goes live, requests or responses that are not dispatched by `pallet-hyperbridge` will not be processed by Hyperbridge. They will fail transaction pool validation and will not be included in blocks. - ::: - ## Calls diff --git a/docs/pages/index.mdx b/docs/pages/index.mdx index 0d3a384bc..bc8f405f2 100644 --- a/docs/pages/index.mdx +++ b/docs/pages/index.mdx @@ -1,6 +1,6 @@ --- layout: landing -title: Hperbridge Documentation +title: Hyperbridge Documentation description: Secure interoperability requires the verification of various proofs, including consensus proofs, consensus fault proofs, state proofs, and state transition validity proofs. For blockchains to securely interoperate, they must verify these proofs onchain to confirm the finalized (irreversible) state of their counterparty. --- diff --git a/docs/vocs.config.tsx b/docs/vocs.config.tsx index 8b47ef894..35c587356 100644 --- a/docs/vocs.config.tsx +++ b/docs/vocs.config.tsx @@ -46,7 +46,6 @@ export default defineConfig({ title: "Hyperbridge Documentation", description: "Hyperbridge is a coprocessor for cryptographically secure interoperability", - // todo: add logo ogImageUrl: "https://docs.hyperbridge.network/og.png", logoUrl: { From c35f736bbe19511d3d90b78b198696dd8d107bde Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Sun, 8 Dec 2024 00:21:59 +0000 Subject: [PATCH 02/11] refurbish pallet-ismp Config api --- .../developers/polkadot/pallet-ismp-rpc.mdx | 6 +- evm/integration-tests/src/lib.rs | 2 +- .../src/tests/get_response.rs | 2 +- .../src/tests/post_request.rs | 2 +- .../src/tests/post_response.rs | 2 +- modules/hyperclient/src/providers/evm.rs | 2 +- .../hyperclient/src/providers/substrate.rs | 2 +- .../ismp/clients/parachain/client/src/lib.rs | 4 +- .../ismp/pallets/call-decompressor/src/lib.rs | 2 +- modules/ismp/pallets/pallet/README.md | 8 +-- modules/ismp/pallets/pallet/src/dispatcher.rs | 6 +- modules/ismp/pallets/pallet/src/impls.rs | 31 +++++---- modules/ismp/pallets/pallet/src/lib.rs | 32 +++++----- .../pallet/src/{mmr.rs => offchain.rs} | 0 modules/ismp/pallets/rpc/src/lib.rs | 4 +- modules/ismp/pallets/runtime-api/src/lib.rs | 2 +- .../pallets/state-coprocessor/src/impls.rs | 4 +- .../ismp/pallets/state-coprocessor/src/lib.rs | 6 +- modules/ismp/pallets/testsuite/src/runtime.rs | 4 +- .../testsuite/src/tests/pallet_ismp.rs | 6 +- .../src/tests/pallet_ismp_relayer.rs | 2 +- modules/trees/mmr/gadget/src/lib.rs | 2 +- modules/trees/mmr/gadget/src/offchain_mmr.rs | 2 +- modules/trees/mmr/pallet/src/lib.rs | 61 ++---------------- modules/trees/mmr/pallet/src/mmr/mmr.rs | 64 ------------------- modules/trees/mmr/pallet/src/mmr/mod.rs | 2 +- modules/trees/mmr/pallet/src/mmr/storage.rs | 2 +- modules/trees/mmr/primitives/src/lib.rs | 51 +++++++-------- parachain/node/src/runtime_api.rs | 4 +- parachain/runtimes/gargantua/src/ismp.rs | 2 +- parachain/runtimes/gargantua/src/lib.rs | 4 +- parachain/runtimes/messier/src/lib.rs | 16 ++--- parachain/runtimes/nexus/src/ismp.rs | 2 +- parachain/runtimes/nexus/src/lib.rs | 4 +- parachain/simtests/src/pallet_mmr.rs | 4 +- tesseract/evm/src/tx.rs | 2 +- tesseract/relayer/src/fees.rs | 2 +- tesseract/substrate/src/calls.rs | 2 +- tesseract/substrate/src/provider.rs | 2 +- 39 files changed, 118 insertions(+), 239 deletions(-) rename modules/ismp/pallets/pallet/src/{mmr.rs => offchain.rs} (100%) diff --git a/docs/pages/developers/polkadot/pallet-ismp-rpc.mdx b/docs/pages/developers/polkadot/pallet-ismp-rpc.mdx index 7b2c0af71..87fce3527 100644 --- a/docs/pages/developers/polkadot/pallet-ismp-rpc.mdx +++ b/docs/pages/developers/polkadot/pallet-ismp-rpc.mdx @@ -78,7 +78,7 @@ This method accepts a list of request commitments and responds with the requests .await.unwrap(); // Use an actual request commitment that exists let commitment = H256::random(); - let params = rpc_params![pallet_ismp::mmr::LeafIndexQuery { commitment }]; + let params = rpc_params![pallet_ismp::offchain::LeafIndexQuery { commitment }]; let requests: Vec = client.rpc().request("ismp_queryRequests", params).await.unwrap(); ``` @@ -90,7 +90,7 @@ This method accepts a list of response commitments and responds with the request .await.unwrap(); // Use an actual response commitment that exists let commitment = H256::random(); - let params = rpc_params![pallet_ismp::mmr::LeafIndexQuery { commitment }]; + let params = rpc_params![pallet_ismp::offchain::LeafIndexQuery { commitment }]; let requests: Vec = client.rpc().request("ismp_queryResponses", params).await.unwrap(); ``` @@ -104,7 +104,7 @@ This method queries the mmr proof a list of request or response commitments, it let commitment = H256::random(); // Block height at which proof should be queried let at = 100; - let params = rpc_params![at, pallet_ismp::mmr::ProofKeys::Requests(vec![commitment])]; + let params = rpc_params![at, pallet_ismp::offchain::ProofKeys::Requests(vec![commitment])]; let requests: Proof = client.rpc().request("ismp_queryMmrProof", params).await.unwrap(); ``` diff --git a/evm/integration-tests/src/lib.rs b/evm/integration-tests/src/lib.rs index d36c8bfdc..1a80370ff 100644 --- a/evm/integration-tests/src/lib.rs +++ b/evm/integration-tests/src/lib.rs @@ -5,7 +5,7 @@ pub use ethers::{abi::Token, types::U256, utils::keccak256}; use merkle_mountain_range::{util::MemMMR, Error, Merge}; -use pallet_ismp::mmr::Leaf; +use pallet_ismp::offchain::Leaf; use pallet_mmr::mmr::Hasher; use primitive_types::H256; use sp_runtime::traits; diff --git a/evm/integration-tests/src/tests/get_response.rs b/evm/integration-tests/src/tests/get_response.rs index 5fc53bd33..3d3cf8f5e 100644 --- a/evm/integration-tests/src/tests/get_response.rs +++ b/evm/integration-tests/src/tests/get_response.rs @@ -14,7 +14,7 @@ use ismp_solidity_abi::{ shared_types::GetRequest, }; use mmr_primitives::DataOrHash; -use pallet_ismp::mmr::Leaf; +use pallet_ismp::offchain::Leaf; use primitive_types::H256; use std::{env, path::PathBuf}; diff --git a/evm/integration-tests/src/tests/post_request.rs b/evm/integration-tests/src/tests/post_request.rs index aca457fec..c537afcc1 100644 --- a/evm/integration-tests/src/tests/post_request.rs +++ b/evm/integration-tests/src/tests/post_request.rs @@ -14,7 +14,7 @@ use ismp_solidity_abi::{ shared_types::StateCommitment, }; use mmr_primitives::DataOrHash; -use pallet_ismp::mmr::Leaf; +use pallet_ismp::offchain::Leaf; use std::{env, path::PathBuf}; #[tokio::test(flavor = "multi_thread")] diff --git a/evm/integration-tests/src/tests/post_response.rs b/evm/integration-tests/src/tests/post_response.rs index a4a0e51c1..c7dbd035f 100644 --- a/evm/integration-tests/src/tests/post_response.rs +++ b/evm/integration-tests/src/tests/post_response.rs @@ -23,7 +23,7 @@ use ismp_solidity_abi::{ }; use mmr_primitives::DataOrHash; -use pallet_ismp::mmr::Leaf; +use pallet_ismp::offchain::Leaf; use primitive_types::H256; use std::{env, path::PathBuf}; diff --git a/modules/hyperclient/src/providers/evm.rs b/modules/hyperclient/src/providers/evm.rs index 318b68f32..2a46a4cce 100644 --- a/modules/hyperclient/src/providers/evm.rs +++ b/modules/hyperclient/src/providers/evm.rs @@ -55,7 +55,7 @@ use ismp_solidity_abi::{ }, }; use mmr_primitives::mmr_position_to_k_index; -use pallet_ismp::mmr::{LeafIndexAndPos, Proof as MmrProof}; +use pallet_ismp::offchain::{LeafIndexAndPos, Proof as MmrProof}; use std::{collections::BTreeMap, ops::RangeInclusive, sync::Arc}; #[cfg(all(target_arch = "wasm32", feature = "web"))] diff --git a/modules/hyperclient/src/providers/substrate.rs b/modules/hyperclient/src/providers/substrate.rs index 4cf2b90b9..67ba786e5 100644 --- a/modules/hyperclient/src/providers/substrate.rs +++ b/modules/hyperclient/src/providers/substrate.rs @@ -38,7 +38,7 @@ use pallet_ismp::{ child_trie::{ request_commitment_storage_key, response_commitment_storage_key, CHILD_TRIE_PREFIX, }, - mmr::ProofKeys, + offchain::ProofKeys, ResponseReceipt, }; use serde::{Deserialize, Serialize}; diff --git a/modules/ismp/clients/parachain/client/src/lib.rs b/modules/ismp/clients/parachain/client/src/lib.rs index c3aaee990..15a6a208d 100644 --- a/modules/ismp/clients/parachain/client/src/lib.rs +++ b/modules/ismp/clients/parachain/client/src/lib.rs @@ -119,9 +119,7 @@ pub mod pallet { // Handling error will prevent this inherent from breaking block production if there's a // reorg and it's no longer valid - if let Err(err) = - pallet_ismp::Pallet::::handle_messages(vec![Message::Consensus(data)]) - { + if let Err(err) = pallet_ismp::Pallet::::execute(vec![Message::Consensus(data)]) { log::trace!(target: "ismp", "Parachain inherent consensus update failed {err:?}"); } else { ConsensusUpdated::::put(true); diff --git a/modules/ismp/pallets/call-decompressor/src/lib.rs b/modules/ismp/pallets/call-decompressor/src/lib.rs index c06fbe510..222670d82 100644 --- a/modules/ismp/pallets/call-decompressor/src/lib.rs +++ b/modules/ismp/pallets/call-decompressor/src/lib.rs @@ -223,7 +223,7 @@ where if let Some(call) = IsSubType::>::is_sub_type(&runtime_call).cloned() { match call { pallet_ismp::Call::handle_unsigned { messages } => - >::handle_messages(messages) + >::execute(messages) .map_err(|_| Error::::ErrorExecutingCall)?, _ => Err(Error::::CallNotSupported)?, }; diff --git a/modules/ismp/pallets/pallet/README.md b/modules/ismp/pallets/pallet/README.md index 00374d8a1..8fafd3158 100644 --- a/modules/ismp/pallets/pallet/README.md +++ b/modules/ismp/pallets/pallet/README.md @@ -48,7 +48,7 @@ The following example shows how to configure `pallet-ismp` in your runtime use frame_support::parameter_types; use frame_system::EnsureRoot; use ismp::Error; -use pallet_ismp::NoOpMmrTree; +use pallet_ismp::TransparentOffchainDB; use ismp::host::StateMachine; use ismp::module::IsmpModule; use ismp::router::{IsmpRouter, Post, Response, Timeout}; @@ -82,9 +82,9 @@ impl pallet_ismp::Config for Runtime { // as an example, the parachain consensus client ismp_parachain::ParachainConsensusClient, ); - // Optional merkle mountain range overlay tree, for cheaper outgoing request proofs. - // You most likely don't need it, just use the `NoOpMmrTree` - type Mmr = NoOpMmrTree; + /// Offchain database implementation. Outgoing requests and responses are + /// inserted in this database, while their commitments are stored onchain. + type OffchainDB = TransparentOffchainDB; // Weight provider for local modules type WeightProvider = (); } diff --git a/modules/ismp/pallets/pallet/src/dispatcher.rs b/modules/ismp/pallets/pallet/src/dispatcher.rs index bc6541a3f..28929d17e 100644 --- a/modules/ismp/pallets/pallet/src/dispatcher.rs +++ b/modules/ismp/pallets/pallet/src/dispatcher.rs @@ -17,7 +17,7 @@ use crate::{ child_trie::{RequestCommitments, RequestReceipts, ResponseCommitments}, - mmr::LeafIndexAndPos, + offchain::LeafIndexAndPos, Config, Pallet, RELAYER_FEE_ACCOUNT, }; use alloc::{boxed::Box, format, vec::Vec}; @@ -94,7 +94,9 @@ where timeout_timestamp: if dispatch_get.timeout == 0 { 0 } else { - ::now().as_secs() + dispatch_get.timeout + ::now() + .as_secs() + .saturating_add(dispatch_get.timeout) }, }; Request::Get(get) diff --git a/modules/ismp/pallets/pallet/src/impls.rs b/modules/ismp/pallets/pallet/src/impls.rs index 62c4a88e8..282a36254 100644 --- a/modules/ismp/pallets/pallet/src/impls.rs +++ b/modules/ismp/pallets/pallet/src/impls.rs @@ -18,9 +18,9 @@ use crate::{ child_trie::{RequestCommitments, ResponseCommitments}, dispatcher::{FeeMetadata, RequestMetadata}, - mmr::{Leaf, LeafIndexAndPos, Proof, ProofKeys}, + offchain::{Leaf, LeafIndexAndPos, Proof, ProofKeys}, weights::get_weight, - Config, Error, Event, NoOpMmrTree, Pallet, Responded, + Config, Error, Event, Pallet, Responded, TransparentOffchainDB, }; use alloc::{string::ToString, vec, vec::Vec}; use codec::Decode; @@ -31,8 +31,7 @@ use ismp::{ messaging::{hash_request, hash_response, Message}, router::{Request, Response}, }; -use log::debug; -use mmr_primitives::{ForkIdentifier, MerkleMountainRangeTree}; +use mmr_primitives::{ForkIdentifier, OffchainDBProvider}; use sp_core::{offchain::StorageKind, H256}; impl Pallet { @@ -71,7 +70,7 @@ impl Pallet { }; let indices = leaf_indices_and_positions.iter().map(|val| val.leaf_index).collect::>(); - let (leaves, proof) = T::Mmr::generate_proof(indices)?; + let (leaves, proof) = T::OffchainDB::proof(indices)?; let proof = Proof { leaf_indices_and_pos: leaf_indices_and_positions, leaf_count: proof.leaf_count, @@ -81,8 +80,8 @@ impl Pallet { Ok((leaves, proof)) } - /// Provides a way to handle messages. - pub fn handle_messages(messages: Vec) -> DispatchResultWithPostInfo { + /// Execute the provided ISMP datagrams, this will short circuit if any messages are invalid. + pub fn execute(messages: Vec) -> DispatchResultWithPostInfo { // Define a host let host = Pallet::::default(); let events = messages @@ -108,7 +107,7 @@ impl Pallet { .collect::, _>>() }) .map_err(|err| { - debug!(target: "ismp", "Handling Error {:?}", err); + log::debug!(target: "ismp", "Handling Error {:?}", err); Pallet::::deposit_event(Event::::Errors { errors: vec![err.into()] }); Error::::InvalidMessage })?; @@ -134,7 +133,7 @@ impl Pallet { let (dest_chain, source_chain, nonce) = (request.dest_chain(), request.source_chain(), request.nonce()); - let leaf_index_and_pos = T::Mmr::push(Leaf::Request(request)); + let leaf_index_and_pos = T::OffchainDB::push(Leaf::Request(request)); // Deposit Event Pallet::::deposit_event(Event::Request { request_nonce: nonce, @@ -174,7 +173,7 @@ impl Pallet { let (dest_chain, source_chain, nonce) = (response.dest_chain(), response.source_chain(), response.nonce()); - let leaf_index_and_pos = T::Mmr::push(Leaf::Response(response)); + let leaf_index_and_pos = T::OffchainDB::push(Leaf::Response(response)); Pallet::::deposit_event(Event::Response { request_nonce: nonce, @@ -201,11 +200,11 @@ impl Pallet { /// Gets the request from the offchain storage pub fn request(commitment: H256) -> Option { let pos = RequestCommitments::::get(commitment)?.mmr.pos; - match T::Mmr::get_leaf(pos) { + match T::OffchainDB::leaf(pos) { Ok(Some(Leaf::Request(req))) => Some(req), _ => { - // Try getting the request from the offchain db using `NoOpMmrTree` - let offchain_key = NoOpMmrTree::::offchain_key(commitment); + // Try getting the request from the offchain db using `TransparentOffchainDB` + let offchain_key = TransparentOffchainDB::::offchain_key(commitment); let Some(elem) = sp_io::offchain::local_storage_get(StorageKind::PERSISTENT, &offchain_key) else { @@ -222,11 +221,11 @@ impl Pallet { /// Gets the response from the offchain storage pub fn response(commitment: H256) -> Option { let pos = ResponseCommitments::::get(commitment)?.mmr.pos; - match T::Mmr::get_leaf(pos) { + match T::OffchainDB::leaf(pos) { Ok(Some(Leaf::Response(res))) => Some(res), _ => { - // Try getting the response from the offchain db using the `NoOpMmrTree` - let offchain_key = NoOpMmrTree::::offchain_key(commitment); + // Try getting the response from the offchain db using the `TransparentOffchainDB` + let offchain_key = TransparentOffchainDB::::offchain_key(commitment); let Some(elem) = sp_io::offchain::local_storage_get(StorageKind::PERSISTENT, &offchain_key) else { diff --git a/modules/ismp/pallets/pallet/src/lib.rs b/modules/ismp/pallets/pallet/src/lib.rs index 7413245c8..c0fe708b2 100644 --- a/modules/ismp/pallets/pallet/src/lib.rs +++ b/modules/ismp/pallets/pallet/src/lib.rs @@ -181,23 +181,20 @@ pub mod errors; pub mod events; pub mod host; mod impls; -pub mod mmr; +pub mod offchain; mod utils; pub mod weights; -use crate::mmr::Leaf; -use mmr_primitives::{MerkleMountainRangeTree, NoOpTree}; +use crate::offchain::Leaf; +use mmr_primitives::{OffchainDBProvider, PlainOffChainDB}; // Re-export pallet items so that they can be accessed from the crate namespace. pub use pallet::*; -/// No-op mmr implementation for runtimes that don't want to build an offchain mmr tree. This -/// implementation does not panic for any runtime called methods, eg `push` or `finalize` -/// It will always return the default values for those methods. -/// -/// Additionally this implementation stores the requests and responses directly inside the offchain +/// The `TransparentOffchainDB` stores the requests and responses directly inside the offchain /// db using the commitment as the offchain key +/// /// *NOTE* it will return an error if you try to generate proofs. -pub type NoOpMmrTree = NoOpTree>; +pub type TransparentOffchainDB = PlainOffChainDB>; // Definition of the pallet logic, to be aggregated at runtime definition through // `construct_runtime`. @@ -308,11 +305,12 @@ pub mod pallet { /// their benchmarks. type WeightProvider: WeightProvider; - /// Merkle mountain range overlay tree implementation. Outgoing requests and responses are - /// inserted in this "overlay tree" to enable cheap proofs for messages. + /// Offchain database implementation. Outgoing requests and responses are + /// inserted in this database, while their commitments are stored onchain. /// - /// State machines that do not need this can simply use the `NoOpMmrTree` - type Mmr: MerkleMountainRangeTree; + /// This offchain DB is also allowed to "merkelize" and "generate proofs" for messages. + /// Most state machines will likey not need this can default to the `TransparentOffchainDB` + type OffchainDB: OffchainDBProvider; } // Simple declaration of the `Pallet` type. It is placeholder we use to implement traits and @@ -407,9 +405,9 @@ pub mod pallet { ); let child_trie_root = H256::from_slice(&child_trie_root); - ChildTrieRoot::::put::<::Hash>(child_trie_root.into()); + ChildTrieRoot::::put::(child_trie_root.into()); // Only finalize if mmr was modified - let root = match T::Mmr::finalize() { + let root = match T::OffchainDB::finalize() { Ok(root) => root, Err(e) => { log::error!(target:"ismp", "Failed to finalize MMR {e:?}"); @@ -446,7 +444,7 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { ensure_none(origin)?; - Self::handle_messages(messages) + Self::execute(messages) } /// Execute the provided batch of ISMP messages. This call will short-circuit and revert if @@ -464,7 +462,7 @@ pub mod pallet { pub fn handle(origin: OriginFor, messages: Vec) -> DispatchResultWithPostInfo { ensure_signed(origin)?; - Self::handle_messages(messages) + Self::execute(messages) } /// Create a consensus client, using a subjectively chosen consensus state. This can also diff --git a/modules/ismp/pallets/pallet/src/mmr.rs b/modules/ismp/pallets/pallet/src/offchain.rs similarity index 100% rename from modules/ismp/pallets/pallet/src/mmr.rs rename to modules/ismp/pallets/pallet/src/offchain.rs diff --git a/modules/ismp/pallets/rpc/src/lib.rs b/modules/ismp/pallets/rpc/src/lib.rs index 8a91f04cc..fd11e7ee2 100644 --- a/modules/ismp/pallets/rpc/src/lib.rs +++ b/modules/ismp/pallets/rpc/src/lib.rs @@ -75,7 +75,7 @@ use ismp::{ use jsonrpsee::types::ErrorObjectOwned; use pallet_ismp::{ child_trie::CHILD_TRIE_PREFIX, - mmr::{Leaf, LeafIndexQuery, ProofKeys}, + offchain::{Leaf, LeafIndexQuery, ProofKeys}, }; use pallet_ismp_runtime_api::IsmpRuntimeApi; use sc_client_api::{Backend, BlockBackend, ChildInfo, ProofProvider, StateBackend}; @@ -280,7 +280,7 @@ where .ok() .flatten() .ok_or_else(|| runtime_error_into_rpc_error("invalid block height provided"))?; - let (_, proof): (Vec, pallet_ismp::mmr::Proof) = api + let (_, proof): (Vec, pallet_ismp::offchain::Proof) = api .generate_proof(at, keys) .map_err(|_| runtime_error_into_rpc_error("Error calling runtime api"))? .map_err(|_| runtime_error_into_rpc_error("Error generating mmr proof"))?; diff --git a/modules/ismp/pallets/runtime-api/src/lib.rs b/modules/ismp/pallets/runtime-api/src/lib.rs index fdbd1ab5e..3e5520fce 100644 --- a/modules/ismp/pallets/runtime-api/src/lib.rs +++ b/modules/ismp/pallets/runtime-api/src/lib.rs @@ -26,7 +26,7 @@ use ismp::{ host::StateMachine, router::{Request, Response}, }; -use pallet_ismp::mmr::{Leaf, Proof, ProofKeys}; +use pallet_ismp::offchain::{Leaf, Proof, ProofKeys}; use primitive_types::H256; use sp_mmr_primitives::Error; diff --git a/modules/ismp/pallets/state-coprocessor/src/impls.rs b/modules/ismp/pallets/state-coprocessor/src/impls.rs index 590ee3636..09413a505 100644 --- a/modules/ismp/pallets/state-coprocessor/src/impls.rs +++ b/modules/ismp/pallets/state-coprocessor/src/impls.rs @@ -27,11 +27,11 @@ use ismp::{ router::{GetRequest, GetResponse, Request, RequestResponse, Response, StorageValue}, Error, }; -use mmr_primitives::MerkleMountainRangeTree; +use mmr_primitives::OffchainDBProvider; use pallet_ismp::{ child_trie::RequestCommitments, dispatcher::{FeeMetadata, RequestMetadata}, - mmr::{Leaf, LeafIndexAndPos}, + offchain::{Leaf, LeafIndexAndPos}, }; use sp_core::U256; diff --git a/modules/ismp/pallets/state-coprocessor/src/lib.rs b/modules/ismp/pallets/state-coprocessor/src/lib.rs index e22c08b16..ac847cf52 100644 --- a/modules/ismp/pallets/state-coprocessor/src/lib.rs +++ b/modules/ismp/pallets/state-coprocessor/src/lib.rs @@ -32,8 +32,8 @@ pub mod pallet { use frame_system::pallet_prelude::*; use impls::GetRequestsWithProof; use ismp::{host::IsmpHost, messaging::hash_request, router::Request}; - use mmr_primitives::MerkleMountainRangeTree; - use pallet_ismp::mmr::Leaf; + use mmr_primitives::OffchainDBProvider; + use pallet_ismp::offchain::Leaf; #[pallet::pallet] #[pallet::without_storage_info] pub struct Pallet(_); @@ -49,7 +49,7 @@ pub mod pallet { /// Merkle mountain range overlay tree implementation. /// /// Verified GetResponse(s) are stored in the mmr - type Mmr: MerkleMountainRangeTree; + type Mmr: OffchainDBProvider; } #[pallet::error] diff --git a/modules/ismp/pallets/testsuite/src/runtime.rs b/modules/ismp/pallets/testsuite/src/runtime.rs index 3d07dbbfa..906494a3e 100644 --- a/modules/ismp/pallets/testsuite/src/runtime.rs +++ b/modules/ismp/pallets/testsuite/src/runtime.rs @@ -38,7 +38,7 @@ use ismp::{ Error, }; use ismp_sync_committee::constants::sepolia::Sepolia; -use pallet_ismp::{mmr::Leaf, ModuleId}; +use pallet_ismp::{offchain::Leaf, ModuleId}; use pallet_token_gateway::CreateAssetId; use pallet_token_governor::GatewayParams; use sp_core::{ @@ -202,7 +202,7 @@ impl pallet_ismp::Config for Test { ismp_sync_committee::SyncCommitteeConsensusClient, ismp_bsc::BscClient, ); - type Mmr = Mmr; + type OffchainDB = Mmr; type WeightProvider = (); } diff --git a/modules/ismp/pallets/testsuite/src/tests/pallet_ismp.rs b/modules/ismp/pallets/testsuite/src/tests/pallet_ismp.rs index dfe34a767..b29f9f0f2 100644 --- a/modules/ismp/pallets/testsuite/src/tests/pallet_ismp.rs +++ b/modules/ismp/pallets/testsuite/src/tests/pallet_ismp.rs @@ -37,7 +37,7 @@ use ismp_testsuite::{ }; use pallet_ismp::{ child_trie::{RequestCommitments, RequestReceipts}, - mmr::Leaf, + offchain::Leaf, FundMessageParams, MessageCommitment, RELAYER_FEE_ACCOUNT, }; @@ -200,7 +200,7 @@ fn should_handle_get_request_timeouts_correctly() { let timeout_msg = TimeoutMessage::Get { requests: requests.clone() }; set_timestamp(Some(Duration::from_secs(100_000_000).as_millis() as u64)); - pallet_ismp::Pallet::::handle_messages(vec![Message::Timeout(timeout_msg)]).unwrap(); + pallet_ismp::Pallet::::execute(vec![Message::Timeout(timeout_msg)]).unwrap(); for request in requests { // commitments should not be found in storage after timeout has been processed let commitment = hash_request::(&request); @@ -271,7 +271,7 @@ fn should_handle_get_request_responses_correctly() { signer: vec![], }; - pallet_ismp::Pallet::::handle_messages(vec![Message::Response(response)]).unwrap(); + pallet_ismp::Pallet::::execute(vec![Message::Response(response)]).unwrap(); for request in requests { let Request::Get(get) = request else { panic!("Shouldn't be possible") }; diff --git a/modules/ismp/pallets/testsuite/src/tests/pallet_ismp_relayer.rs b/modules/ismp/pallets/testsuite/src/tests/pallet_ismp_relayer.rs index a2849a252..0f520bc3f 100644 --- a/modules/ismp/pallets/testsuite/src/tests/pallet_ismp_relayer.rs +++ b/modules/ismp/pallets/testsuite/src/tests/pallet_ismp_relayer.rs @@ -48,7 +48,7 @@ use crate::runtime::{ }; use ismp_bsc::BSC_CONSENSUS_ID; use ismp_sync_committee::BEACON_CONSENSUS_ID; -use pallet_ismp::{dispatcher::RequestMetadata, mmr::LeafIndexAndPos}; +use pallet_ismp::{dispatcher::RequestMetadata, offchain::LeafIndexAndPos}; #[test] fn test_withdrawal_proof() { diff --git a/modules/trees/mmr/gadget/src/lib.rs b/modules/trees/mmr/gadget/src/lib.rs index 5dd49c71f..11e816bb2 100644 --- a/modules/trees/mmr/gadget/src/lib.rs +++ b/modules/trees/mmr/gadget/src/lib.rs @@ -46,7 +46,7 @@ mod offchain_mmr; use crate::offchain_mmr::OffchainMmr; use futures::StreamExt; use log::{error, trace, warn}; -use pallet_ismp::mmr::Leaf; +use pallet_ismp::offchain::Leaf; use pallet_mmr_runtime_api::MmrRuntimeApi; use sc_client_api::{Backend, BlockchainEvents, FinalityNotification, FinalityNotifications}; use sc_offchain::OffchainDb; diff --git a/modules/trees/mmr/gadget/src/offchain_mmr.rs b/modules/trees/mmr/gadget/src/offchain_mmr.rs index 166600678..05882736e 100644 --- a/modules/trees/mmr/gadget/src/offchain_mmr.rs +++ b/modules/trees/mmr/gadget/src/offchain_mmr.rs @@ -23,7 +23,7 @@ use crate::{aux_schema, HashFor, MmrClient, LOG_TARGET}; use log::{debug, error, info, trace, warn}; -use pallet_ismp::mmr::Leaf; +use pallet_ismp::offchain::Leaf; use pallet_mmr_runtime_api::MmrRuntimeApi; use sc_client_api::{Backend, FinalityNotification}; use sc_offchain::OffchainDb; diff --git a/modules/trees/mmr/pallet/src/lib.rs b/modules/trees/mmr/pallet/src/lib.rs index 3dab2e1e1..794ec4a47 100644 --- a/modules/trees/mmr/pallet/src/lib.rs +++ b/modules/trees/mmr/pallet/src/lib.rs @@ -65,7 +65,7 @@ use sp_core::H256; use sp_runtime::traits::{self, One}; use sp_std::prelude::*; -use mmr_primitives::{DataOrHash, LeafMetadata, MerkleMountainRangeTree}; +use mmr_primitives::{DataOrHash, LeafMetadata, OffchainDBProvider}; pub use pallet::*; use sp_mmr_primitives::mmr_lib::leaf_index_to_pos; pub use sp_mmr_primitives::{ @@ -174,7 +174,7 @@ pub mod pallet { } } -impl MerkleMountainRangeTree for Pallet +impl OffchainDBProvider for Pallet where I: 'static, T: Config, @@ -182,11 +182,11 @@ where { type Leaf = T::Leaf; - fn leaf_count() -> LeafIndex { + fn count() -> LeafIndex { NumberOfLeaves::::get() } - fn generate_proof( + fn proof( indices: Vec, ) -> Result<(Vec, primitives::LeafProof), Error> { let (leaves, proof) = Pallet::::generate_proof(indices)?; @@ -252,7 +252,7 @@ where Ok(root.into()) } - fn get_leaf(pos: NodeIndex) -> Result, Error> { + fn leaf(pos: NodeIndex) -> Result, Error> { let store = Storage::::default(); store .get_elem(pos) @@ -266,30 +266,6 @@ where } } -/// Stateless MMR proof verification for batch of leaves. -/// -/// This function can be used to verify received MMR [primitives::Proof] (`proof`) -/// for given leaves set (`leaves`) against a known MMR root hash (`root`). -/// Note, the leaves should be sorted such that corresponding leaves and leaf indices have the -/// same position in both the `leaves` vector and the `leaf_indices` vector contained in the -/// [primitives::Proof]. -pub fn verify_leaves_proof( - root: H::Output, - leaves: Vec>, - proof: primitives::LeafProof, -) -> Result<(), primitives::Error> -where - H: traits::Hash, - L: mmr_primitives::FullLeaf, -{ - let is_valid = mmr::verify_leaves_proof::(root, leaves, proof)?; - if is_valid { - Ok(()) - } else { - Err(primitives::Error::Verify.log_debug(("The proof is incorrect.", root))) - } -} - impl, I: 'static> Pallet { /// Build offchain key from a combination of a fork resistant hash, position and indexing prefix /// @@ -333,31 +309,4 @@ impl, I: 'static> Pallet { let mmr: ModuleMmr = mmr::Mmr::new(leaves_count); mmr.generate_proof(indices) } - - /// Verify MMR proof for given `leaves`. - /// - /// This method is safe to use within the runtime code. - /// It will return `Ok(())` if the proof is valid - /// and an `Err(..)` if MMR is inconsistent (some leaves are missing) - /// or the proof is invalid. - pub fn verify_leaves( - leaves: Vec>, - proof: primitives::LeafProof>, - ) -> Result<(), primitives::Error> { - if proof.leaf_count > NumberOfLeaves::::get() || - proof.leaf_count == 0 || - (proof.items.len().saturating_add(leaves.len())) as u64 > proof.leaf_count - { - return Err(primitives::Error::Verify - .log_debug("The proof has incorrect number of leaves or proof items.")); - } - - let mmr: ModuleMmr = mmr::Mmr::new(proof.leaf_count); - let is_valid = mmr.verify_leaves_proof(leaves, proof)?; - if is_valid { - Ok(()) - } else { - Err(primitives::Error::Verify.log_debug("The proof is incorrect.")) - } - } } diff --git a/modules/trees/mmr/pallet/src/mmr/mmr.rs b/modules/trees/mmr/pallet/src/mmr/mmr.rs index 6f32c84cf..711849350 100644 --- a/modules/trees/mmr/pallet/src/mmr/mmr.rs +++ b/modules/trees/mmr/pallet/src/mmr/mmr.rs @@ -26,40 +26,6 @@ use crate::{ use sp_mmr_primitives::utils::NodesUtils; use sp_std::prelude::*; -/// Stateless verification of the proof for a batch of leaves. -/// Note, the leaves should be sorted such that corresponding leaves and leaf indices have the -/// same position in both the `leaves` vector and the `leaf_indices` vector contained in the -/// [primitives::Proof] -pub fn verify_leaves_proof( - root: H::Output, - leaves: Vec>, - proof: primitives::LeafProof, -) -> Result -where - H: sp_runtime::traits::Hash, - L: mmr_primitives::FullLeaf, -{ - let size = NodesUtils::new(proof.leaf_count).size(); - - if leaves.len() != proof.leaf_indices.len() { - return Err(Error::Verify.log_debug("Proof leaf_indices not same length with leaves")); - } - - let leaves_and_position_data = proof - .leaf_indices - .into_iter() - .map(|index| merkle_mountain_range::leaf_index_to_pos(index)) - .zip(leaves.into_iter()) - .collect(); - - let p = merkle_mountain_range::MerkleProof::, Hasher>::new( - size, - proof.items.into_iter().map(Node::Hash).collect(), - ); - p.verify(Node::Hash(root), leaves_and_position_data) - .map_err(|e| Error::Verify.log_debug(e)) -} - /// A wrapper around an MMR library to expose limited functionality. /// /// Available functions depend on the storage kind ([Runtime](crate::mmr::storage::RuntimeStorage) @@ -92,36 +58,6 @@ where Self { mmr: merkle_mountain_range::MMR::new(size, Default::default()), leaves } } - /// Verify proof for a set of leaves. - /// Note, the leaves should be sorted such that corresponding leaves and leaf indices have - /// the same position in both the `leaves` vector and the `leaf_indices` vector contained in the - /// [primitives::Proof] - pub fn verify_leaves_proof( - &self, - leaves: Vec, - proof: primitives::LeafProof>, - ) -> Result { - let p = - merkle_mountain_range::MerkleProof::, Hasher, L>>::new( - self.mmr.mmr_size(), - proof.items.into_iter().map(Node::Hash).collect(), - ); - - if leaves.len() != proof.leaf_indices.len() { - return Err(Error::Verify.log_debug("Proof leaf_indices not same length with leaves")); - } - - let leaves_positions_and_data = proof - .leaf_indices - .into_iter() - .map(|index| merkle_mountain_range::leaf_index_to_pos(index)) - .zip(leaves.into_iter().map(|leaf| Node::Data(leaf))) - .collect(); - let root = self.mmr.get_root().map_err(|e| Error::GetRoot.log_error(e))?; - p.verify(root, leaves_positions_and_data) - .map_err(|e| Error::Verify.log_debug(e)) - } - /// Return the internal size of the MMR (number of nodes). #[cfg(test)] pub fn size(&self) -> NodeIndex { diff --git a/modules/trees/mmr/pallet/src/mmr/mod.rs b/modules/trees/mmr/pallet/src/mmr/mod.rs index 033b471db..fd15eeeb4 100644 --- a/modules/trees/mmr/pallet/src/mmr/mod.rs +++ b/modules/trees/mmr/pallet/src/mmr/mod.rs @@ -21,7 +21,7 @@ pub mod storage; use mmr_primitives::{DataOrHash, FullLeaf}; use sp_runtime::traits; -pub use self::mmr::{verify_leaves_proof, Mmr}; +pub use self::mmr::Mmr; /// Node type for runtime `T`. pub type NodeOf = Node<>::Hashing, L>; diff --git a/modules/trees/mmr/pallet/src/mmr/storage.rs b/modules/trees/mmr/pallet/src/mmr/storage.rs index 8b5a48386..b3509f341 100644 --- a/modules/trees/mmr/pallet/src/mmr/storage.rs +++ b/modules/trees/mmr/pallet/src/mmr/storage.rs @@ -74,7 +74,7 @@ where // unless the MMR client gadget has a delay. let key = Pallet::::node_canon_offchain_key(pos); debug!( - target: "pallet-mmr::offchain", "offchain db get {}: canon key {:?}", + target: "pallet-mmr", "offchain db get {}: canon key {:?}", pos, key ); // Try to retrieve the element from Off-chain DB. diff --git a/modules/trees/mmr/primitives/src/lib.rs b/modules/trees/mmr/primitives/src/lib.rs index e9a443fa2..799338685 100644 --- a/modules/trees/mmr/primitives/src/lib.rs +++ b/modules/trees/mmr/primitives/src/lib.rs @@ -34,42 +34,39 @@ pub struct LeafMetadata { } /// Public interface for this pallet. Other runtime pallets will use this interface to insert leaves -/// into the tree. They can insert as many as they need and request the computed root hash at a -/// later time. This is so that the mmr root is only computed once per block. +/// into the offchain db. This allows for batch insertions and asychronous root hash computation +/// This is so that the root is only computed once per block. /// /// Internally, the pallet makes use of temporary storage item where it places leaves that have not /// yet been finalized. -pub trait MerkleMountainRangeTree { - /// Associated leaf type. +pub trait OffchainDBProvider { + /// Concrete leaf type used by the implementation. type Leaf; - /// Returns the total number of leaves that have been committed to the tree. - fn leaf_count() -> u64; + /// Returns the total number of leaves that have been persisted to the db. + fn count() -> u64; - /// Generate an MMR proof for the given `leaf_indices`. - /// Generates a proof for the MMR at the current block height. - fn generate_proof( - indices: Vec, - ) -> Result<(Vec, primitives::LeafProof), primitives::Error>; - - /// Push a new leaf into the MMR. Doesn't actually perform any expensive tree recomputation. - /// Simply adds the leaves to a buffer where they can be recalled when the tree actually - /// needs to be finalized. + /// Push a new leaf into the offchain db. fn push(leaf: Self::Leaf) -> LeafMetadata; - /// Finalize the tree and compute it's new root hash. Ideally this should only be called once a - /// block. This will pull the leaves from the buffer and commit them to the underlying tree. + /// Merkelize the offchain db and compute it's new root hash. This should only be called once a + /// block. This should pull the leaves from the buffer and commit them. fn finalize() -> Result; - /// Given the leaf position, it should return the leaf from the mmr store - fn get_leaf(pos: NodeIndex) -> Result, primitives::Error>; + /// Given the leaf position, return the leaf from the offchain db + fn leaf(pos: NodeIndex) -> Result, primitives::Error>; + + /// Generate a proof for the given leaf indices. The implementation should provide + /// a proof for the leaves at the current block height. + fn proof( + indices: Vec, + ) -> Result<(Vec, primitives::LeafProof), primitives::Error>; } -/// NoOp tree can be used as a drop in replacement for when the underlying mmr tree is unneeded. -/// This will store leaves directly in the offchain db using the leaf commitment as the key -pub struct NoOpTree(PhantomData<(T, H)>); +/// The `PlainOffChainDB` simply persists requests and responses directly to the offchain-db. +pub struct PlainOffChainDB(PhantomData<(T, H)>); -impl NoOpTree { +impl PlainOffChainDB { /// Offchain key for storing requests using the commitment as identifiers pub fn offchain_key(commitment: H256) -> Vec { let prefix = b"no_op"; @@ -77,14 +74,14 @@ impl NoOpTree { } } -impl MerkleMountainRangeTree for NoOpTree { +impl OffchainDBProvider for PlainOffChainDB { type Leaf = T; - fn leaf_count() -> u64 { + fn count() -> u64 { 0 } - fn generate_proof( + fn proof( _indices: Vec, ) -> Result<(Vec, primitives::LeafProof), primitives::Error> { Err(primitives::Error::GenerateProof)? @@ -102,7 +99,7 @@ impl MerkleMountainRangeTree for NoO Ok(H256::default()) } - fn get_leaf(_pos: NodeIndex) -> Result, primitives::Error> { + fn leaf(_pos: NodeIndex) -> Result, primitives::Error> { Ok(None) } } diff --git a/parachain/node/src/runtime_api.rs b/parachain/node/src/runtime_api.rs index 443e138fa..39b09b649 100644 --- a/parachain/node/src/runtime_api.rs +++ b/parachain/node/src/runtime_api.rs @@ -86,7 +86,7 @@ pub trait BaseHostRuntimeApis: opaque::Block, H256, opaque::BlockNumber, - pallet_ismp::mmr::Leaf, + pallet_ismp::offchain::Leaf, > + simnode_runtime_api::CreateTransactionApi< opaque::Block, gargantua_runtime::RuntimeCall, @@ -113,7 +113,7 @@ impl BaseHostRuntimeApis for Api where opaque::Block, H256, opaque::BlockNumber, - pallet_ismp::mmr::Leaf, + pallet_ismp::offchain::Leaf, > + simnode_runtime_api::CreateTransactionApi< opaque::Block, gargantua_runtime::RuntimeCall, diff --git a/parachain/runtimes/gargantua/src/ismp.rs b/parachain/runtimes/gargantua/src/ismp.rs index 589cb19d2..2d84441e3 100644 --- a/parachain/runtimes/gargantua/src/ismp.rs +++ b/parachain/runtimes/gargantua/src/ismp.rs @@ -102,7 +102,7 @@ impl pallet_ismp::Config for Runtime { >, ismp_grandpa::consensus::GrandpaConsensusClient, ); - type Mmr = Mmr; + type OffchainDB = Mmr; type WeightProvider = (); } diff --git a/parachain/runtimes/gargantua/src/lib.rs b/parachain/runtimes/gargantua/src/lib.rs index 1b315f89f..b32467853 100644 --- a/parachain/runtimes/gargantua/src/lib.rs +++ b/parachain/runtimes/gargantua/src/lib.rs @@ -71,7 +71,7 @@ use frame_system::{ EnsureRoot, EnsureRootWithSuccess, }; -use pallet_ismp::mmr::Proof; +use pallet_ismp::offchain::Proof; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_mmr_primitives::{LeafIndex, INDEXING_PREFIX}; pub use sp_runtime::{MultiAddress, Perbill, Permill}; @@ -102,7 +102,7 @@ use pallet_collective::PrimeDefaultVote; #[cfg(feature = "runtime-benchmarks")] use pallet_treasury::ArgumentsFactory; -use pallet_ismp::mmr::{Leaf, ProofKeys}; +use pallet_ismp::offchain::{Leaf, ProofKeys}; use sp_core::{crypto::AccountId32, Get}; use sp_runtime::traits::IdentityLookup; diff --git a/parachain/runtimes/messier/src/lib.rs b/parachain/runtimes/messier/src/lib.rs index 531e13a85..8089178ec 100644 --- a/parachain/runtimes/messier/src/lib.rs +++ b/parachain/runtimes/messier/src/lib.rs @@ -49,10 +49,6 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use ::ismp::{ - consensus::{ConsensusClientId, StateMachineHeight, StateMachineId}, - router::{Request, Response}, -}; use frame_support::{ construct_runtime, dispatch::DispatchClass, @@ -69,7 +65,11 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureRootWithSuccess, }; -use pallet_ismp::mmr::{Proof, ProofKeys}; +use ismp::{ + consensus::{ConsensusClientId, StateMachineHeight, StateMachineId}, + router::{Request, Response}, +}; +use pallet_ismp::offchain::{Proof, ProofKeys}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_mmr_primitives::{LeafIndex, INDEXING_PREFIX}; pub use sp_runtime::{MultiAddress, Perbill, Permill}; @@ -84,10 +84,10 @@ use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; // XCM Imports -use ::staging_xcm::latest::prelude::BodyId; use cumulus_primitives_core::ParaId; use frame_support::traits::ConstBool; use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; +use staging_xcm::latest::prelude::BodyId; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. pub type Signature = MultiSignature; @@ -305,12 +305,12 @@ parameter_types! { // Configure FRAME pallets to include in runtime. -use ::ismp::host::StateMachine; use frame_support::{derive_impl, traits::tokens::pay::PayAssetFromAccount}; +use ismp::host::StateMachine; #[cfg(feature = "runtime-benchmarks")] use pallet_asset_rate::AssetKindFactory; use pallet_collective::PrimeDefaultVote; -use pallet_ismp::mmr::Leaf; +use pallet_ismp::offchain::Leaf; #[cfg(feature = "runtime-benchmarks")] use pallet_treasury::ArgumentsFactory; use sp_core::crypto::AccountId32; diff --git a/parachain/runtimes/nexus/src/ismp.rs b/parachain/runtimes/nexus/src/ismp.rs index 88f0389a8..e3624f23f 100644 --- a/parachain/runtimes/nexus/src/ismp.rs +++ b/parachain/runtimes/nexus/src/ismp.rs @@ -104,7 +104,7 @@ impl pallet_ismp::Config for Runtime { >, ismp_grandpa::consensus::GrandpaConsensusClient, ); - type Mmr = Mmr; + type OffchainDB = Mmr; type WeightProvider = (); } diff --git a/parachain/runtimes/nexus/src/lib.rs b/parachain/runtimes/nexus/src/lib.rs index c999c3100..ded7ee6c8 100644 --- a/parachain/runtimes/nexus/src/lib.rs +++ b/parachain/runtimes/nexus/src/lib.rs @@ -74,7 +74,7 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureRootWithSuccess, }; -use pallet_ismp::mmr::{Proof, ProofKeys}; +use pallet_ismp::offchain::{Proof, ProofKeys}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_mmr_primitives::{LeafIndex, INDEXING_PREFIX}; pub use sp_runtime::{MultiAddress, Perbill, Permill}; @@ -316,7 +316,7 @@ use frame_support::{ traits::{tokens::pay::PayAssetFromAccount, Contains}, }; use pallet_collective::PrimeDefaultVote; -use pallet_ismp::mmr::Leaf; +use pallet_ismp::offchain::Leaf; #[cfg(feature = "runtime-benchmarks")] use pallet_treasury::ArgumentsFactory; use sp_core::crypto::AccountId32; diff --git a/parachain/simtests/src/pallet_mmr.rs b/parachain/simtests/src/pallet_mmr.rs index c22a24b94..ea36ce5ce 100644 --- a/parachain/simtests/src/pallet_mmr.rs +++ b/parachain/simtests/src/pallet_mmr.rs @@ -13,7 +13,7 @@ use subxt::{rpc_params, tx::SubmittableExtrinsic, utils::H160}; use merkle_mountain_range::util::MemMMR; use mmr_primitives::{DataOrHash, FullLeaf}; -use pallet_ismp::mmr::{Leaf, ProofKeys}; +use pallet_ismp::offchain::{Leaf, ProofKeys}; use pallet_mmr::mmr::Hasher as MmrHasher; use subxt_utils::{ gargantua, gargantua::api::runtime_types::pallet_ismp_demo::pallet::EvmParams, Hyperbridge, @@ -405,7 +405,7 @@ async fn dispatch_requests() -> Result<(), anyhow::Error> { let params = rpc_params![at, keys]; let response: pallet_ismp_rpc::Proof = client.rpc().request("ismp_queryMmrProof", params).await?; - let proof: pallet_ismp::mmr::Proof = Decode::decode(&mut &*response.proof)?; + let proof: pallet_ismp::offchain::Proof = Decode::decode(&mut &*response.proof)?; let merkle_proof = MerkleProof::, MmrHasher>::new( mmr.mmr_size(), diff --git a/tesseract/evm/src/tx.rs b/tesseract/evm/src/tx.rs index 331202853..76f76a983 100644 --- a/tesseract/evm/src/tx.rs +++ b/tesseract/evm/src/tx.rs @@ -30,7 +30,7 @@ use ismp_solidity_abi::{ }, }; use mmr_primitives::mmr_position_to_k_index; -use pallet_ismp::mmr::{LeafIndexAndPos, Proof as MmrProof}; +use pallet_ismp::offchain::{LeafIndexAndPos, Proof as MmrProof}; use primitive_types::{H256, U256}; use sp_mmr_primitives::utils::NodesUtils; use std::{collections::BTreeSet, sync::Arc, time::Duration}; diff --git a/tesseract/relayer/src/fees.rs b/tesseract/relayer/src/fees.rs index c458a3f9f..6b3864c9e 100644 --- a/tesseract/relayer/src/fees.rs +++ b/tesseract/relayer/src/fees.rs @@ -479,7 +479,7 @@ mod tests { router::Request, }; use itertools::Itertools; - use pallet_ismp::mmr::LeafIndexQuery; + use pallet_ismp::offchain::LeafIndexQuery; use pallet_ismp_host_executive::HostParam; use sp_core::H160; use subxt::rpc_params; diff --git a/tesseract/substrate/src/calls.rs b/tesseract/substrate/src/calls.rs index 5a8b3afe2..b7dc6af9e 100644 --- a/tesseract/substrate/src/calls.rs +++ b/tesseract/substrate/src/calls.rs @@ -11,7 +11,7 @@ use ismp::{ host::StateMachine, messaging::CreateConsensusState, }; -use pallet_ismp::{child_trie::CHILD_TRIE_PREFIX, mmr::LeafIndexAndPos}; +use pallet_ismp::{child_trie::CHILD_TRIE_PREFIX, offchain::LeafIndexAndPos}; use pallet_ismp_host_executive::HostParam; use pallet_ismp_relayer::{ message, diff --git a/tesseract/substrate/src/provider.rs b/tesseract/substrate/src/provider.rs index 7da7878ea..857324a1a 100644 --- a/tesseract/substrate/src/provider.rs +++ b/tesseract/substrate/src/provider.rs @@ -32,7 +32,7 @@ use pallet_ismp::{ child_trie::{ request_commitment_storage_key, response_commitment_storage_key, CHILD_TRIE_PREFIX, }, - mmr::ProofKeys, + offchain::ProofKeys, }; use pallet_ismp_host_executive::HostParam; use pallet_ismp_relayer::withdrawal::Signature; From 8771b5c4a2886d140f4b1ab8f922b2b14527faee Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Sun, 8 Dec 2024 12:53:52 +0000 Subject: [PATCH 03/11] refurbish code --- modules/ismp/core/src/handlers/request.rs | 17 +++++----- modules/ismp/core/src/handlers/response.rs | 20 ++++++----- modules/ismp/core/src/handlers/timeout.rs | 33 +++++++++++-------- modules/ismp/pallets/pallet/src/lib.rs | 6 ++-- .../ismp/state-machines/substrate/src/lib.rs | 3 +- 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/modules/ismp/core/src/handlers/request.rs b/modules/ismp/core/src/handlers/request.rs index 58b1b5388..ff05de7e9 100644 --- a/modules/ismp/core/src/handlers/request.rs +++ b/modules/ismp/core/src/handlers/request.rs @@ -59,19 +59,20 @@ where Err(Error::InvalidRequestDestination { meta: req.clone().into() })? } - // check if the source chain does not match the proof metadata in which case - // the proof metadata must be the configured proxy - // and we must not have a configured state machine client for the destination - if req.source_chain() != msg.proof.height.id.state_id && - !(host.is_allowed_proxy(&msg.proof.height.id.state_id) && - check_state_machine_client(req.source_chain())) - { + let source_chain = req.source_chain(); + + // in order to allow proxies, the host must configure the given state machine + // as it's proxy and must not have a state machine client for the source chain + let allow_proxy = host.is_allowed_proxy(&msg.proof.height.id.state_id) && + check_state_machine_client(source_chain); + + // check if the request is allowed to be proxied + if source_chain != msg.proof.height.id.state_id && !allow_proxy { Err(Error::RequestProxyProhibited { meta: req.clone().into() })? } } // Verify membership proof - let state = host.state_machine_commitment(msg.proof.height)?; state_machine.verify_membership( host, diff --git a/modules/ismp/core/src/handlers/response.rs b/modules/ismp/core/src/handlers/response.rs index a59e593ba..e53d82397 100644 --- a/modules/ismp/core/src/handlers/response.rs +++ b/modules/ismp/core/src/handlers/response.rs @@ -62,13 +62,15 @@ where Err(Error::ResponseTimeout { response: response.into() })? } - // check if the source chain does not match the proof metadata in which case - // the proof metadata must be the configured proxy - // and we must not have a configured state machine client for the destination - if response.source_chain() != msg.proof.height.id.state_id && - !(host.is_allowed_proxy(&msg.proof.height.id.state_id) && - check_state_machine_client(response.source_chain())) - { + let source_chain = response.source_chain(); + + // in order to allow proxies, the host must configure the given state machine + // as it's proxy and must not have a state machine client for the source chain + let allow_proxy = host.is_allowed_proxy(&msg.proof.height.id.state_id) && + check_state_machine_client(source_chain); + + // check if the response is allowed to be proxied + if response.source_chain() != msg.proof.height.id.state_id && !allow_proxy { Err(Error::ResponseProxyProhibited { meta: response.into() })? } } @@ -140,8 +142,8 @@ where Err(Error::InsufficientProofHeight)? } - // Since each get request can contain multiple storage keys, we should handle them - // individually + // Since each get request can contain multiple storage keys + // we should handle them individually get_requests .into_iter() .map(|request| { diff --git a/modules/ismp/core/src/handlers/timeout.rs b/modules/ismp/core/src/handlers/timeout.rs index 1d2483ca2..a68943fdb 100644 --- a/modules/ismp/core/src/handlers/timeout.rs +++ b/modules/ismp/core/src/handlers/timeout.rs @@ -45,13 +45,15 @@ where let state = host.state_machine_commitment(timeout_proof.height)?; for request in &requests { - // check if the destination chain does not match the proof metadata in which case - // the proof metadata must be the configured proxy - // and we must not have a configured state machine client for the destination - if request.dest_chain() != timeout_proof.height.id.state_id && - !(host.is_allowed_proxy(&timeout_proof.height.id.state_id) && - check_state_machine_client(request.dest_chain())) - { + let dest_chain = request.dest_chain(); + + // in order to allow proxies, the host must configure the given state machine + // as it's proxy and must not have a state machine client for the source chain + let allow_proxy = host.is_allowed_proxy(&timeout_proof.height.id.state_id) && + check_state_machine_client(dest_chain); + + // check if the timeout is allowed to be proxied + if dest_chain != timeout_proof.height.id.state_id && !allow_proxy { Err(Error::RequestProxyProhibited { meta: request.into() })? } @@ -112,17 +114,20 @@ where let state_machine = validate_state_machine(host, timeout_proof.height)?; let state = host.state_machine_commitment(timeout_proof.height)?; for response in &responses { - // check if the destination chain does not match the proof metadata in which case - // the proof metadata must be the configured proxy - // and we must not have a configured state machine client for the destination - if response.dest_chain() != timeout_proof.height.id.state_id && - !(host.is_allowed_proxy(&timeout_proof.height.id.state_id) && - check_state_machine_client(response.dest_chain())) - { + let dest_chain = response.dest_chain(); + + // in order to allow proxies, the host must configure the given state machine + // as it's proxy and must not have a state machine client for the source chain + let allow_proxy = host.is_allowed_proxy(&timeout_proof.height.id.state_id) && + check_state_machine_client(dest_chain); + + // check if the response is allowed to be proxied + if dest_chain != timeout_proof.height.id.state_id && !allow_proxy { Err(Error::ResponseProxyProhibited { meta: Response::Post(response.clone()).into(), })? } + // Ensure a commitment exists for all responses in the batch let commitment = hash_post_response::(response); if host.response_commitment(commitment).is_err() { diff --git a/modules/ismp/pallets/pallet/src/lib.rs b/modules/ismp/pallets/pallet/src/lib.rs index c0fe708b2..21a67b650 100644 --- a/modules/ismp/pallets/pallet/src/lib.rs +++ b/modules/ismp/pallets/pallet/src/lib.rs @@ -118,9 +118,9 @@ //! // as an example, the parachain consensus client //! ismp_parachain::ParachainConsensusClient, //! ); -//! // Optional merkle mountain range overlay tree, for cheaper outgoing request proofs. -//! // You most likely don't need it, just use the `NoOpMmrTree` -//! type Mmr = NoOpMmrTree; +//! // Offchain database implementation. Outgoing requests and responses are +//! // inserted in this database, while their commitments are stored onchain. +//! type OffchainDB = TransparentOffchainDB; //! // Weight provider for local modules //! type WeightProvider = (); //! } diff --git a/modules/ismp/state-machines/substrate/src/lib.rs b/modules/ismp/state-machines/substrate/src/lib.rs index 7bbb3a237..41a4a6544 100644 --- a/modules/ismp/state-machines/substrate/src/lib.rs +++ b/modules/ismp/state-machines/substrate/src/lib.rs @@ -126,8 +126,7 @@ where ); let root = match T::Coprocessor::get() { - Some(id) if id == proof.height.id.state_id => state.state_root, /* child root on */ - // hyperbridge + Some(id) if id == proof.height.id.state_id => state.state_root, _ => state.overlay_root.ok_or_else(|| { Error::Custom( "Child trie root is not available for provided state commitment".into(), From ff4b87055aba5efd4c365e4204801b80613a87a9 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Sun, 8 Dec 2024 14:52:51 +0000 Subject: [PATCH 04/11] refurbish dependencies --- Cargo.lock | 30 +++++++++---------- Cargo.toml | 13 ++++---- modules/consensus/beefy/primitives/Cargo.toml | 6 ++-- modules/consensus/beefy/prover/Cargo.toml | 7 ++--- modules/consensus/bsc/verifier/Cargo.toml | 19 ++++++------ .../consensus/bsc/verifier/src/primitives.rs | 2 +- .../grandpa/primitives/src/justification.rs | 9 ++++-- modules/consensus/grandpa/prover/Cargo.toml | 15 ++++------ .../consensus/polygon-pos/verifier/Cargo.toml | 2 +- .../sync-committee/primitives/Cargo.toml | 20 ++++++------- .../sync-committee/prover/Cargo.toml | 29 ++++++++---------- .../sync-committee/prover/src/test.rs | 2 +- .../sync-committee/verifier/Cargo.toml | 8 ++--- modules/hyperclient/Cargo.toml | 8 ++--- modules/ismp/clients/arbitrum/Cargo.toml | 10 +++---- modules/ismp/clients/bsc/Cargo.toml | 4 +-- modules/ismp/clients/optimism/Cargo.toml | 6 ++-- .../ismp/clients/parachain/client/Cargo.toml | 2 +- .../clients/parachain/inherent/Cargo.toml | 2 +- .../ismp/clients/sync-committee/Cargo.toml | 8 ++--- .../sync-committee/evm-common/Cargo.toml | 10 +++---- modules/ismp/core/Cargo.toml | 6 ++-- .../ismp/pallets/call-decompressor/Cargo.toml | 2 +- modules/ismp/pallets/pallet/Cargo.toml | 2 +- modules/ismp/pallets/relayer/Cargo.toml | 9 ++---- modules/ismp/pallets/relayer/src/lib.rs | 3 +- .../ismp/pallets/relayer/src/withdrawal.rs | 2 +- modules/ismp/pallets/rpc/Cargo.toml | 12 ++++---- modules/ismp/pallets/rpc/src/lib.rs | 2 +- modules/ismp/pallets/runtime-api/Cargo.toml | 2 +- modules/trees/ethereum/Cargo.toml | 20 ++++++++----- modules/trees/ethereum/src/node_codec.rs | 11 +++++-- modules/trees/mmr/pallet/Cargo.toml | 4 +-- .../trees/mmr/pallet/runtime-api/Cargo.toml | 14 ++++++--- modules/trees/mmr/pallet/src/lib.rs | 2 ++ modules/trees/mmr/pallet/src/mmr/storage.rs | 3 +- modules/trees/mmr/primitives/Cargo.toml | 2 +- modules/utils/serde/Cargo.toml | 2 +- modules/utils/subxt/Cargo.toml | 4 +-- parachain/node/Cargo.toml | 15 +++++----- parachain/node/src/chain_spec.rs | 4 +-- parachain/runtimes/gargantua/Cargo.toml | 8 ++--- parachain/runtimes/nexus/Cargo.toml | 10 +++---- tesseract/evm/Cargo.toml | 2 +- tesseract/integration-test/src/lib.rs | 4 +-- 45 files changed, 177 insertions(+), 180 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b61bb213d..49ce2c03c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "Inflector" @@ -360,7 +360,7 @@ dependencies = [ "evm-common", "geth-primitives", "hex", - "hex-literal 0.3.4", + "hex-literal 0.4.1", "ismp", "ismp-testsuite", "parity-scale-codec", @@ -1239,7 +1239,7 @@ version = "0.1.1" dependencies = [ "anyhow", "beefy-verifier-primitives", - "derive_more 0.99.18", + "derive_more 1.0.0", "frame-support 37.0.0", "hex", "hex-literal 0.4.1", @@ -1248,7 +1248,6 @@ dependencies = [ "parity-scale-codec", "primitive-types", "rs_merkle", - "serde_json", "sp-consensus-beefy", "sp-io 38.0.0", "sp-mmr-primitives", @@ -1262,7 +1261,7 @@ dependencies = [ name = "beefy-verifier-primitives" version = "0.1.1" dependencies = [ - "derive_more 0.99.18", + "derive_more 1.0.0", "parity-scale-codec", "serde", "sp-consensus-beefy", @@ -1666,11 +1665,11 @@ dependencies = [ "ark-bls12-381", "ark-ec", "bls_on_arkworks", - "ethabi", "geth-primitives", "ismp", "log", "parity-scale-codec", + "primitive-types", "sp-core 34.0.0", "sp-runtime 39.0.0", "ssz-rs", @@ -4485,6 +4484,8 @@ dependencies = [ name = "ethereum-triedb" version = "0.1.1" dependencies = [ + "anyhow", + "derive_more 1.0.0", "hash-db", "hash256-std-hasher", "hex", @@ -4494,6 +4495,7 @@ dependencies = [ "primitive-types", "rlp", "rlp-derive", + "thiserror 2.0.3", "tiny-keccak", "trie-db 0.29.1", ] @@ -4820,7 +4822,7 @@ dependencies = [ "hash-db", "hash256-std-hasher", "hex", - "hex-literal 0.3.4", + "hex-literal 0.4.1", "ismp", "pallet-ismp-host-executive", "parity-scale-codec", @@ -6593,15 +6595,13 @@ name = "grandpa-prover" version = "0.1.0" dependencies = [ "anyhow", - "derive_more 0.99.18", + "derive_more 1.0.0", "downcast-rs", "finality-grandpa", "grandpa-verifier-primitives", "hex", "hex-literal 0.4.1", "ismp", - "jsonrpsee 0.23.2", - "jsonrpsee-ws-client 0.23.2", "parity-scale-codec", "sc-consensus-grandpa-rpc", "serde", @@ -7705,7 +7705,6 @@ dependencies = [ "scale-info", "serde", "serde-hex-utils", - "serde_json", "thiserror 2.0.3", ] @@ -7876,7 +7875,7 @@ dependencies = [ "frame-system", "geth-primitives", "hex", - "hex-literal 0.3.4", + "hex-literal 0.4.1", "ismp", "op-verifier", "pallet-ismp", @@ -11388,7 +11387,7 @@ dependencies = [ "evm-common", "geth-primitives", "hex", - "hex-literal 0.3.4", + "hex-literal 0.4.1", "ismp", "parity-scale-codec", ] @@ -12305,7 +12304,6 @@ dependencies = [ "sp-core 34.0.0", "sp-io 38.0.0", "sp-runtime 39.0.0", - "sp-std 14.0.0", "sp-trie 37.0.0", "substrate-state-machine", "trie-db 0.29.1", @@ -12319,7 +12317,7 @@ dependencies = [ "frame-system", "hash-db", "hex", - "hex-literal 0.3.4", + "hex-literal 0.4.1", "ismp", "jsonrpsee 0.23.2", "pallet-ismp", @@ -16840,7 +16838,7 @@ dependencies = [ [[package]] name = "rs_merkle" version = "1.2.0" -source = "git+https://github.com/polytope-labs/rs-merkle?branch=seun/2d-merkle-proofs#02750ca0b3a93dc9b53c826b58692b3c1cf7e2a7" +source = "git+https://github.com/polytope-labs/rs-merkle?branch=seun%2F2d-merkle-proofs#02750ca0b3a93dc9b53c826b58692b3c1cf7e2a7" dependencies = [ "micromath", "sha2 0.10.8", diff --git a/Cargo.toml b/Cargo.toml index 1f65fe1b1..eb37a2604 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -236,19 +236,23 @@ serde = { version = "1", default-features = false } trie-db = { version = "0.29.0", default-features = false } hash-db = { version = "0.16.0", default-features = false } memory-db = { version = "0.32.0", default-features = false } -codec = { version = "3.1.3", package = "parity-scale-codec", default-features = false } -log = { version = "0.4.21", default-features = false } -anyhow = { version = "1.0.93", default-features = false } +codec = { version = "3.6", package = "parity-scale-codec", default-features = false } +log = { version = "0.4", default-features = false } +anyhow = { version = "1.0", default-features = false } derive_more = { version = "1.0", default-features = false } thiserror = { version = "2", default-features = false } alloy-rlp = { version = "0.3.7", default-features = false } alloy-rlp-derive = "0.3.7" alloy-sol-macro = "0.7.7" alloy-sol-types = { version = "0.7.7", default-features = false } +json = { package = "serde_json", version = "1.0.99", default-features = false } +hex = { version = "0.4.3", default-features = false } +hex-literal = "0.4.1" +rlp = { version = "0.5.1", default-features = false } orml-xcm-support = { version = "=1.0.0", default-features = false } orml-traits = { version = "=1.0.0", default-features = false } -primitive-types = { version = "0.12.1", default-features = false } +primitive-types = { version = "0.12.2", default-features = false } sc-simnode = { version = "1.15.0" } simnode-runtime-api = { version = "1.15.0", default-features = false } subxt = { version = "0.30.1", default-features = false } @@ -320,7 +324,6 @@ mmr-primitives = { version = "1.15.1", path = "modules/trees/mmr/primitives", de # runtimes gargantua-runtime = { path = "./parachain/runtimes/gargantua", default-features = false } -#messier-runtime = { path = "./parachain/runtimes/messier", default-features = false } nexus-runtime = { path = "./parachain/runtimes/nexus", default-features = false } # tesseract diff --git a/modules/consensus/beefy/primitives/Cargo.toml b/modules/consensus/beefy/primitives/Cargo.toml index c7deabee7..0738238f1 100644 --- a/modules/consensus/beefy/primitives/Cargo.toml +++ b/modules/consensus/beefy/primitives/Cargo.toml @@ -11,9 +11,9 @@ publish = false targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -derive_more = { version = "0.99.17", default-features = false, features = ["from"] } -serde = { version = "1.0.144", features = ["derive"], optional = true } +codec = { workspace = true, features = ["derive"] } +derive_more = { workspace = true, features = ["from"] } +serde = { workspace = true, features = ["derive"], optional = true } sp-std = { workspace = true } sp-core = { workspace = true} diff --git a/modules/consensus/beefy/prover/Cargo.toml b/modules/consensus/beefy/prover/Cargo.toml index 8b579e85f..9746a8d70 100644 --- a/modules/consensus/beefy/prover/Cargo.toml +++ b/modules/consensus/beefy/prover/Cargo.toml @@ -13,8 +13,8 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] anyhow.workspace = true primitive-types = { workspace = true, features = ["codec"] } -codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] } -derive_more = { version = "0.99.17", features = ["from"] } +codec = { workspace = true, features = ["derive"], default-features = true } +derive_more = { workspace = true, features = ["from"], default-features = true } rs_merkle = { git = "https://github.com/polytope-labs/rs-merkle", branch = "seun/2d-merkle-proofs" } hex-literal = "0.4.1" @@ -31,10 +31,9 @@ mmr-rpc = { workspace = true } # Optional deps subxt = { workspace = true, features = ["substrate-compat"], default-features = true } -serde_json = { version = "1.0.74" } hex = { version = "0.4.3" } beefy-verifier-primitives = { path = "../primitives" } [features] -local = [] \ No newline at end of file +local = [] diff --git a/modules/consensus/bsc/verifier/Cargo.toml b/modules/consensus/bsc/verifier/Cargo.toml index 3e42756d5..e7d4246f0 100644 --- a/modules/consensus/bsc/verifier/Cargo.toml +++ b/modules/consensus/bsc/verifier/Cargo.toml @@ -8,23 +8,23 @@ publish = false [dependencies] -log = { version = "0.4.17", default-features = false } +log = { workspace = true } anyhow = { workspace = true, default-features = false } -sp-core = {workspace = true, default-features = false } +sp-core = { workspace = true, default-features = false } alloy-rlp = { workspace = true } alloy-primitives = { workspace = true } alloy-rlp-derive = { workspace = true } -codec = { package = "parity-scale-codec", version = "3.1.3", default-features = false } -ethabi = { version = "18.0.0", features = ["rlp", "parity-codec"], default-features = false } -ismp = { path = "../../../ismp/core", default-features = false } -geth-primitives = { path = "../../geth-primitives", default-features = false } -sync-committee-verifier = { path = "../../sync-committee/verifier", default-features = false } -sync-committee-primitives = { path = "../../sync-committee/primitives", default-features = false } +primitive-types = { workspace = true } +codec = { workspace = true } +ismp = { workspace = true, default-features = false } +geth-primitives = { workspace = true, default-features = false } +sync-committee-verifier = { workspace = true, default-features = false } +sync-committee-primitives = { workspace = true, default-features = false } ark-bls12-381 = { version = "0.4.0", default-features = false, features = ["curve"] } bls = { package = "bls_on_arkworks", version = "0.2.2", default-features = false } ark-ec = { version = "0.4.2", default-features = false } ssz-rs = { git = "https://github.com/polytope-labs/ssz-rs", branch = "main", default-features = false } -sp-runtime.workspace = true +sp-runtime = { workspace = true } [features] default = ["std"] @@ -36,7 +36,6 @@ std = [ "ismp/std", "alloy-primitives/std", "alloy-rlp/std", - "ethabi/std", "ark-bls12-381/std", "bls/std", "sync-committee-verifier/std", diff --git a/modules/consensus/bsc/verifier/src/primitives.rs b/modules/consensus/bsc/verifier/src/primitives.rs index ce1bd43c2..1eab2d920 100644 --- a/modules/consensus/bsc/verifier/src/primitives.rs +++ b/modules/consensus/bsc/verifier/src/primitives.rs @@ -4,9 +4,9 @@ use alloy_rlp::Decodable; use alloy_rlp_derive::{RlpDecodable, RlpEncodable}; use anyhow::anyhow; use codec::{Decode, Encode}; -use ethabi::ethereum_types::H160; use geth_primitives::CodecHeader; use ismp::messaging::Keccak256; +use primitive_types::H160; use sp_runtime::traits::ConstU32; pub const EPOCH_LENGTH: u64 = 200; diff --git a/modules/consensus/grandpa/primitives/src/justification.rs b/modules/consensus/grandpa/primitives/src/justification.rs index 12b3bb9bc..37132860e 100644 --- a/modules/consensus/grandpa/primitives/src/justification.rs +++ b/modules/consensus/grandpa/primitives/src/justification.rs @@ -14,7 +14,10 @@ // limitations under the License. use crate::Commit; -use alloc::collections::{BTreeMap, BTreeSet}; +use alloc::{ + collections::{BTreeMap, BTreeSet}, + vec, +}; use anyhow::anyhow; use codec::{Decode, Encode}; use finality_grandpa::voter_set::VoterSet; @@ -117,7 +120,7 @@ where )?; if base_hash == signed.precommit.target_hash { - continue + continue; } let route = ancestry_chain @@ -276,7 +279,7 @@ where if $equivocation.first.0.target_hash == $equivocation.second.0.target_hash && $equivocation.first.0.target_number == $equivocation.second.0.target_number { - return Err(anyhow!("both votes have the same target!")) + return Err(anyhow!("both votes have the same target!")); } // check signatures on both votes are valid diff --git a/modules/consensus/grandpa/prover/Cargo.toml b/modules/consensus/grandpa/prover/Cargo.toml index 317708b8c..747883bce 100644 --- a/modules/consensus/grandpa/prover/Cargo.toml +++ b/modules/consensus/grandpa/prover/Cargo.toml @@ -5,19 +5,15 @@ edition = "2021" authors = ["Polytope Labs "] publish = false - - [dependencies] -hex = "0.4.3" -hex-literal = "0.4.1" -anyhow.workspace = true -serde = { workspace = true, default-features = true} +hex = { workspace = true, default-features = true } +anyhow = { workspace = true, default-features = true } +serde = { workspace = true, default-features = true } subxt = { workspace = true, default-features = true } codec = { workspace = true, default-features = true, features = ["derive"] } -derive_more = "0.99.17" +hex-literal = { workspace = true } +derive_more = { workspace = true, default-features = true } downcast-rs = "1.2.0" -jsonrpsee = { version = "0.23", features = ["async-client", "jsonrpsee-ws-client"] } -jsonrpsee-ws-client = "0.23" finality-grandpa = "0.16.0" sc-consensus-grandpa-rpc = { workspace = true, default-features = true } @@ -27,7 +23,6 @@ sp-core = { workspace = true, default-features = true } sp-trie = { workspace = true, default-features = true } sp-state-machine = { workspace = true, default-features = true } - grandpa-verifier-primitives = { workspace = true, default-features = true } ismp = { workspace = true, default-features = true } subxt-utils = { workspace = true, default-features = true } diff --git a/modules/consensus/polygon-pos/verifier/Cargo.toml b/modules/consensus/polygon-pos/verifier/Cargo.toml index 0d3a39fae..2f3188aa9 100644 --- a/modules/consensus/polygon-pos/verifier/Cargo.toml +++ b/modules/consensus/polygon-pos/verifier/Cargo.toml @@ -14,7 +14,7 @@ alloy-rlp = { version = "0.3.2", default-features = false } alloy-primitives = { version = "0.6.0", default-features = false, features = ["rlp"] } alloy-rlp-derive = "0.3.2" codec = { package = "parity-scale-codec", version = "3.1.3", default-features = false } -ethabi = { version = "18.0.0", features = ["rlp", "parity-codec"], default-features = false } +ethabi = { workspace = true } ismp = { path = "../../../ismp/core", default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } geth-primitives = { path = "../../geth-primitives", default-features = false } diff --git a/modules/consensus/sync-committee/primitives/Cargo.toml b/modules/consensus/sync-committee/primitives/Cargo.toml index efcb88d39..c10c5d671 100644 --- a/modules/consensus/sync-committee/primitives/Cargo.toml +++ b/modules/consensus/sync-committee/primitives/Cargo.toml @@ -5,22 +5,20 @@ edition = "2021" authors = ["Polytope Labs"] publish = false - - [dependencies] -ssz-rs = { git = "https://github.com/polytope-labs/ssz-rs", branch = "main", default-features = false } -hex-literal = { package = "hex-literal", version = "0.4.1", default-features = false } -codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = [ - "derive" -] } -primitive-types = { version = "0.12.1", default-features = false, features = ["serde_no_std", "impl-codec"] } -serde = { version = "1.0.185", optional = true, features = ["derive"] } -hex = { version = "0.4.3", default-features = false, features = ["alloc"] } +hex-literal = { workspace = true } +codec = { workspace = true, features = ["derive"] } +primitive-types = { workspace = true, features = ["serde_no_std", "impl-codec"] } +serde = { workspace = true, optional = true, features = ["derive"] } +hex = { workspace = true, default-features = false, features = ["alloc"] } anyhow = { workspace = true, default-features = false} +serde-hex-utils = { workspace = true, default-features = false } + +ssz-rs = { git = "https://github.com/polytope-labs/ssz-rs", branch = "main", default-features = false } + ark-ec = { version = "0.4.2", default-features = false } ark-bls12-381 = { version = "0.4.0", default-features = false } bls_on_arkworks = { version = "0.2.2", default-features = false } -serde-hex-utils = { workspace = true, default-features = false } [features] default = ["std"] diff --git a/modules/consensus/sync-committee/prover/Cargo.toml b/modules/consensus/sync-committee/prover/Cargo.toml index dca397129..da5c27905 100644 --- a/modules/consensus/sync-committee/prover/Cargo.toml +++ b/modules/consensus/sync-committee/prover/Cargo.toml @@ -4,33 +4,30 @@ version = "0.1.1" edition = "2021" publish = false - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] -sync-committee-primitives = { path= "../primitives" } -sync-committee-verifier = { path= "../verifier" } +sync-committee-primitives = { workspace = true, default-features = true } +sync-committee-verifier = { workspace = true, default-features = true } +serde = { workspace = true, default-features = true, features = ["derive"] } +anyhow = { workspace = true, default-features = true } +tokio = { workspace = true, features = ["sync"] } +tokio-stream = { workspace = true } +log = { workspace = true, default-features = true } +hex = { workspace = true, default-features = true } +json = { workspace = true, default-features = true } +primitive-types = { workspace = true, default-features = true, features = ["serde_no_std", "impl-codec"] } + ssz-rs = { git = "https://github.com/polytope-labs/ssz-rs", branch = "main" } -reqwest = {version="0.11.14", features=["json"]} +reqwest = { version="0.11.14", features=["json"]} reqwest-middleware = "0.2.4" reqwest-chain = "0.1.0" -serde = { version = "1.0.185", features = ["derive"] } -serde_json = { version = "1.0.81"} -anyhow.workspace = true -tokio = { workspace = true, features = ["sync"]} -tokio-stream = { workspace = true } -base2 = {version= "0.3.1" } +base2 = { version= "0.3.1" } env_logger = "0.10.0" ark-ec = { version = "0.4.2" } ark-bls12-381 = { version = "0.4.0" } bls_on_arkworks = { version = "0.2.2" } -primitive-types = { version = "0.12.1", features = ["serde_no_std", "impl-codec"] } -log = "0.4.20" -hex = "0.4.3" async-trait = "0.1.77" tracing = "0.1.40" - [dev-dependencies] env_logger = "0.10.0" sync-committee-primitives = { path= "../primitives" } diff --git a/modules/consensus/sync-committee/prover/src/test.rs b/modules/consensus/sync-committee/prover/src/test.rs index 4d3daba58..97c9bae8b 100644 --- a/modules/consensus/sync-committee/prover/src/test.rs +++ b/modules/consensus/sync-committee/prover/src/test.rs @@ -220,7 +220,7 @@ async fn test_prover() { while let Some(event) = es.next().await { match event { Ok(reqwest_eventsource::Event::Message(msg)) => { - let message: EventResponse = serde_json::from_str(&msg.data).unwrap(); + let message: EventResponse = json::from_str(&msg.data).unwrap(); let checkpoint = Checkpoint { epoch: message.epoch.parse().unwrap(), root: message.block }; let light_client_update = if let Some(update) = sync_committee_prover diff --git a/modules/consensus/sync-committee/verifier/Cargo.toml b/modules/consensus/sync-committee/verifier/Cargo.toml index ef450b4df..ae0c3e904 100644 --- a/modules/consensus/sync-committee/verifier/Cargo.toml +++ b/modules/consensus/sync-committee/verifier/Cargo.toml @@ -5,12 +5,11 @@ edition = "2021" authors = ["Polytope Labs"] publish = false - [dependencies] -sync-committee-primitives = { path= "../primitives", default-features = false } -ssz-rs = { git = "https://github.com/polytope-labs/ssz-rs", branch = "main", default-features = false } -log = { version = "0.4.17", default-features = false } +sync-committee-primitives = { workspace = true, default-features = false } +log = { workspace = true, default-features = false } anyhow = { workspace = true, default-features = false } +ssz-rs = { git = "https://github.com/polytope-labs/ssz-rs", branch = "main", default-features = false } ark-ec = { version = "0.4.2", default-features = false } ark-bls12-381 = { version = "0.4.0", default-features = false, features = ["curve"] } bls = { package = "bls_on_arkworks", version = "0.2.2", default-features = false } @@ -28,6 +27,5 @@ std = [ "bls/std" ] - [dev-dependencies] hex = "0.4.3" diff --git a/modules/hyperclient/Cargo.toml b/modules/hyperclient/Cargo.toml index 5ca5d8b60..2e919f68e 100644 --- a/modules/hyperclient/Cargo.toml +++ b/modules/hyperclient/Cargo.toml @@ -12,14 +12,12 @@ crate-type = ["cdylib", "rlib"] [dependencies] # workspace -wasm-bindgen = { version = "0.2.90" } subxt = { workspace = true } anyhow = { workspace = true } codec = { workspace = true } tokio = { workspace = true, features = ["macros"] } primitive-types = { workspace = true, features = ["serde"] } ethers = { workspace = true } -reqwest = { version = "0.11.27", default-features = false } ismp = { workspace = true, default-features = true } pallet-ismp = { workspace = true, features = ["disable-panic-handler"] } evm-common = { workspace = true } @@ -31,8 +29,12 @@ subxt-utils = { workspace = true } mmr-primitives = { workspace = true } sp-mmr-primitives = { workspace = true } serde-hex-utils = { workspace = true } +hex = { workspace = true } +hex-literal = { workspace = true } # crates.io +wasm-bindgen = { version = "0.2.90" } +reqwest = { version = "0.11.27", default-features = false } getrandom = { version = "0.2", default-features = false, features = ["js"] } serde = { version = "1.0.196", features = ["derive"], default-features = false } serde-wasm-bindgen = { version = "0.6.3", default-features = false } @@ -47,8 +49,6 @@ hashbrown = { version = "0.14.3", features = ["serde"] } url = "2.5.1" gql_client = "=1.0.7" console_error_panic_hook = "0.1.7" -hex = "0.4.3" -hex-literal = { version = "0.4.1" } hex_fmt = { version = "0.3.0", default-features = false } tracing = { version = "0.1.40", default-features = false } tracing-wasm = "0.2.1" diff --git a/modules/ismp/clients/arbitrum/Cargo.toml b/modules/ismp/clients/arbitrum/Cargo.toml index 8d795de2c..33a6ed19d 100644 --- a/modules/ismp/clients/arbitrum/Cargo.toml +++ b/modules/ismp/clients/arbitrum/Cargo.toml @@ -18,11 +18,10 @@ evm-common = { workspace = true } alloy-rlp = { workspace = true } alloy-rlp-derive = { workspace = true } alloy-primitives = { workspace = true } -hex = { version = "0.4.3", default-features = false } -hex-literal = "0.3.4" -ethabi = { version = "18.0.0", features = ["rlp", "parity-codec"], default-features = false } -codec = { package = "parity-scale-codec", version = "3.1.3", default-features = false } - +hex = { workspace = true, default-features = false } +hex-literal = { workspace = true } +codec = { workspace = true, default-features = false } +ethabi = { workspace = true } [dev-dependencies] ethers = { workspace = true, features = ["default"] } @@ -30,7 +29,6 @@ tokio = { workspace = true, features = ["full"] } ismp-testsuite = { path = "../../testsuite" } sp-core = { workspace = true } - [features] default = ["std"] std = [ diff --git a/modules/ismp/clients/bsc/Cargo.toml b/modules/ismp/clients/bsc/Cargo.toml index 21da1db09..6575f7166 100644 --- a/modules/ismp/clients/bsc/Cargo.toml +++ b/modules/ismp/clients/bsc/Cargo.toml @@ -8,9 +8,9 @@ publish = false [dependencies] -log = { version = "0.4.17", default-features = false } +log = { workspace = true, default-features = false } anyhow = { workspace = true, default-features = false } -codec = { package = "parity-scale-codec", version = "3.1.3", default-features = false } +codec = { workspace = true, default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } sp-core = {workspace = true, default-features = false } diff --git a/modules/ismp/clients/optimism/Cargo.toml b/modules/ismp/clients/optimism/Cargo.toml index d5707a183..0e283d706 100644 --- a/modules/ismp/clients/optimism/Cargo.toml +++ b/modules/ismp/clients/optimism/Cargo.toml @@ -17,9 +17,9 @@ evm-common = { workspace = true } alloy-rlp = { workspace = true } alloy-rlp-derive = { workspace = true } alloy-primitives = { workspace = true } -hex = { version = "0.4.3", default-features = false } -hex-literal = "0.3.4" -ethabi = { version = "18.0.0", features = ["rlp", "parity-codec"], default-features = false } +hex = { workspace = true, default-features = false } +hex-literal = { workspace = true } +ethabi = { workspace = true } codec = { package = "parity-scale-codec", version = "3.1.3", default-features = false } diff --git a/modules/ismp/clients/parachain/client/Cargo.toml b/modules/ismp/clients/parachain/client/Cargo.toml index c508ca892..fb6f6ea2e 100644 --- a/modules/ismp/clients/parachain/client/Cargo.toml +++ b/modules/ismp/clients/parachain/client/Cargo.toml @@ -16,7 +16,7 @@ readme = "./README.md" serde = { workspace = true, features = ["derive"], optional = false } codec = { workspace = true, features = ["derive"] } scale-info = { workspace = true, features = ["derive"] } -hex-literal = "0.4.1" +hex-literal = { workspace = true } primitive-types = { workspace = true } log = { workspace = true } diff --git a/modules/ismp/clients/parachain/inherent/Cargo.toml b/modules/ismp/clients/parachain/inherent/Cargo.toml index 09a3d6915..64ec136d0 100644 --- a/modules/ismp/clients/parachain/inherent/Cargo.toml +++ b/modules/ismp/clients/parachain/inherent/Cargo.toml @@ -32,4 +32,4 @@ ismp = { workspace = true, default-features = true } ismp-parachain = { workspace = true, default-features = true } ismp-parachain-runtime-api = { workspace = true, default-features = true } pallet-ismp-runtime-api = { workspace = true, default-features = true } -log = "0.4.21" +log = { workspace = true } diff --git a/modules/ismp/clients/sync-committee/Cargo.toml b/modules/ismp/clients/sync-committee/Cargo.toml index e889c284d..e5138975d 100644 --- a/modules/ismp/clients/sync-committee/Cargo.toml +++ b/modules/ismp/clients/sync-committee/Cargo.toml @@ -21,10 +21,10 @@ op-verifier = { workspace = true } pallet-ismp-host-executive = { workspace = true } # crates.io -hex = { version = "0.4.3", default-features = false } -hex-literal = "0.3.4" -ethabi = { version = "18.0.0", features = ["rlp", "parity-codec"], default-features = false } -codec = { package = "parity-scale-codec", version = "3.1.3", default-features = false } +hex = { workspace = true, default-features = false } +hex-literal = { workspace = true } +ethabi = { workspace = true } +codec = { workspace = true, default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } frame-support = { workspace = true } diff --git a/modules/ismp/clients/sync-committee/evm-common/Cargo.toml b/modules/ismp/clients/sync-committee/evm-common/Cargo.toml index b7f19780c..78e089c89 100644 --- a/modules/ismp/clients/sync-committee/evm-common/Cargo.toml +++ b/modules/ismp/clients/sync-committee/evm-common/Cargo.toml @@ -20,12 +20,12 @@ hash-db = { workspace = true } alloy-rlp = { workspace = true } alloy-rlp-derive = { workspace = true } alloy-primitives = { workspace = true } -hex = { version = "0.4.3", default-features = false } -hex-literal = "0.3.4" -ethabi = { version = "18.0.0", features = ["rlp", "parity-codec"], default-features = false } +hex = { workspace = true, default-features = false } +hex-literal = { workspace = true } +ethabi = { workspace = true } hash256-std-hasher = { version = "0.15.2", default-features = false } -codec = { package = "parity-scale-codec", version = "3.1.3", default-features = false } -sp-crypto-hashing = { version = "0.1.0", default-features = false } +codec = { workspace = true, default-features = false } +sp-crypto-hashing = { workspace = true, default-features = false } [features] default = ["std"] diff --git a/modules/ismp/core/Cargo.toml b/modules/ismp/core/Cargo.toml index d3eac9561..22cecfff7 100644 --- a/modules/ismp/core/Cargo.toml +++ b/modules/ismp/core/Cargo.toml @@ -19,10 +19,9 @@ serde = { workspace = true, features = ["derive"] } scale-info = { workspace = true, features = ["derive"] } derive_more = { workspace = true, default-features = false, features = ["from", "into", "display"] } displaydoc = { version = "0.2", default-features = false } -serde_json = { version = "1.0.99", default-features = false, features = ["alloc"] } -hex = { version = "0.4.3", features = ["alloc"], default-features = false } +hex = { workspace = true, features = ["alloc"] } anyhow = { workspace = true, default-features = false } -thiserror = { workspace = true, default-features = false } +thiserror = { workspace = true } serde-hex-utils = { workspace = true, default-features = false } [features] @@ -35,7 +34,6 @@ std = [ "serde/std", "anyhow/std", "hex/std", - "serde_json/std", "serde-hex-utils/std", "thiserror/std", "displaydoc/std", diff --git a/modules/ismp/pallets/call-decompressor/Cargo.toml b/modules/ismp/pallets/call-decompressor/Cargo.toml index 2b0e3a49c..7c885daea 100644 --- a/modules/ismp/pallets/call-decompressor/Cargo.toml +++ b/modules/ismp/pallets/call-decompressor/Cargo.toml @@ -24,7 +24,7 @@ pallet-ismp = { workspace = true, features = ["unsigned"] } pallet-ismp-relayer = { workspace = true } # crates.io -codec = { package = "parity-scale-codec", version = "3.1.3", default-features = false } +codec = { workspace = true, default-features = false } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } ruzstd = { version = "0.6.0", default-features = false } diff --git a/modules/ismp/pallets/pallet/Cargo.toml b/modules/ismp/pallets/pallet/Cargo.toml index 6bc5f5d9a..766d25f80 100644 --- a/modules/ismp/pallets/pallet/Cargo.toml +++ b/modules/ismp/pallets/pallet/Cargo.toml @@ -31,7 +31,7 @@ anyhow = { workspace = true, default-features = false } # crates.io fortuples = "0.9.1" log = { version = "0.4.17", default-features = false } -serde = { version = "1.0.136", features = ["derive"], default-features = false } +serde = { workspace = true, features = ["derive"] } [dev-dependencies] env_logger = "0.10.0" diff --git a/modules/ismp/pallets/relayer/Cargo.toml b/modules/ismp/pallets/relayer/Cargo.toml index 5e2673829..383e108b6 100644 --- a/modules/ismp/pallets/relayer/Cargo.toml +++ b/modules/ismp/pallets/relayer/Cargo.toml @@ -13,7 +13,6 @@ frame-support = { workspace = true } frame-system = { workspace = true } sp-runtime = { workspace = true } sp-core = { workspace = true } -sp-std = { workspace = true } sp-io = { workspace = true } pallet-ismp = { workspace = true } evm-common = { workspace = true } @@ -24,15 +23,14 @@ pallet-hyperbridge = { workspace = true } ismp = { workspace = true } # crates.io -codec = { package = "parity-scale-codec", version = "3.1.3", default-features = false } -log = { version = "0.4.17", default-features = false } +codec = { workspace = true, default-features = false } +log = { workspace = true, default-features = false } hashbrown = { version = "0.14.3" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } alloy-rlp = { workspace = true } alloy-primitives = { workspace = true } alloy-rlp-derive = { workspace = true } -ethabi = { version = "18.0.0", features = ["rlp", "parity-codec"], default-features = false } - +ethabi = { workspace = true } [dev-dependencies] pallet-ismp = { workspace = true, features = [ "testing" ] } @@ -56,7 +54,6 @@ std = [ "log/std", "scale-info/std", "sp-runtime/std", - "sp-std/std", "sp-core/std", "sp-io/std", "ismp/std", diff --git a/modules/ismp/pallets/relayer/src/lib.rs b/modules/ismp/pallets/relayer/src/lib.rs index 1d99fae85..43424da3e 100644 --- a/modules/ismp/pallets/relayer/src/lib.rs +++ b/modules/ismp/pallets/relayer/src/lib.rs @@ -23,7 +23,7 @@ extern crate alloc; pub mod withdrawal; use crate::withdrawal::{Key, Signature, WithdrawalInputData, WithdrawalParams, WithdrawalProof}; -use alloc::{collections::BTreeMap, vec::Vec}; +use alloc::{collections::BTreeMap, vec, vec::Vec}; use alloy_primitives::Address; use codec::Encode; use ethabi::ethereum_types::H256; @@ -48,7 +48,6 @@ use pallet_ismp::child_trie::{RequestCommitments, ResponseCommitments}; use pallet_ismp_host_executive::{HostParam, HostParams}; use sp_core::U256; use sp_runtime::{AccountId32, DispatchError}; -use sp_std::prelude::*; pub const MODULE_ID: &'static [u8] = b"ISMP-RLYR"; diff --git a/modules/ismp/pallets/relayer/src/withdrawal.rs b/modules/ismp/pallets/relayer/src/withdrawal.rs index 52ae04a77..8b3f6bf25 100644 --- a/modules/ismp/pallets/relayer/src/withdrawal.rs +++ b/modules/ismp/pallets/relayer/src/withdrawal.rs @@ -1,9 +1,9 @@ +use alloc::{vec, vec::Vec}; use alloy_primitives::{Address, B256}; use alloy_rlp_derive::{RlpDecodable, RlpEncodable}; use codec::{Decode, Encode}; use ismp::{host::StateMachine, messaging::Proof}; use sp_core::{H160, H256, U256}; -use sp_std::prelude::*; #[derive(Debug, Clone, Encode, Decode, scale_info::TypeInfo, PartialEq, Eq)] pub enum Key { diff --git a/modules/ismp/pallets/rpc/Cargo.toml b/modules/ismp/pallets/rpc/Cargo.toml index 3ec92c346..cf97c743e 100644 --- a/modules/ismp/pallets/rpc/Cargo.toml +++ b/modules/ismp/pallets/rpc/Cargo.toml @@ -16,12 +16,12 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] anyhow = { workspace = true } -hex = "0.4.3" -codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] } -hex-literal = { version = "0.3.3" } -jsonrpsee = { version = "0.23", features = ["client-core", "server", "macros"] } -serde = { version = "1.0.136", features = ["derive"] } -serde_json = "1.0.45" +hex = { workspace = true } +codec = { workspace = true, features = ["derive"], default-features = true } +hex-literal = { workspace = true, default-features = true } +jsonrpsee = { workspace = true, features = ["client-core", "server", "macros"] } +serde = { workspace = true, features = ["derive"], default-features = true } +json = { workspace = true, default-features = true } tower = { version = "0.4.13", features = ["util"] } ismp = { workspace = true, default-features = true } diff --git a/modules/ismp/pallets/rpc/src/lib.rs b/modules/ismp/pallets/rpc/src/lib.rs index fd11e7ee2..b0623cc4f 100644 --- a/modules/ismp/pallets/rpc/src/lib.rs +++ b/modules/ismp/pallets/rpc/src/lib.rs @@ -505,7 +505,7 @@ where // using swap remove should be fine unless the node is in an inconsistent // state .swap_remove(index as usize); - let ext_bytes = serde_json::to_string(&extrinsic).map_err(|err| { + let ext_bytes = json::to_string(&extrinsic).map_err(|err| { runtime_error_into_rpc_error(format!( "Failed to serialize extrinsic: {err:?}" )) diff --git a/modules/ismp/pallets/runtime-api/Cargo.toml b/modules/ismp/pallets/runtime-api/Cargo.toml index dd131d24f..4d030ae8b 100644 --- a/modules/ismp/pallets/runtime-api/Cargo.toml +++ b/modules/ismp/pallets/runtime-api/Cargo.toml @@ -16,7 +16,7 @@ sp-api = { workspace = true } primitive-types = { workspace = true } pallet-ismp = { workspace = true, default-features = false } ismp = { workspace = true, default-features = false } -serde = { version = "1.0.136", features = ["derive"], optional = true } +serde = { workspace = true, features = ["derive"], optional = true } sp-mmr-primitives = { workspace = true } codec = { workspace = true, features = ["derive"] } diff --git a/modules/trees/ethereum/Cargo.toml b/modules/trees/ethereum/Cargo.toml index 549b93453..f580bf637 100644 --- a/modules/trees/ethereum/Cargo.toml +++ b/modules/trees/ethereum/Cargo.toml @@ -13,28 +13,32 @@ readme = "./README.md" [dependencies] trie-db = { workspace = true } hash-db = { workspace = true } -memory-db = { workspace = true } +memory-db = { workspace = true } codec = { workspace = true, features = ["derive"] } - -rlp = { version = "0.5.1", default-features = false } -primitive-types = { version = "0.12.0", default-features = false } +rlp = { workspace = true } +thiserror = { workspace = true } +derive_more = { workspace = true, features = ["from"] } +anyhow = { workspace = true } +primitive-types = { workspace = true, features = ["rlp"] } hash256-std-hasher = { version = "0.15.2", optional = true } tiny-keccak = { version = "2.0.2", features = ["keccak"], optional = true } [dev-dependencies] hex = "0.4.3" hex-literal = "0.3.4" -primitive-types = { version = "0.12.0", features = ["rlp"] } rlp-derive = "0.1.0" [features] default = ["std"] std = [ - "tiny-keccak", - "hash256-std-hasher", "trie-db/std", "hash-db/std", + "memory-db/std", + "codec/std", + "thiserror/std", "rlp/std", + "anyhow/std", "primitive-types/std", - "codec/std" + "hash256-std-hasher", + "tiny-keccak", ] diff --git a/modules/trees/ethereum/src/node_codec.rs b/modules/trees/ethereum/src/node_codec.rs index 789b797a9..918d6c53c 100644 --- a/modules/trees/ethereum/src/node_codec.rs +++ b/modules/trees/ethereum/src/node_codec.rs @@ -37,6 +37,13 @@ const HASHED_NULL_NODE: [u8; 32] = [ 0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21, ]; +/// The error type for this crate +#[derive(Debug, thiserror::Error, derive_more::From)] +pub enum Error { + #[error("DecodeError: {_0}")] + DecodeError(DecoderError), +} + // NOTE: what we'd really like here is: // `impl NodeCodec for RlpNodeCodec where H::Out: Decodable` // but due to the current limitations of Rust const evaluation we can't @@ -45,7 +52,7 @@ impl NodeCodec for RlpNodeCodec where H: Hasher, { - type Error = DecoderError; + type Error = Error; type HashOut = H::Out; fn hashed_null_node() -> H::Out { @@ -135,7 +142,7 @@ where // an empty branch index. Prototype::Data(0) => Ok(NodePlan::Empty), // something went wrong. - _ => Err(DecoderError::Custom("Rlp is not valid.")), + _ => Err(DecoderError::Custom("Rlp is not valid."))?, } } diff --git a/modules/trees/mmr/pallet/Cargo.toml b/modules/trees/mmr/pallet/Cargo.toml index 016a3d0b7..b6135f17a 100644 --- a/modules/trees/mmr/pallet/Cargo.toml +++ b/modules/trees/mmr/pallet/Cargo.toml @@ -7,13 +7,11 @@ license = "Apache-2.0" description = "A fork of the FRAME Merkle Mountain Range pallet which allows accumulating multiple leaves per block" publish = false - [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] [dependencies] -serde = { version = "1.0.136", features = ["derive"], default-features = false } - +serde = { workspace = true, features = ["derive"], default-features = false } codec = { workspace = true } log = { workspace = true } scale-info = { workspace = true } diff --git a/modules/trees/mmr/pallet/runtime-api/Cargo.toml b/modules/trees/mmr/pallet/runtime-api/Cargo.toml index 20d1e1a49..283a7cd4a 100644 --- a/modules/trees/mmr/pallet/runtime-api/Cargo.toml +++ b/modules/trees/mmr/pallet/runtime-api/Cargo.toml @@ -11,11 +11,17 @@ publish = false sp-api = { workspace = true } sp-std = { workspace = true } sp-core = { workspace = true } -serde = { version = "1.0.136", features = ["derive"], optional = true } +serde = { workspace = true, features = ["derive"], optional = true } codec = { workspace = true } sp-mmr-primitives = { workspace = true } [features] -default = ['std'] -std = ['sp-api/std', 'sp-std/std', 'codec/std', "serde", "sp-core/std", "sp-mmr-primitives/std"] - +default = ["std"] +std = [ + "sp-api/std", + "sp-std/std", + "codec/std", + "serde", + "sp-core/std", + "sp-mmr-primitives/std" +] diff --git a/modules/trees/mmr/pallet/src/lib.rs b/modules/trees/mmr/pallet/src/lib.rs index 794ec4a47..8b22f125f 100644 --- a/modules/trees/mmr/pallet/src/lib.rs +++ b/modules/trees/mmr/pallet/src/lib.rs @@ -56,6 +56,8 @@ //! NOTE This pallet is experimental and not proven to work in production. #![cfg_attr(not(feature = "std"), no_std)] +extern crate alloc; + use core::marker::PhantomData; use frame_system::pallet_prelude::{BlockNumberFor, HeaderFor}; use log; diff --git a/modules/trees/mmr/pallet/src/mmr/storage.rs b/modules/trees/mmr/pallet/src/mmr/storage.rs index b3509f341..df14bdb06 100644 --- a/modules/trees/mmr/pallet/src/mmr/storage.rs +++ b/modules/trees/mmr/pallet/src/mmr/storage.rs @@ -17,6 +17,7 @@ //! An MMR storage implementation. +use alloc::{vec, vec::Vec}; use codec::Encode; use log::{debug, trace}; use merkle_mountain_range::helper; @@ -25,8 +26,6 @@ use sp_core::offchain::StorageKind; use sp_io::offchain_index; use sp_mmr_primitives::utils::NodesUtils; use sp_std::iter::Peekable; -#[cfg(not(feature = "std"))] -use sp_std::prelude::*; use crate::{ mmr::{Node, NodeOf}, diff --git a/modules/trees/mmr/primitives/Cargo.toml b/modules/trees/mmr/primitives/Cargo.toml index 4112bd70f..b2aea24a3 100644 --- a/modules/trees/mmr/primitives/Cargo.toml +++ b/modules/trees/mmr/primitives/Cargo.toml @@ -19,7 +19,7 @@ sp-core = { workspace = true } sp-runtime = { workspace = true } sp-std = { workspace = true } sp-mmr-primitives = { workspace = true } -serde = { version = "1.0.136", features = ["derive"], default-features = false } +serde = { workspace = true, features = ["derive"], default-features = false } scale-info = { workspace = true } frame-system = { workspace = true } ismp = { workspace = true } diff --git a/modules/utils/serde/Cargo.toml b/modules/utils/serde/Cargo.toml index 173e39bb6..881350378 100644 --- a/modules/utils/serde/Cargo.toml +++ b/modules/utils/serde/Cargo.toml @@ -13,7 +13,7 @@ readme = "./README.md" [dependencies] # crates.io serde = { workspace = true, features = ["derive"] } -hex = { version = "0.4.3", features = ["alloc"], default-features = false } +hex = { workspace = true, features = ["alloc"], default-features = false } anyhow = { workspace = true, default-features = false } [features] diff --git a/modules/utils/subxt/Cargo.toml b/modules/utils/subxt/Cargo.toml index 4f28b72e3..5889e69e3 100644 --- a/modules/utils/subxt/Cargo.toml +++ b/modules/utils/subxt/Cargo.toml @@ -10,13 +10,13 @@ ismp = { workspace = true } sp-crypto-hashing = { workspace = true } codec = { workspace = true } anyhow = { workspace = true } -futures = "0.3.30" reconnecting-jsonrpsee-ws-client = { workspace = true } primitive-types = { workspace = true } alloy-primitives = { workspace = true } pallet-ismp-host-executive = { workspace = true } pallet-hyperbridge = { workspace = true } -derivative ={ version = "2.2.0" } +derivative = { version = "2.2.0" } +futures = "0.3.30" [features] default = ["std"] diff --git a/parachain/node/Cargo.toml b/parachain/node/Cargo.toml index 2905770fd..31f4bad82 100644 --- a/parachain/node/Cargo.toml +++ b/parachain/node/Cargo.toml @@ -14,17 +14,16 @@ dist = true [dependencies] # crates.io clap = { version = "4.0.32", features = ["derive"] } -log = "0.4.17" -codec = { package = "parity-scale-codec", version = "3.0.0" } -serde = { version = "1.0.152", features = ["derive"] } -jsonrpsee = { version = "0.23", features = ["server"] } +log = { workspace = true, default-features = true } +codec = { workspace = true, default-features = true } +serde = { workspace = true, default-features = true } +jsonrpsee = { workspace = true } futures = "0.3.28" -serde_json = "1.0.108" +json = { workspace = true, default-features = true } # local -gargantua-runtime = { path = "../runtimes/gargantua" } -#messier-runtime = { path = "../runtimes/messier" } -nexus-runtime = { path = "../runtimes/nexus" } +gargantua-runtime = { workspace = true, default-features = true } +nexus-runtime = { workspace = true, default-features = true } pallet-ismp-rpc = { workspace = true } pallet-ismp-runtime-api = { workspace = true } mmr-gadget = { workspace = true } diff --git a/parachain/node/src/chain_spec.rs b/parachain/node/src/chain_spec.rs index 0b1102e4e..a3f702ac3 100644 --- a/parachain/node/src/chain_spec.rs +++ b/parachain/node/src/chain_spec.rs @@ -183,7 +183,7 @@ fn testnet_genesis( endowed_accounts: Vec, root: AccountId, id: u32, -) -> serde_json::Value { +) -> json::Value { let asset_id: H256 = sp_io::hashing::keccak_256(&MultiLocation::parent().encode()).into(); let para_id: ParaId = id.into(); @@ -194,7 +194,7 @@ fn testnet_genesis( _ => ParachainData { id: 1000, slot_duration: 6000 }, /* default to assethub */ }; - serde_json::json!({ + json::json!({ "balances": { "balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), }, diff --git a/parachain/runtimes/gargantua/Cargo.toml b/parachain/runtimes/gargantua/Cargo.toml index 61e5b6239..98c57f72a 100644 --- a/parachain/runtimes/gargantua/Cargo.toml +++ b/parachain/runtimes/gargantua/Cargo.toml @@ -11,9 +11,9 @@ substrate-wasm-builder = { workspace = true } [dependencies] # crates.io -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -hex-literal = { version = "0.4.1", optional = true } -log = { version = "0.4.17", default-features = false } +codec = { workspace = true, features = ["derive"] } +hex-literal = { workspace = true, optional = true } +log = { workspace = true } scale-info = { version = "2.3.1", default-features = false, features = ["derive"] } smallvec = "1.10.0" orml-xcm-support = { workspace = true } @@ -248,4 +248,4 @@ try-runtime = [ # This must be used when buiding for a runtime upgrade so metadata hash verification is possible -metadata-hash = ["substrate-wasm-builder/metadata-hash"] \ No newline at end of file +metadata-hash = ["substrate-wasm-builder/metadata-hash"] diff --git a/parachain/runtimes/nexus/Cargo.toml b/parachain/runtimes/nexus/Cargo.toml index e4b72cbbe..235863521 100644 --- a/parachain/runtimes/nexus/Cargo.toml +++ b/parachain/runtimes/nexus/Cargo.toml @@ -15,9 +15,9 @@ substrate-wasm-builder = { workspace = true } [dependencies] # crates.io -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -hex-literal = { version = "0.4.1", optional = true } -log = { version = "0.4.17", default-features = false } +codec = { workspace = true, features = ["derive"] } +hex-literal = { workspace = true, optional = true } +log = { workspace = true } scale-info = { version = "2.3.1", default-features = false, features = ["derive"] } smallvec = "1.10.0" orml-xcm-support = { workspace = true } @@ -226,7 +226,7 @@ runtime-benchmarks = [ "pallet-assets/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", "parachains-common/runtime-benchmarks", - "pallet-multisig/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", "pallet-proxy/runtime-benchmarks" ] @@ -257,4 +257,4 @@ try-runtime = [ ] # This must be used when building for a runtime upgrade so metadata hash verification is possible -metadata-hash = ["substrate-wasm-builder/metadata-hash"] \ No newline at end of file +metadata-hash = ["substrate-wasm-builder/metadata-hash"] diff --git a/tesseract/evm/Cargo.toml b/tesseract/evm/Cargo.toml index 2f901f362..60febca91 100644 --- a/tesseract/evm/Cargo.toml +++ b/tesseract/evm/Cargo.toml @@ -25,7 +25,7 @@ codec = { package = "parity-scale-codec", version = "3.2.2", features = ["derive sp-core = { workspace = true, features = ["full_crypto"] } log = "0.4.19" ethers = { workspace = true, features = ["rustls"] } -ethabi = { version = "18.0.0", features = ["rlp", "full-serde"], default-features = false } +ethabi = { workspace = true, features = ["full-serde"] } tokio = { workspace = true, features = ["macros", "sync", "time"] } tokio-stream = { workspace = true } frame-support = { workspace = true, default-features = true } diff --git a/tesseract/integration-test/src/lib.rs b/tesseract/integration-test/src/lib.rs index 7a18fb249..b04620c4c 100644 --- a/tesseract/integration-test/src/lib.rs +++ b/tesseract/integration-test/src/lib.rs @@ -433,8 +433,8 @@ async fn get_request_works() -> Result<(), anyhow::Error> { Ok(()) } -// #[tokio::test(flavor = "multi_thread")] -// #[ignore] +#[tokio::test(flavor = "multi_thread")] +#[ignore] async fn run_integration_tests() -> Result<(), anyhow::Error> { let _ = log_setup(); let (chain_a_sub_client, chain_b_sub_client) = create_clients().await?; From 1863e682c901eec77f9daf6a2b88a5cbfe5232b9 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Sun, 8 Dec 2024 14:55:33 +0000 Subject: [PATCH 05/11] reword docs --- modules/ismp/core/src/handlers/timeout.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ismp/core/src/handlers/timeout.rs b/modules/ismp/core/src/handlers/timeout.rs index a68943fdb..e546106f6 100644 --- a/modules/ismp/core/src/handlers/timeout.rs +++ b/modules/ismp/core/src/handlers/timeout.rs @@ -48,7 +48,7 @@ where let dest_chain = request.dest_chain(); // in order to allow proxies, the host must configure the given state machine - // as it's proxy and must not have a state machine client for the source chain + // as it's proxy and must not have a state machine client for the destination chain let allow_proxy = host.is_allowed_proxy(&timeout_proof.height.id.state_id) && check_state_machine_client(dest_chain); @@ -117,7 +117,7 @@ where let dest_chain = response.dest_chain(); // in order to allow proxies, the host must configure the given state machine - // as it's proxy and must not have a state machine client for the source chain + // as it's proxy and must not have a state machine client for the destination chain let allow_proxy = host.is_allowed_proxy(&timeout_proof.height.id.state_id) && check_state_machine_client(dest_chain); From b00a865de1662065c7cb52276c10fd9aaa9fd1a6 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Sun, 8 Dec 2024 14:58:32 +0000 Subject: [PATCH 06/11] fix broken docs link --- modules/consensus/grandpa/primitives/Cargo.toml | 2 +- modules/consensus/grandpa/verifier/Cargo.toml | 2 +- modules/ismp/clients/grandpa/Cargo.toml | 2 +- modules/ismp/clients/parachain/client/Cargo.toml | 2 +- modules/ismp/clients/parachain/inherent/Cargo.toml | 2 +- modules/ismp/clients/parachain/runtime-api/Cargo.toml | 2 +- modules/ismp/pallets/hyperbridge/Cargo.toml | 2 +- modules/ismp/pallets/pallet/Cargo.toml | 4 ++-- modules/ismp/pallets/rpc/Cargo.toml | 2 +- modules/ismp/pallets/runtime-api/Cargo.toml | 2 +- modules/ismp/state-machines/substrate/Cargo.toml | 2 +- modules/trees/mmr/primitives/Cargo.toml | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/consensus/grandpa/primitives/Cargo.toml b/modules/consensus/grandpa/primitives/Cargo.toml index be173e9fc..e0ab267f9 100644 --- a/modules/consensus/grandpa/primitives/Cargo.toml +++ b/modules/consensus/grandpa/primitives/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" repository = "https://github.com/polytope-labs/hyperbridge" -homepage = "https://docs.hyperbridge.network/developers/polkadot/integration" +homepage = "https://docs.hyperbridge.network/developers/polkadot/getting-started" documentation = "https://docs.rs/grandpa-verifier-primitives" description = "Primitives for verifying GRANDPA consensus proofs" keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability", "GRANDPA"] diff --git a/modules/consensus/grandpa/verifier/Cargo.toml b/modules/consensus/grandpa/verifier/Cargo.toml index e734f3d6f..0bdae52c5 100644 --- a/modules/consensus/grandpa/verifier/Cargo.toml +++ b/modules/consensus/grandpa/verifier/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" repository = "https://github.com/polytope-labs/hyperbridge" -homepage = "https://docs.hyperbridge.network/developers/polkadot/integration" +homepage = "https://docs.hyperbridge.network/developers/polkadot/getting-started" documentation = "https://docs.rs/grandpa-verifier" description = "GRANDPA consensus proof verifier" keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability", "GRANDPA"] diff --git a/modules/ismp/clients/grandpa/Cargo.toml b/modules/ismp/clients/grandpa/Cargo.toml index 12f6a4b27..5ce17c1a2 100644 --- a/modules/ismp/clients/grandpa/Cargo.toml +++ b/modules/ismp/clients/grandpa/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" repository = "https://github.com/polytope-labs/hyperbridge" -homepage = "https://docs.hyperbridge.network/developers/polkadot/integration" +homepage = "https://docs.hyperbridge.network/developers/polkadot/getting-started" documentation = "https://docs.rs/ismp-grandpa" description = "GRANDPA consensus client for pallet-ismp" keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability", "GRANDPA"] diff --git a/modules/ismp/clients/parachain/client/Cargo.toml b/modules/ismp/clients/parachain/client/Cargo.toml index fb6f6ea2e..66787174a 100644 --- a/modules/ismp/clients/parachain/client/Cargo.toml +++ b/modules/ismp/clients/parachain/client/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" repository = "https://github.com/polytope-labs/hyperbridge" -homepage = "https://docs.hyperbridge.network/developers/polkadot/integration" +homepage = "https://docs.hyperbridge.network/developers/polkadot/getting-started" documentation = "https://docs.rs/ismp-parachain" description = "Parachain consensus client for pallet-ismp" keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability"] diff --git a/modules/ismp/clients/parachain/inherent/Cargo.toml b/modules/ismp/clients/parachain/inherent/Cargo.toml index 64ec136d0..e1434c76d 100644 --- a/modules/ismp/clients/parachain/inherent/Cargo.toml +++ b/modules/ismp/clients/parachain/inherent/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" repository = "https://github.com/polytope-labs/hyperbridge" -homepage = "https://docs.hyperbridge.network/developers/polkadot/integration" +homepage = "https://docs.hyperbridge.network/developers/polkadot/getting-started" documentation = "https://docs.rs/ismp-parachain-inherent" description = "ISMP parachain consensus client inherent provider" keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability"] diff --git a/modules/ismp/clients/parachain/runtime-api/Cargo.toml b/modules/ismp/clients/parachain/runtime-api/Cargo.toml index 7ca0f110b..c1ea9d913 100644 --- a/modules/ismp/clients/parachain/runtime-api/Cargo.toml +++ b/modules/ismp/clients/parachain/runtime-api/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" repository = "https://github.com/polytope-labs/hyperbridge" -homepage = "https://docs.hyperbridge.network/developers/polkadot/integration" +homepage = "https://docs.hyperbridge.network/developers/polkadot/getting-started" documentation = "https://docs.rs/ismp-parachain" description = "Substrate runtime API for the ISMP Parachain consensus client" keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability"] diff --git a/modules/ismp/pallets/hyperbridge/Cargo.toml b/modules/ismp/pallets/hyperbridge/Cargo.toml index cf18ea2b4..ef0689686 100644 --- a/modules/ismp/pallets/hyperbridge/Cargo.toml +++ b/modules/ismp/pallets/hyperbridge/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" repository = "https://github.com/polytope-labs/hyperbridge" -homepage = "https://docs.hyperbridge.network/developers/polkadot/integration" +homepage = "https://docs.hyperbridge.network/developers/polkadot/getting-started" documentation = "https://docs.rs/pallet-hyperbridge" description = "Pallet hyperbridge mediates the connection between hyperbridge and substrate-based chains." keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability"] diff --git a/modules/ismp/pallets/pallet/Cargo.toml b/modules/ismp/pallets/pallet/Cargo.toml index 766d25f80..0083d08d4 100644 --- a/modules/ismp/pallets/pallet/Cargo.toml +++ b/modules/ismp/pallets/pallet/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" repository = "https://github.com/polytope-labs/hyperbridge" -homepage = "https://docs.hyperbridge.network/developers/polkadot/integration" +homepage = "https://docs.hyperbridge.network/developers/polkadot/getting-started" documentation = "https://docs.rs/pallet-ismp" description = "The substrate runtime implementation of the Interoperable State Machine Protocol" keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability"] @@ -30,7 +30,7 @@ anyhow = { workspace = true, default-features = false } # crates.io fortuples = "0.9.1" -log = { version = "0.4.17", default-features = false } +log = { workspace = true } serde = { workspace = true, features = ["derive"] } [dev-dependencies] diff --git a/modules/ismp/pallets/rpc/Cargo.toml b/modules/ismp/pallets/rpc/Cargo.toml index cf97c743e..a96e9675d 100644 --- a/modules/ismp/pallets/rpc/Cargo.toml +++ b/modules/ismp/pallets/rpc/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" repository = "https://github.com/polytope-labs/hyperbridge" -homepage = "https://docs.hyperbridge.network/developers/polkadot/integration" +homepage = "https://docs.hyperbridge.network/developers/polkadot/getting-started" documentation = "https://docs.rs/pallet-ismp-rpc" description = "RPC apis for pallet-ismp" keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability"] diff --git a/modules/ismp/pallets/runtime-api/Cargo.toml b/modules/ismp/pallets/runtime-api/Cargo.toml index 4d030ae8b..e54a5eb9f 100644 --- a/modules/ismp/pallets/runtime-api/Cargo.toml +++ b/modules/ismp/pallets/runtime-api/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" repository = "https://github.com/polytope-labs/hyperbridge" -homepage = "https://docs.hyperbridge.network/developers/polkadot/integration" +homepage = "https://docs.hyperbridge.network/developers/polkadot/getting-started" documentation = "https://docs.rs/pallet-ismp" description = "The substrate runtime API for pallet-ismp" keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability"] diff --git a/modules/ismp/state-machines/substrate/Cargo.toml b/modules/ismp/state-machines/substrate/Cargo.toml index 674ef4446..4e3db8a09 100644 --- a/modules/ismp/state-machines/substrate/Cargo.toml +++ b/modules/ismp/state-machines/substrate/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" repository = "https://github.com/polytope-labs/hyperbridge" -homepage = "https://docs.hyperbridge.network/developers/polkadot/integration" +homepage = "https://docs.hyperbridge.network/developers/polkadot/getting-started" documentation = "https://docs.rs/substrate-state-machine" description = "ISMP state machine client implementation for substrate-based chains " keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability"] diff --git a/modules/trees/mmr/primitives/Cargo.toml b/modules/trees/mmr/primitives/Cargo.toml index b2aea24a3..a7120281b 100644 --- a/modules/trees/mmr/primitives/Cargo.toml +++ b/modules/trees/mmr/primitives/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" repository = "https://github.com/polytope-labs/hyperbridge" -homepage = "https://docs.hyperbridge.network/developers/polkadot/integration" +homepage = "https://docs.hyperbridge.network/developers/polkadot/getting-started" documentation = "https://docs.rs/ismp-parachain" description = "Merkle mountain range primitives for pallet-ismp" keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability"] From 7c8cf404ce23440d8ea0baf8b80e4e516ba113c1 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Sun, 8 Dec 2024 15:01:52 +0000 Subject: [PATCH 07/11] update docs --- docs/pages/developers/polkadot/pallet-ismp.mdx | 16 ++++++++-------- modules/ismp/pallets/pallet/README.md | 4 ++-- modules/ismp/pallets/pallet/src/lib.rs | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/pages/developers/polkadot/pallet-ismp.mdx b/docs/pages/developers/polkadot/pallet-ismp.mdx index 67b2eff0f..0a486c752 100644 --- a/docs/pages/developers/polkadot/pallet-ismp.mdx +++ b/docs/pages/developers/polkadot/pallet-ismp.mdx @@ -44,9 +44,9 @@ impl pallet_ismp::Config for Runtime { // as an example, the parachain consensus client ismp_parachain::ParachainConsensusClient, ); - // Optional merkle mountain range overlay tree, for cheaper outgoing request proofs. - // You most likely don't need it, just use the `NoOpMmrTree` - type Mmr = pallet_ismp::NoOpMmrTree; + // Offchain database implementation. Outgoing requests and responses are + // inserted in this database, while their commitments are stored onchain. + type OffchainDB = TransparentOffchainDB; // Weight provider for local modules type WeightProvider = (); } @@ -71,15 +71,15 @@ This component defines the state machine identifier of the supported coprocessor * `ConsensusClients`: This is a tuple of types that implement the `ConsensusClient` interface, it defines all the consensus algorithms supported by this deployment of the protocol. -* `Mmr`: - This type allows us to use mmr tree as an overlay for cheaper proofs for requests and responses instead of the merkle patricia trie proofs. +* `OffchainDB`: + This implementation provides the interface for persisting requests and responses to the offchain db. Only commitments of requests and responses are stored onchain * `Router`: The router is a type that provides an `IsmpModule` implementation for a module id. ### Router -The `IsmpRouter` is a module which produces an `IsmpModule` implementation for a given module identifier. +The `IsmpRouter` is a module which produces an `IsmpModule` implementation for a given module identifier. ```rust showLineNumbers [runtime.rs] #[derive(Default)] @@ -212,10 +212,10 @@ Should not be called on a message that has been completed (delivered or timed-ou Pallet ISMP offers a two different approaches to transaction fees. ### Unsigned - + This essentially means all cross-chain messages received are executed for free as unsigned transactions. The upside to this is that it cannot be exploited as a spam vector, since the transaction pool will check if the submitted extrinsics are valid before they are included in the pool. This validity check ensures that the transaction can be successfully executed and contains valid proofs. Malformed messages or those with invalid proofs are filtered out by the transaction pool validation logic preventing unnecessary processing and potential network congestion. -### Signed +### Signed In this method, relayers and users will need to pay the native token for executing cross-chain messages. This is likely more preferrable but requires that the token be widely available. diff --git a/modules/ismp/pallets/pallet/README.md b/modules/ismp/pallets/pallet/README.md index 8fafd3158..b2cfae4f8 100644 --- a/modules/ismp/pallets/pallet/README.md +++ b/modules/ismp/pallets/pallet/README.md @@ -82,8 +82,8 @@ impl pallet_ismp::Config for Runtime { // as an example, the parachain consensus client ismp_parachain::ParachainConsensusClient, ); - /// Offchain database implementation. Outgoing requests and responses are - /// inserted in this database, while their commitments are stored onchain. + // Offchain database implementation. Outgoing requests and responses are + // inserted in this database, while their commitments are stored onchain. type OffchainDB = TransparentOffchainDB; // Weight provider for local modules type WeightProvider = (); diff --git a/modules/ismp/pallets/pallet/src/lib.rs b/modules/ismp/pallets/pallet/src/lib.rs index 21a67b650..f99a9b707 100644 --- a/modules/ismp/pallets/pallet/src/lib.rs +++ b/modules/ismp/pallets/pallet/src/lib.rs @@ -119,7 +119,7 @@ //! ismp_parachain::ParachainConsensusClient, //! ); //! // Offchain database implementation. Outgoing requests and responses are -//! // inserted in this database, while their commitments are stored onchain. +//! // inserted in this database, while their commitments are stored onchain. //! type OffchainDB = TransparentOffchainDB; //! // Weight provider for local modules //! type WeightProvider = (); From 4287c5e2ccf90dca2948a7ab7a5e9cb6c236192f Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Sun, 8 Dec 2024 19:12:30 +0000 Subject: [PATCH 08/11] refurbish bls signature verification --- Cargo.lock | 8 +- Cargo.toml | 5 ++ evm/src/modules/GnosisUniswapV2Interface.sol | 1 - modules/consensus/bsc/verifier/Cargo.toml | 8 +- modules/consensus/bsc/verifier/src/lib.rs | 65 ++++------------ .../sync-committee/primitives/Cargo.toml | 6 -- .../sync-committee/prover/Cargo.toml | 15 +--- .../sync-committee/prover/src/lib.rs | 2 +- .../sync-committee/verifier/Cargo.toml | 9 +-- .../sync-committee/verifier/src/crypto.rs | 74 +++++-------------- .../sync-committee/verifier/src/error.rs | 2 + .../sync-committee/verifier/src/lib.rs | 19 ++++- 12 files changed, 67 insertions(+), 147 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49ce2c03c..8403578e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1662,7 +1662,6 @@ dependencies = [ "alloy-rlp", "alloy-rlp-derive", "anyhow", - "ark-bls12-381", "ark-ec", "bls_on_arkworks", "geth-primitives", @@ -23512,9 +23511,6 @@ name = "sync-committee-primitives" version = "0.1.1" dependencies = [ "anyhow", - "ark-bls12-381", - "ark-ec", - "bls_on_arkworks", "hex", "hex-literal 0.4.1", "parity-scale-codec", @@ -23529,8 +23525,6 @@ name = "sync-committee-prover" version = "0.1.1" dependencies = [ "anyhow", - "ark-bls12-381", - "ark-ec", "async-trait", "base2", "bls_on_arkworks", @@ -23560,10 +23554,10 @@ name = "sync-committee-verifier" version = "0.1.1" dependencies = [ "anyhow", - "ark-bls12-381", "ark-ec", "bls_on_arkworks", "hex", + "hex-literal 0.4.1", "log", "ssz-rs", "sync-committee-primitives", diff --git a/Cargo.toml b/Cargo.toml index eb37a2604..f891ee747 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -250,6 +250,11 @@ hex = { version = "0.4.3", default-features = false } hex-literal = "0.4.1" rlp = { version = "0.5.1", default-features = false } +# arkworks +ark-ec = { version = "0.4.2", default-features = false } +bls = { package = "bls_on_arkworks", version = "0.2.2", default-features = false } + + orml-xcm-support = { version = "=1.0.0", default-features = false } orml-traits = { version = "=1.0.0", default-features = false } primitive-types = { version = "0.12.2", default-features = false } diff --git a/evm/src/modules/GnosisUniswapV2Interface.sol b/evm/src/modules/GnosisUniswapV2Interface.sol index 95a28be3f..9f6b510c0 100644 --- a/evm/src/modules/GnosisUniswapV2Interface.sol +++ b/evm/src/modules/GnosisUniswapV2Interface.sol @@ -52,7 +52,6 @@ contract GnosisUniswapV2Interface { return out; } - /** * @dev Returns the quoted amount for the dispatch. */ diff --git a/modules/consensus/bsc/verifier/Cargo.toml b/modules/consensus/bsc/verifier/Cargo.toml index e7d4246f0..9cdfc426a 100644 --- a/modules/consensus/bsc/verifier/Cargo.toml +++ b/modules/consensus/bsc/verifier/Cargo.toml @@ -20,11 +20,10 @@ ismp = { workspace = true, default-features = false } geth-primitives = { workspace = true, default-features = false } sync-committee-verifier = { workspace = true, default-features = false } sync-committee-primitives = { workspace = true, default-features = false } -ark-bls12-381 = { version = "0.4.0", default-features = false, features = ["curve"] } -bls = { package = "bls_on_arkworks", version = "0.2.2", default-features = false } -ark-ec = { version = "0.4.2", default-features = false } -ssz-rs = { git = "https://github.com/polytope-labs/ssz-rs", branch = "main", default-features = false } +bls = { workspace = true } +ark-ec = { workspace = true } sp-runtime = { workspace = true } +ssz-rs = { git = "https://github.com/polytope-labs/ssz-rs", branch = "main", default-features = false } [features] default = ["std"] @@ -36,7 +35,6 @@ std = [ "ismp/std", "alloy-primitives/std", "alloy-rlp/std", - "ark-bls12-381/std", "bls/std", "sync-committee-verifier/std", "sync-committee-primitives/std", diff --git a/modules/consensus/bsc/verifier/src/lib.rs b/modules/consensus/bsc/verifier/src/lib.rs index 21e108b42..11d4b8748 100644 --- a/modules/consensus/bsc/verifier/src/lib.rs +++ b/modules/consensus/bsc/verifier/src/lib.rs @@ -3,20 +3,16 @@ #[warn(unused_variables)] use alloc::vec::Vec; use anyhow::anyhow; -use ark_ec::AffineRepr; +use bls::{point_to_pubkey, types::G1ProjectivePoint}; +use geth_primitives::{CodecHeader, Header}; use ismp::messaging::Keccak256; use primitives::{parse_extra, BscClientUpdate, Config, EPOCH_LENGTH, VALIDATOR_BIT_SET_SIZE}; use sp_core::H256; -use sync_committee_verifier::crypto::{pairing, pubkey_to_projective}; -pub mod primitives; -use bls::{ - point_to_pubkey, pubkey_to_point, - types::{G1AffinePoint, G1ProjectivePoint, Signature}, - DST_ETHEREUM, -}; -use geth_primitives::{CodecHeader, Header}; use ssz_rs::{Bitvector, Deserialize}; use sync_committee_primitives::constants::BlsPublicKey; +use sync_committee_verifier::crypto::pubkey_to_projective; + +pub mod primitives; extern crate alloc; @@ -69,17 +65,20 @@ pub fn verify_bsc_header( .filter_map(|(validator, bit)| if *bit { Some(validator.clone()) } else { None }) .collect(); - let aggregate_public_key = aggregate_public_keys(&participants) - .as_slice() - .try_into() - .map_err(|_| anyhow!("Could not aggregate public keys"))?; - + let aggregate_public_key = aggregate_public_keys(&participants); let msg = H::keccak256(alloy_rlp::encode(extra_data.vote_data.clone()).as_slice()); - let signature = extra_data.agg_signature; - verify_aggregate_signature(&aggregate_public_key, msg.0.to_vec(), signature.to_vec().as_ref()) - .map_err(|_| anyhow!("Could not verify aggregate signature"))?; + let verify = bls::verify( + &aggregate_public_key, + &msg.as_ref().to_vec(), + signature.to_vec().as_ref(), + &bls::DST_ETHEREUM.as_bytes().to_vec(), + ); + + if !verify { + Err(anyhow!("Could not verify aggregate signature"))? + } let next_validator_addresses: Option = // If an epoch ancestry was provided, we try to extract the next validator set from it @@ -154,35 +153,3 @@ pub fn aggregate_public_keys(keys: &[BlsPublicKey]) -> Vec { point_to_pubkey(aggregate.into()) } - -// we need a bls-utils crate -pub fn verify_aggregate_signature( - aggregate: &BlsPublicKey, - msg: Vec, - signature: &Signature, -) -> anyhow::Result<()> { - let aggregate_key_point: G1AffinePoint = - pubkey_to_point(aggregate).map_err(|_| anyhow!("Could not convert public key to point"))?; - let signature = bls::signature_to_point(signature).map_err(|e| anyhow!("{:?}", e))?; - - if !bls::signature_subgroup_check(signature) { - Err(anyhow!("Signature not in subgroup"))? - } - - let q = bls::hash_to_point(&msg, &DST_ETHEREUM.as_bytes().to_vec()); - let c1 = pairing(q, aggregate_key_point); - - // From the spec: - // > When the signature variant is minimal-pubkey-size, P is the distinguished point P1 that - // > generates the group G1. - // - let p = G1AffinePoint::generator(); - - let c2 = pairing(signature, p); - - if c1 == c2 { - Ok(()) - } else { - Err(anyhow!("Aggregate signature verification failed")) - } -} diff --git a/modules/consensus/sync-committee/primitives/Cargo.toml b/modules/consensus/sync-committee/primitives/Cargo.toml index c10c5d671..e2ad0fbf5 100644 --- a/modules/consensus/sync-committee/primitives/Cargo.toml +++ b/modules/consensus/sync-committee/primitives/Cargo.toml @@ -16,9 +16,6 @@ serde-hex-utils = { workspace = true, default-features = false } ssz-rs = { git = "https://github.com/polytope-labs/ssz-rs", branch = "main", default-features = false } -ark-ec = { version = "0.4.2", default-features = false } -ark-bls12-381 = { version = "0.4.0", default-features = false } -bls_on_arkworks = { version = "0.2.2", default-features = false } [features] default = ["std"] @@ -28,9 +25,6 @@ std = [ 'codec/std', "primitive-types/std", "anyhow/std", - "ark-ec/std", - "bls_on_arkworks/std", - "ark-bls12-381/std", "primitive-types/std", "serde", "serde-hex-utils/std" diff --git a/modules/consensus/sync-committee/prover/Cargo.toml b/modules/consensus/sync-committee/prover/Cargo.toml index da5c27905..a7867bb16 100644 --- a/modules/consensus/sync-committee/prover/Cargo.toml +++ b/modules/consensus/sync-committee/prover/Cargo.toml @@ -22,9 +22,7 @@ reqwest-middleware = "0.2.4" reqwest-chain = "0.1.0" base2 = { version= "0.3.1" } env_logger = "0.10.0" -ark-ec = { version = "0.4.2" } -ark-bls12-381 = { version = "0.4.0" } -bls_on_arkworks = { version = "0.2.2" } +bls = { workspace = true, default-features = true } async-trait = "0.1.77" tracing = "0.1.40" @@ -37,14 +35,3 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread"]} parity-scale-codec = "3.2.2" reqwest-eventsource = "0.4.0" dotenv = "0.15.0" - -[features] -default = ["std"] -std = [ - "ssz-rs/default", - "sync-committee-primitives/std", - "anyhow/std", - "ark-ec/std", - "bls_on_arkworks/std", - "ark-bls12-381/std" -] diff --git a/modules/consensus/sync-committee/prover/src/lib.rs b/modules/consensus/sync-committee/prover/src/lib.rs index c6d525fdc..702405c01 100644 --- a/modules/consensus/sync-committee/prover/src/lib.rs +++ b/modules/consensus/sync-committee/prover/src/lib.rs @@ -16,7 +16,7 @@ use crate::{ routes::*, }; use anyhow::anyhow; -use bls_on_arkworks::{point_to_pubkey, types::G1ProjectivePoint}; +use bls::{point_to_pubkey, types::G1ProjectivePoint}; use log::trace; use primitive_types::H256; use reqwest::{Client, Url}; diff --git a/modules/consensus/sync-committee/verifier/Cargo.toml b/modules/consensus/sync-committee/verifier/Cargo.toml index ae0c3e904..9ee85903a 100644 --- a/modules/consensus/sync-committee/verifier/Cargo.toml +++ b/modules/consensus/sync-committee/verifier/Cargo.toml @@ -10,9 +10,8 @@ sync-committee-primitives = { workspace = true, default-features = false } log = { workspace = true, default-features = false } anyhow = { workspace = true, default-features = false } ssz-rs = { git = "https://github.com/polytope-labs/ssz-rs", branch = "main", default-features = false } -ark-ec = { version = "0.4.2", default-features = false } -ark-bls12-381 = { version = "0.4.0", default-features = false, features = ["curve"] } -bls = { package = "bls_on_arkworks", version = "0.2.2", default-features = false } +bls = { workspace = true } +ark-ec = { workspace = true } [features] default = ["std"] @@ -22,10 +21,10 @@ std = [ "sync-committee-primitives/std", "log/std", "anyhow/std", + "bls/std", "ark-ec/std", - "ark-bls12-381/std", - "bls/std" ] [dev-dependencies] hex = "0.4.3" +hex-literal = { workspace = true, default-features = true } diff --git a/modules/consensus/sync-committee/verifier/src/crypto.rs b/modules/consensus/sync-committee/verifier/src/crypto.rs index d1602c2e5..357d74d27 100644 --- a/modules/consensus/sync-committee/verifier/src/crypto.rs +++ b/modules/consensus/sync-committee/verifier/src/crypto.rs @@ -1,11 +1,6 @@ use alloc::vec::Vec; use anyhow::anyhow; -use ark_bls12_381::Bls12_381; -use ark_ec::{pairing::Pairing, AffineRepr}; -use bls::{ - types::{BLS12381Pairing, G1AffinePoint, G1ProjectivePoint, G2AffinePoint, Signature}, - DST_ETHEREUM, -}; +use bls::types::G1ProjectivePoint; use sync_committee_primitives::constants::BlsPublicKey; pub fn pubkey_to_projective(compressed_key: &BlsPublicKey) -> anyhow::Result { @@ -14,7 +9,7 @@ pub fn pubkey_to_projective(compressed_key: &BlsPublicKey) -> anyhow::Result anyhow::Result { @@ -27,48 +22,13 @@ fn subtract_points_from_aggregate( Ok(subset_aggregate) } -pub fn pairing(u: G2AffinePoint, v: G1AffinePoint) -> BLS12381Pairing { - Bls12_381::pairing(v, u) -} - -/// Adapted from https://github.com/ArnaudBrousseau/bls_on_arkworks/blob/main/src/lib.rs#L335 -/// Verifies an aggregate bls12-381 signature from ethereum sync-committee -/// Expects signature subgroup to be valid -pub fn verify_aggregate_signature( - aggregate: &BlsPublicKey, - non_participants: &[BlsPublicKey], - msg: Vec, - signature: &Signature, -) -> anyhow::Result<()> { - let subset_aggregate = subtract_points_from_aggregate(aggregate, non_participants)?; - let aggregate_key_point: G1AffinePoint = subset_aggregate.into(); - let signature = bls::signature_to_point(signature).map_err(|e| anyhow!("{:?}", e))?; - - if !bls::signature_subgroup_check(signature) { - Err(anyhow!("Signature not in subgroup"))? - } - - let q = bls::hash_to_point(&msg, &DST_ETHEREUM.as_bytes().to_vec()); - let c1 = pairing(q, aggregate_key_point); - - // From the spec: - // > When the signature variant is minimal-pubkey-size, P is the distinguished point P1 that - // > generates the group G1. - // - let p = G1AffinePoint::generator(); - - let c2 = pairing(signature, p); - - if c1 == c2 { - Ok(()) - } else { - Err(anyhow!("Aggregate signature verification failed")) - } -} - #[cfg(test)] mod tests { - use crate::crypto::verify_aggregate_signature; + use ark_ec::CurveGroup; + use sync_committee_primitives::constants::BlsPublicKey; + + use crate::crypto::subtract_points_from_aggregate; + use hex_literal::hex; #[test] fn test_signature_verification() { @@ -89,7 +49,7 @@ mod tests { hex::decode("813a89a296973e35545cfa74fe3efd172a7d19443c97c625d699e9737229b0a2") .unwrap(); let aggregate_signature = hex::decode("a1abfcf9bd54b7a003e1f45f7543b194d8d25b816577b02ee4f1c99aa9821c620be6ecedbc8c5fab64d343a6cc832040029040e591fa24db54f5441f28d73918775e8feeac6177c9e016d2576b982d1cce453896a8aace2bda7374e5a76ce213").unwrap(); - let aggregate_pub_key = hex::decode("a3f2da752bd1dfc7288b46cc061668856e0cefa93ba6e8ff4699f355138f63a541fdb3444ddebcdce695d6313fa4b244").unwrap().try_into().unwrap(); + let aggregate_pub_key: BlsPublicKey = hex!("a3f2da752bd1dfc7288b46cc061668856e0cefa93ba6e8ff4699f355138f63a541fdb3444ddebcdce695d6313fa4b244").to_vec().try_into().unwrap(); let bit_vector = hex::decode("01000100010001000100").unwrap(); @@ -97,14 +57,18 @@ mod tests { .into_iter() .zip(bit_vector) .filter_map(|(pk, bit)| if bit == 0 { Some(pk.try_into().unwrap()) } else { None }) - .collect::>(); + .collect::>(); + + let aggregate = + subtract_points_from_aggregate(&aggregate_pub_key, &non_participants).unwrap(); - verify_aggregate_signature( - &aggregate_pub_key, - &non_participants, - message, + let verify = bls::verify( + &bls::point_to_pubkey(aggregate.into_affine()), + &message, &aggregate_signature, - ) - .unwrap() + &bls::DST_ETHEREUM.as_bytes().to_vec(), + ); + + assert!(verify, "Signature verification failed"); } } diff --git a/modules/consensus/sync-committee/verifier/src/error.rs b/modules/consensus/sync-committee/verifier/src/error.rs index a1181a531..99acc49d3 100644 --- a/modules/consensus/sync-committee/verifier/src/error.rs +++ b/modules/consensus/sync-committee/verifier/src/error.rs @@ -9,6 +9,7 @@ pub enum Error { InvalidMerkleBranch(String), InvalidRoot(String), MerkleizationError(String), + BlsError(bls::errors::BLSError), SignatureVerification, } @@ -20,6 +21,7 @@ impl Display for Error { }, Error::InvalidUpdate(err) => write!(f, "Invalid update {err:?}"), Error::DomainError => write!(f, "Couldn't get domain"), + Error::BlsError(err) => write!(f, "BlsError: {err:?}"), Error::InvalidMerkleBranch(err) => write!(f, "Invalid merkle branch {err:?}"), Error::InvalidRoot(err) => write!(f, "Invalid root {err:?}"), Error::MerkleizationError(err) => write!(f, "Merkleization error {err:?}"), diff --git a/modules/consensus/sync-committee/verifier/src/lib.rs b/modules/consensus/sync-committee/verifier/src/lib.rs index b59d59ea0..80393bb47 100644 --- a/modules/consensus/sync-committee/verifier/src/lib.rs +++ b/modules/consensus/sync-committee/verifier/src/lib.rs @@ -6,8 +6,10 @@ extern crate alloc; pub mod crypto; pub mod error; -use crate::{crypto::verify_aggregate_signature, error::Error}; +use crate::error::Error; use alloc::vec::Vec; +use ark_ec::CurveGroup; +use crypto::subtract_points_from_aggregate; use ssz_rs::{ calculate_multi_merkle_root, prelude::is_valid_merkle_branch, GeneralizedIndex, Merkleized, Node, @@ -97,14 +99,23 @@ pub fn verify_sync_committee_attestation( let signing_root = compute_signing_root(&mut update.attested_header, domain) .map_err(|_| Error::InvalidRoot("Failed to compute signing root".into()))?; - verify_aggregate_signature( + let aggregate = subtract_points_from_aggregate( &sync_committee.aggregate_public_key, &non_participant_pubkeys, - signing_root.as_bytes().to_vec(), - &update.sync_aggregate.sync_committee_signature, ) .map_err(|_| Error::SignatureVerification)?; + let verify = bls::verify( + &bls::point_to_pubkey(aggregate.into_affine()), + &signing_root.as_bytes().to_vec(), + &update.sync_aggregate.sync_committee_signature, + &bls::DST_ETHEREUM.as_bytes().to_vec(), + ); + + if !verify { + Err(Error::SignatureVerification)? + } + // Verify that the `finality_branch` confirms `finalized_header` // to match the finalized checkpoint root saved in the state of `attested_header`. // Note that the genesis finalized checkpoint root is represented as a zero hash. From 321a8e9ae18e82a22f968460a0cb1dab668f292f Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Sun, 8 Dec 2024 19:36:47 +0000 Subject: [PATCH 09/11] rename evm-common to evm-state-machine --- Cargo.lock | 20 +++++++++---------- Cargo.toml | 13 +++++------- modules/hyperclient/Cargo.toml | 2 +- modules/hyperclient/src/providers/evm.rs | 5 +++-- modules/hyperclient/src/types.rs | 1 - modules/ismp/clients/arbitrum/Cargo.toml | 4 ++-- modules/ismp/clients/arbitrum/src/lib.rs | 2 +- modules/ismp/clients/arbitrum/src/tests.rs | 2 +- modules/ismp/clients/bsc/Cargo.toml | 4 ++-- modules/ismp/clients/bsc/src/lib.rs | 2 +- modules/ismp/clients/optimism/Cargo.toml | 4 ++-- modules/ismp/clients/optimism/src/lib.rs | 2 +- .../ismp/clients/sync-committee/Cargo.toml | 4 ++-- .../sync-committee/src/beacon_client.rs | 4 ++-- modules/ismp/pallets/relayer/Cargo.toml | 4 ++-- modules/ismp/pallets/relayer/src/lib.rs | 2 +- .../ismp/pallets/state-coprocessor/Cargo.toml | 4 ++-- .../pallets/state-coprocessor/src/impls.rs | 2 +- modules/ismp/pallets/testsuite/Cargo.toml | 2 +- .../src/tests/pallet_ismp_relayer.rs | 2 +- .../evm}/Cargo.toml | 3 +-- .../evm}/src/lib.rs | 0 .../evm}/src/presets.rs | 0 .../evm}/src/types.rs | 0 .../evm}/src/utils.rs | 0 tesseract/evm/Cargo.toml | 2 +- tesseract/evm/src/lib.rs | 2 +- tesseract/evm/src/provider.rs | 2 +- tesseract/evm/src/test.rs | 2 +- 29 files changed, 46 insertions(+), 50 deletions(-) rename modules/ismp/{clients/sync-committee/evm-common => state-machines/evm}/Cargo.toml (97%) rename modules/ismp/{clients/sync-committee/evm-common => state-machines/evm}/src/lib.rs (100%) rename modules/ismp/{clients/sync-committee/evm-common => state-machines/evm}/src/presets.rs (100%) rename modules/ismp/{clients/sync-committee/evm-common => state-machines/evm}/src/types.rs (100%) rename modules/ismp/{clients/sync-committee/evm-common => state-machines/evm}/src/utils.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 8403578e6..e100f67ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -357,7 +357,7 @@ dependencies = [ "ethabi", "ethereum-triedb", "ethers", - "evm-common", + "evm-state-machine", "geth-primitives", "hex", "hex-literal 0.4.1", @@ -4809,7 +4809,7 @@ dependencies = [ ] [[package]] -name = "evm-common" +name = "evm-state-machine" version = "0.1.1" dependencies = [ "alloy-primitives", @@ -7300,7 +7300,7 @@ dependencies = [ "console_error_panic_hook", "ethereum-triedb", "ethers", - "evm-common", + "evm-state-machine", "futures", "getrandom 0.2.15", "gloo-timers 0.3.0", @@ -7713,7 +7713,7 @@ version = "0.1.1" dependencies = [ "anyhow", "bsc-verifier", - "evm-common", + "evm-state-machine", "geth-primitives", "ismp", "log", @@ -7869,7 +7869,7 @@ dependencies = [ "arbitrum-verifier", "ethabi", "ethereum-triedb", - "evm-common", + "evm-state-machine", "frame-support 37.0.0", "frame-system", "geth-primitives", @@ -11383,7 +11383,7 @@ dependencies = [ "alloy-rlp-derive", "ethabi", "ethereum-triedb", - "evm-common", + "evm-state-machine", "geth-primitives", "hex", "hex-literal 0.4.1", @@ -12283,7 +12283,7 @@ dependencies = [ "alloy-rlp-derive", "ethabi", "ethereum-triedb", - "evm-common", + "evm-state-machine", "frame-support 37.0.0", "frame-system", "hash-db", @@ -12365,7 +12365,7 @@ dependencies = [ "dotenv", "env_logger 0.11.5", "ethereum-triedb", - "evm-common", + "evm-state-machine", "frame-support 37.0.0", "frame-system", "futures", @@ -12891,7 +12891,7 @@ version = "0.1.0" dependencies = [ "alloy-primitives", "alloy-rlp", - "evm-common", + "evm-state-machine", "frame-support 37.0.0", "frame-system", "ismp", @@ -23802,7 +23802,7 @@ dependencies = [ "ethereum-triedb", "ethers", "ethers-contract-abigen", - "evm-common", + "evm-state-machine", "frame-support 37.0.0", "futures", "geth-primitives", diff --git a/Cargo.toml b/Cargo.toml index f891ee747..5e4b7e0c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,6 @@ resolver = "2" members = [ # runtime "parachain/runtimes/gargantua", -# "parachain/runtimes/messier", "parachain/runtimes/nexus", # node @@ -27,19 +26,16 @@ members = [ "modules/ismp/pallets/token-gateway-inspector", "modules/ismp/pallets/hyperbridge", "modules/ismp/pallets/state-coprocessor", - "modules/ismp/testsuite", "modules/ismp/clients/sync-committee", "modules/ismp/clients/casper-ffg", "modules/ismp/clients/parachain/client", "modules/ismp/clients/parachain/inherent", "modules/ismp/clients/parachain/runtime-api", - "modules/ismp/state-machines/substrate", - "modules/ismp/state-machines/hyperbridge", "modules/ismp/clients/arbitrum", "modules/ismp/clients/optimism", - "modules/ismp/clients/sync-committee/evm-common", "modules/ismp/clients/bsc", "modules/ismp/clients/grandpa", + "modules/ismp/testsuite", # cryptography "modules/consensus/sync-committee/prover", @@ -58,6 +54,9 @@ members = [ "modules/trees/mmr/primitives", "modules/trees/mmr/gadget", "modules/trees/mmr/pallet/runtime-api", + "modules/ismp/state-machines/evm", + "modules/ismp/state-machines/substrate", + "modules/ismp/state-machines/hyperbridge", # evm stuff "evm/integration-tests", @@ -84,8 +83,6 @@ members = [ "tesseract/telemetry", "tesseract/config", "tesseract/fisherman", - - # integration tests "tesseract/integration-test", ] @@ -295,11 +292,11 @@ ismp-parachain = { version = "1.15.1", path = "./modules/ismp/clients/parachain/ ismp-parachain-inherent = { version = "1.15.1", 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 } -evm-common = { path = "./modules/ismp/clients/sync-committee/evm-common", 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 } hyperbridge-client-machine = { path = "modules/ismp/state-machines/hyperbridge", default-features = false } diff --git a/modules/hyperclient/Cargo.toml b/modules/hyperclient/Cargo.toml index 2e919f68e..2c7301892 100644 --- a/modules/hyperclient/Cargo.toml +++ b/modules/hyperclient/Cargo.toml @@ -20,7 +20,7 @@ primitive-types = { workspace = true, features = ["serde"] } ethers = { workspace = true } ismp = { workspace = true, default-features = true } pallet-ismp = { workspace = true, features = ["disable-panic-handler"] } -evm-common = { workspace = true } +evm-state-machine = { workspace = true } sp-core = { workspace = true, features = ["serde"]} substrate-state-machine = { workspace = true } ismp-solidity-abi = { workspace = true } diff --git a/modules/hyperclient/src/providers/evm.rs b/modules/hyperclient/src/providers/evm.rs index 2a46a4cce..1956487de 100644 --- a/modules/hyperclient/src/providers/evm.rs +++ b/modules/hyperclient/src/providers/evm.rs @@ -17,7 +17,7 @@ use crate::{providers::interface::Client, types::BoxStream}; use codec::{Decode, Encode}; use ethereum_triedb::StorageProof; use ethers::prelude::Middleware; -use evm_common::{ +use evm_state_machine::{ presets::{ REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, @@ -29,7 +29,7 @@ use sp_mmr_primitives::utils::NodesUtils; use super::interface::Query; use crate::{ providers::interface::WithMetadata, - types::{EventMetadata, EvmStateProof, SubstrateStateProof}, + types::{EventMetadata, SubstrateStateProof}, }; use anyhow::{anyhow, Context, Error}; use core::time::Duration; @@ -38,6 +38,7 @@ use ethers::{ providers::{Http, Provider}, utils::keccak256, }; +use evm_state_machine::types::EvmStateProof; use futures::{stream, StreamExt}; use ismp::{ consensus::{ConsensusStateId, StateCommitment, StateMachineHeight, StateMachineId}, diff --git a/modules/hyperclient/src/types.rs b/modules/hyperclient/src/types.rs index ac620d1eb..2c03d656d 100644 --- a/modules/hyperclient/src/types.rs +++ b/modules/hyperclient/src/types.rs @@ -20,7 +20,6 @@ use crate::{ use anyhow::anyhow; use core::{fmt, pin::Pin}; use ethers::types::H160; -pub use evm_common::types::EvmStateProof; use futures::Stream; use hex_fmt::HexFmt; use ismp::{consensus::ConsensusStateId, host::StateMachine}; diff --git a/modules/ismp/clients/arbitrum/Cargo.toml b/modules/ismp/clients/arbitrum/Cargo.toml index 33a6ed19d..2804a6d72 100644 --- a/modules/ismp/clients/arbitrum/Cargo.toml +++ b/modules/ismp/clients/arbitrum/Cargo.toml @@ -12,7 +12,7 @@ publish = false ismp = { workspace = true } ethereum-triedb = { workspace = true } geth-primitives = { workspace = true } -evm-common = { workspace = true } +evm-state-machine = { workspace = true } # crates.io alloy-rlp = { workspace = true } @@ -40,5 +40,5 @@ std = [ "ethabi/std", "hex/std", "geth-primitives/std", - "evm-common/std" + "evm-state-machine/std" ] diff --git a/modules/ismp/clients/arbitrum/src/lib.rs b/modules/ismp/clients/arbitrum/src/lib.rs index c6e2b66e4..40a84f608 100644 --- a/modules/ismp/clients/arbitrum/src/lib.rs +++ b/modules/ismp/clients/arbitrum/src/lib.rs @@ -23,7 +23,7 @@ mod tests; use alloc::format; use alloy_rlp::Decodable; use ethabi::ethereum_types::{H160, H256, U256}; -use evm_common::{derive_map_key, get_contract_account, get_value_from_proof, prelude::*}; +use evm_state_machine::{derive_map_key, get_contract_account, get_value_from_proof, prelude::*}; use geth_primitives::{CodecHeader, Header}; use ismp::{ consensus::{ diff --git a/modules/ismp/clients/arbitrum/src/tests.rs b/modules/ismp/clients/arbitrum/src/tests.rs index 425b31b17..71927c96b 100644 --- a/modules/ismp/clients/arbitrum/src/tests.rs +++ b/modules/ismp/clients/arbitrum/src/tests.rs @@ -18,7 +18,7 @@ use ethers::prelude::*; use hex_literal::hex; use crate::NODES_SLOT; -use evm_common::derive_map_key; +use evm_state_machine::derive_map_key; use ismp_testsuite::mocks::Host; use sp_core::{H160, H256}; diff --git a/modules/ismp/clients/bsc/Cargo.toml b/modules/ismp/clients/bsc/Cargo.toml index 6575f7166..91320c9fd 100644 --- a/modules/ismp/clients/bsc/Cargo.toml +++ b/modules/ismp/clients/bsc/Cargo.toml @@ -18,7 +18,7 @@ ismp = { workspace = true } bsc-verifier = { workspace = true } sync-committee-primitives = { workspace = true } geth-primitives = { workspace = true } -evm-common = { workspace = true } +evm-state-machine = { workspace = true } pallet-ismp-host-executive = { workspace = true } [features] @@ -32,6 +32,6 @@ std = [ "bsc-verifier/std", "ismp/std", "sync-committee-primitives/std", - "evm-common/std", + "evm-state-machine/std", "pallet-ismp-host-executive/std" ] diff --git a/modules/ismp/clients/bsc/src/lib.rs b/modules/ismp/clients/bsc/src/lib.rs index 74807a941..bad763492 100644 --- a/modules/ismp/clients/bsc/src/lib.rs +++ b/modules/ismp/clients/bsc/src/lib.rs @@ -12,7 +12,7 @@ use bsc_verifier::{ verify_bsc_header, NextValidators, VerificationResult, }; use codec::{Decode, Encode}; -use evm_common::EvmStateMachine; +use evm_state_machine::EvmStateMachine; use geth_primitives::Header; use ismp::{ consensus::{ diff --git a/modules/ismp/clients/optimism/Cargo.toml b/modules/ismp/clients/optimism/Cargo.toml index 0e283d706..5a6733c65 100644 --- a/modules/ismp/clients/optimism/Cargo.toml +++ b/modules/ismp/clients/optimism/Cargo.toml @@ -11,7 +11,7 @@ publish = false ismp = { workspace = true } ethereum-triedb = { workspace = true } geth-primitives = { workspace = true } -evm-common = { workspace = true } +evm-state-machine = { workspace = true } # crates.io alloy-rlp = { workspace = true } @@ -35,5 +35,5 @@ std = [ "ethabi/std", "hex/std", "geth-primitives/std", - "evm-common/std" + "evm-state-machine/std" ] diff --git a/modules/ismp/clients/optimism/src/lib.rs b/modules/ismp/clients/optimism/src/lib.rs index 55c5ce1eb..d9e65f828 100644 --- a/modules/ismp/clients/optimism/src/lib.rs +++ b/modules/ismp/clients/optimism/src/lib.rs @@ -20,7 +20,7 @@ extern crate alloc; use alloc::format; use alloy_rlp::Decodable; use ethabi::ethereum_types::{H160, H256, U128, U256}; -use evm_common::{ +use evm_state_machine::{ derive_array_item_key, derive_map_key, get_contract_account, get_value_from_proof, prelude::*, }; use geth_primitives::{CodecHeader, Header}; diff --git a/modules/ismp/clients/sync-committee/Cargo.toml b/modules/ismp/clients/sync-committee/Cargo.toml index e5138975d..cc6e22e8e 100644 --- a/modules/ismp/clients/sync-committee/Cargo.toml +++ b/modules/ismp/clients/sync-committee/Cargo.toml @@ -15,7 +15,7 @@ sync-committee-verifier = { workspace = true, default-features = false } ethereum-triedb = { workspace = true, default-features = false } pallet-ismp = { workspace = true, default-features = false } geth-primitives = { workspace = true, default-features = false } -evm-common = { workspace = true } +evm-state-machine = { workspace = true } arbitrum-verifier = { workspace = true } op-verifier = { workspace = true } pallet-ismp-host-executive = { workspace = true } @@ -52,7 +52,7 @@ std = [ "sp-core/std", "pallet-ismp/std", "geth-primitives/std", - "evm-common/std", + "evm-state-machine/std", "arbitrum-verifier/std", "op-verifier/std" ] diff --git a/modules/ismp/clients/sync-committee/src/beacon_client.rs b/modules/ismp/clients/sync-committee/src/beacon_client.rs index 942a58d72..9212948bb 100644 --- a/modules/ismp/clients/sync-committee/src/beacon_client.rs +++ b/modules/ismp/clients/sync-committee/src/beacon_client.rs @@ -16,13 +16,13 @@ use alloc::{collections::BTreeMap, format, string::ToString}; use arbitrum_verifier::verify_arbitrum_payload; use codec::{Decode, Encode}; -use evm_common::construct_intermediate_state; +use evm_state_machine::construct_intermediate_state; use crate::{ pallet::{self, SupportedStatemachines}, types::{BeaconClientUpdate, ConsensusState, L2Consensus}, }; -use evm_common::EvmStateMachine; +use evm_state_machine::EvmStateMachine; use ismp::{ consensus::{ ConsensusClient, ConsensusClientId, ConsensusStateId, StateMachineClient, diff --git a/modules/ismp/pallets/relayer/Cargo.toml b/modules/ismp/pallets/relayer/Cargo.toml index 383e108b6..a758e1b40 100644 --- a/modules/ismp/pallets/relayer/Cargo.toml +++ b/modules/ismp/pallets/relayer/Cargo.toml @@ -15,7 +15,7 @@ sp-runtime = { workspace = true } sp-core = { workspace = true } sp-io = { workspace = true } pallet-ismp = { workspace = true } -evm-common = { workspace = true } +evm-state-machine = { workspace = true } pallet-ismp-host-executive = { workspace = true } pallet-hyperbridge = { workspace = true } @@ -62,7 +62,7 @@ std = [ "alloy-primitives/std", "alloy-rlp/std", "ethabi/std", - "evm-common/std", + "evm-state-machine/std", "pallet-ismp-host-executive/std" ] diff --git a/modules/ismp/pallets/relayer/src/lib.rs b/modules/ismp/pallets/relayer/src/lib.rs index 43424da3e..9fcf0c6e2 100644 --- a/modules/ismp/pallets/relayer/src/lib.rs +++ b/modules/ismp/pallets/relayer/src/lib.rs @@ -27,7 +27,7 @@ use alloc::{collections::BTreeMap, vec, vec::Vec}; use alloy_primitives::Address; use codec::Encode; use ethabi::ethereum_types::H256; -use evm_common::{ +use evm_state_machine::{ presets::{ REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, diff --git a/modules/ismp/pallets/state-coprocessor/Cargo.toml b/modules/ismp/pallets/state-coprocessor/Cargo.toml index a21d4ab83..167ff67fd 100644 --- a/modules/ismp/pallets/state-coprocessor/Cargo.toml +++ b/modules/ismp/pallets/state-coprocessor/Cargo.toml @@ -22,7 +22,7 @@ log = { workspace = true } ismp = { workspace = true } pallet-ismp = { workspace = true } mmr-primitives = { workspace = true } -evm-common = { workspace = true } +evm-state-machine = { workspace = true } pallet-ismp-relayer = { workspace = true } alloy-rlp = { workspace = true } @@ -44,7 +44,7 @@ std = [ "ismp/std", "pallet-ismp/std", "mmr-primitives/std", - "evm-common/std", + "evm-state-machine/std", "pallet-ismp-relayer/std", "alloy-primitives/std" ] diff --git a/modules/ismp/pallets/state-coprocessor/src/impls.rs b/modules/ismp/pallets/state-coprocessor/src/impls.rs index 09413a505..cfa662bf6 100644 --- a/modules/ismp/pallets/state-coprocessor/src/impls.rs +++ b/modules/ismp/pallets/state-coprocessor/src/impls.rs @@ -18,7 +18,7 @@ use super::{Config, Pallet}; use alloc::{string::ToString, vec, vec::Vec}; use codec::{Decode, Encode}; -use evm_common::{derive_unhashed_map_key, presets::REQUEST_COMMITMENTS_SLOT}; +use evm_state_machine::{derive_unhashed_map_key, presets::REQUEST_COMMITMENTS_SLOT}; use ismp::{ events::RequestResponseHandled, handlers::validate_state_machine, diff --git a/modules/ismp/pallets/testsuite/Cargo.toml b/modules/ismp/pallets/testsuite/Cargo.toml index 11cbc6982..3ff06f379 100644 --- a/modules/ismp/pallets/testsuite/Cargo.toml +++ b/modules/ismp/pallets/testsuite/Cargo.toml @@ -31,7 +31,7 @@ hash-db = { workspace = true } xcm-simulator-example = { workspace = true } xcm-simulator = { workspace = true } pallet-assets = { workspace = true, default-features = true } -evm-common = { workspace = true, default-features = true} +evm-state-machine = { workspace = true, default-features = true} ismp = { workspace = true, default-features = true } ismp-testsuite = { workspace = true, default-features = true } diff --git a/modules/ismp/pallets/testsuite/src/tests/pallet_ismp_relayer.rs b/modules/ismp/pallets/testsuite/src/tests/pallet_ismp_relayer.rs index 0f520bc3f..bb92900b1 100644 --- a/modules/ismp/pallets/testsuite/src/tests/pallet_ismp_relayer.rs +++ b/modules/ismp/pallets/testsuite/src/tests/pallet_ismp_relayer.rs @@ -18,7 +18,7 @@ use alloy_primitives::hex; use codec::{Decode, Encode}; use ethereum_triedb::{keccak::KeccakHasher, MemoryDB, StorageProof}; -use evm_common::types::EvmStateProof; +use evm_state_machine::types::EvmStateProof; use frame_support::crypto::ecdsa::ECDSAExt; use ismp::{ consensus::{StateCommitment, StateMachineHeight, StateMachineId}, diff --git a/modules/ismp/clients/sync-committee/evm-common/Cargo.toml b/modules/ismp/state-machines/evm/Cargo.toml similarity index 97% rename from modules/ismp/clients/sync-committee/evm-common/Cargo.toml rename to modules/ismp/state-machines/evm/Cargo.toml index 78e089c89..f16444205 100644 --- a/modules/ismp/clients/sync-committee/evm-common/Cargo.toml +++ b/modules/ismp/state-machines/evm/Cargo.toml @@ -1,12 +1,11 @@ [package] -name = "evm-common" +name = "evm-state-machine" version = "0.1.1" edition = "2021" description = "Contains methods and types commonly used in evm state verification" authors = ["Polytope Labs "] publish = false - [dependencies] # polytope labs ismp = { workspace = true } diff --git a/modules/ismp/clients/sync-committee/evm-common/src/lib.rs b/modules/ismp/state-machines/evm/src/lib.rs similarity index 100% rename from modules/ismp/clients/sync-committee/evm-common/src/lib.rs rename to modules/ismp/state-machines/evm/src/lib.rs diff --git a/modules/ismp/clients/sync-committee/evm-common/src/presets.rs b/modules/ismp/state-machines/evm/src/presets.rs similarity index 100% rename from modules/ismp/clients/sync-committee/evm-common/src/presets.rs rename to modules/ismp/state-machines/evm/src/presets.rs diff --git a/modules/ismp/clients/sync-committee/evm-common/src/types.rs b/modules/ismp/state-machines/evm/src/types.rs similarity index 100% rename from modules/ismp/clients/sync-committee/evm-common/src/types.rs rename to modules/ismp/state-machines/evm/src/types.rs diff --git a/modules/ismp/clients/sync-committee/evm-common/src/utils.rs b/modules/ismp/state-machines/evm/src/utils.rs similarity index 100% rename from modules/ismp/clients/sync-committee/evm-common/src/utils.rs rename to modules/ismp/state-machines/evm/src/utils.rs diff --git a/tesseract/evm/Cargo.toml b/tesseract/evm/Cargo.toml index 60febca91..34e9a70fa 100644 --- a/tesseract/evm/Cargo.toml +++ b/tesseract/evm/Cargo.toml @@ -42,7 +42,7 @@ geth-primitives = { workspace = true, default-features = true } ismp-sync-committee = { workspace = true, default-features = true } ethereum-triedb = { workspace = true, default-features = true } mmr-primitives = { workspace = true, default-features = true } -evm-common = { workspace = true, default-features = true } +evm-state-machine = { workspace = true, default-features = true } sp-mmr-primitives = { workspace = true, default-features = true } tesseract-primitives = { workspace = true, default-features = true } diff --git a/tesseract/evm/src/lib.rs b/tesseract/evm/src/lib.rs index 0a6df373e..e17d4a799 100644 --- a/tesseract/evm/src/lib.rs +++ b/tesseract/evm/src/lib.rs @@ -10,7 +10,7 @@ use ethers::{ use frame_support::crypto::ecdsa::ECDSAExt; use ismp::{consensus::ConsensusStateId, events::Event, host::StateMachine, messaging::Message}; -use evm_common::presets::{ +use evm_state_machine::presets::{ REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, }; diff --git a/tesseract/evm/src/provider.rs b/tesseract/evm/src/provider.rs index fd8bc7d5c..5829f95cc 100644 --- a/tesseract/evm/src/provider.rs +++ b/tesseract/evm/src/provider.rs @@ -11,7 +11,7 @@ use ethers::{ providers::Middleware, types::{CallFrame, GethDebugTracingCallOptions, GethTrace, GethTraceFrame}, }; -use evm_common::types::EvmStateProof; +use evm_state_machine::types::EvmStateProof; use ismp::{ consensus::{ConsensusStateId, StateMachineId}, events::{Event, StateCommitmentVetoed}, diff --git a/tesseract/evm/src/test.rs b/tesseract/evm/src/test.rs index 118f6c8e7..d3bafa1e2 100644 --- a/tesseract/evm/src/test.rs +++ b/tesseract/evm/src/test.rs @@ -1,7 +1,7 @@ use crate::{EvmClient, EvmConfig}; use codec::Decode; use ethers::providers::Middleware; -use evm_common::{ +use evm_state_machine::{ get_contract_account, get_value_from_proof, types::EvmStateProof, verify_membership, }; use hex_literal::hex; From d001abfde32879d8da6dd0e7e5ad7b1d2644ce3b Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Mon, 9 Dec 2024 08:30:00 +0000 Subject: [PATCH 10/11] bump patch versions --- Cargo.lock | 12 ++++++------ Cargo.toml | 18 ++++++++++-------- modules/ismp/pallets/hyperbridge/Cargo.toml | 2 +- modules/ismp/pallets/pallet/Cargo.toml | 2 +- modules/ismp/pallets/pallet/src/lib.rs | 16 +++++++++------- modules/ismp/pallets/rpc/Cargo.toml | 2 +- modules/ismp/pallets/runtime-api/Cargo.toml | 2 +- modules/ismp/pallets/token-gateway/Cargo.toml | 2 +- .../token-gateway/primitives/Cargo.toml | 2 +- 9 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e100f67ea..3c1230464 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12146,7 +12146,7 @@ dependencies = [ [[package]] name = "pallet-hyperbridge" -version = "1.15.1" +version = "1.15.2" dependencies = [ "anyhow", "frame-support 37.0.0", @@ -12215,7 +12215,7 @@ dependencies = [ [[package]] name = "pallet-ismp" -version = "1.15.1" +version = "1.15.2" dependencies = [ "anyhow", "env_logger 0.10.2", @@ -12310,7 +12310,7 @@ dependencies = [ [[package]] name = "pallet-ismp-rpc" -version = "1.15.1" +version = "1.15.2" dependencies = [ "anyhow", "frame-system", @@ -12339,7 +12339,7 @@ dependencies = [ [[package]] name = "pallet-ismp-runtime-api" -version = "1.15.1" +version = "1.15.2" dependencies = [ "ismp", "pallet-ismp", @@ -12981,7 +12981,7 @@ dependencies = [ [[package]] name = "pallet-token-gateway" -version = "1.15.1" +version = "1.15.2" dependencies = [ "alloy-primitives", "alloy-sol-macro", @@ -24189,7 +24189,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "token-gateway-primitives" -version = "1.15.1" +version = "1.15.2" dependencies = [ "alloy-primitives", "alloy-sol-macro", diff --git a/Cargo.toml b/Cargo.toml index 5e4b7e0c3..962d0981f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -264,7 +264,7 @@ jsonrpsee = { version = "0.23" } jsonrpsee-core = { version = "0.23" } # local crates -ismp = { version = "0.2.1", path = "./modules/ismp/core", default-features = false } +ismp = { version = "0.2.2", path = "./modules/ismp/core", default-features = false } ismp-testsuite = { path = "./modules/ismp/testsuite" } ismp-solidity-abi = { path = "./evm/abi", default-features = false } simnode-tests = { path = "parachain/simtests" } @@ -300,11 +300,15 @@ evm-state-machine = { path = "./modules/ismp/state-machines/evm", default-featur substrate-state-machine = { version = "1.15.1", path = "modules/ismp/state-machines/substrate", default-features = false } hyperbridge-client-machine = { path = "modules/ismp/state-machines/hyperbridge", default-features = false } -# pallets -pallet-ismp = { version = "1.15.1", path = "modules/ismp/pallets/pallet", default-features = false } -pallet-ismp-rpc = { version = "1.15.1", path = "modules/ismp/pallets/rpc" } -pallet-ismp-runtime-api = { version = "1.15.1", path = "modules/ismp/pallets/runtime-api", default-features = false } -pallet-hyperbridge = { version = "1.15.1", path = "modules/ismp/pallets/hyperbridge", default-features = false } +# published pallets +pallet-ismp = { version = "1.15.2", path = "modules/ismp/pallets/pallet", default-features = false } +pallet-ismp-rpc = { version = "1.15.2", path = "modules/ismp/pallets/rpc" } +pallet-ismp-runtime-api = { version = "1.15.2", path = "modules/ismp/pallets/runtime-api", default-features = false } +pallet-hyperbridge = { version = "1.15.2", path = "modules/ismp/pallets/hyperbridge", default-features = false } +pallet-token-gateway = { version = "1.15.2", path = "modules/ismp/pallets/token-gateway", default-features = false } +token-gateway-primitives = { version = "1.15.2", path = "modules/ismp/pallets/token-gateway/primitives", default-features = false } + +# ismp modules pallet-fishermen = { path = "modules/ismp/pallets/fishermen", default-features = false } pallet-ismp-demo = { path = "modules/ismp/pallets/demo", default-features = false } pallet-ismp-relayer = { path = "modules/ismp/pallets/relayer", default-features = false } @@ -314,8 +318,6 @@ pallet-xcm-gateway = { path = "modules/ismp/pallets/asset-gateway", default-feat pallet-token-governor = { path = "modules/ismp/pallets/token-governor", default-features = false } pallet-state-coprocessor = { path = "modules/ismp/pallets/state-coprocessor", default-features = false } pallet-mmr = { path = "modules/trees/mmr/pallet", default-features = false } -pallet-token-gateway = { version = "1.15.1", path = "modules/ismp/pallets/token-gateway", default-features = false } -token-gateway-primitives = { version = "1.15.1", path = "modules/ismp/pallets/token-gateway/primitives", default-features = false } pallet-token-gateway-inspector = { path = "modules/ismp/pallets/token-gateway-inspector", default-features = false } # merkle trees diff --git a/modules/ismp/pallets/hyperbridge/Cargo.toml b/modules/ismp/pallets/hyperbridge/Cargo.toml index ef0689686..c2b756469 100644 --- a/modules/ismp/pallets/hyperbridge/Cargo.toml +++ b/modules/ismp/pallets/hyperbridge/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-hyperbridge" -version = "1.15.1" +version = "1.15.2" edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" diff --git a/modules/ismp/pallets/pallet/Cargo.toml b/modules/ismp/pallets/pallet/Cargo.toml index 0083d08d4..15835da3d 100644 --- a/modules/ismp/pallets/pallet/Cargo.toml +++ b/modules/ismp/pallets/pallet/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-ismp" -version = "1.15.1" +version = "1.15.2" edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" diff --git a/modules/ismp/pallets/pallet/src/lib.rs b/modules/ismp/pallets/pallet/src/lib.rs index f99a9b707..3f1f7964b 100644 --- a/modules/ismp/pallets/pallet/src/lib.rs +++ b/modules/ismp/pallets/pallet/src/lib.rs @@ -84,7 +84,7 @@ //! use frame_support::parameter_types; //! use frame_system::EnsureRoot; //! use ismp::Error; -//! use pallet_ismp::NoOpMmrTree; +//! use pallet_ismp::TransparentOffchainDB; //! use ismp::host::StateMachine; //! use ismp::module::IsmpModule; //! use ismp::router::{IsmpRouter, Post, Response, Timeout}; @@ -534,8 +534,9 @@ pub mod pallet { let metadata = match message.commitment { MessageCommitment::Request(commitment) => RequestCommitments::::get(commitment), - MessageCommitment::Response(commitment) => - ResponseCommitments::::get(commitment), + MessageCommitment::Response(commitment) => { + ResponseCommitments::::get(commitment) + }, }; let Some(mut metadata) = metadata else { @@ -685,10 +686,11 @@ pub mod pallet { // check that requests will be successfully dispatched // so we can not be spammed with failing txs .map(|result| match result { - MessageResult::Request(results) | - MessageResult::Response(results) | - MessageResult::Timeout(results) => - results.into_iter().map(|result| result.map(|_| ())).collect::>(), + MessageResult::Request(results) + | MessageResult::Response(results) + | MessageResult::Timeout(results) => { + results.into_iter().map(|result| result.map(|_| ())).collect::>() + }, MessageResult::ConsensusMessage(_) | MessageResult::FrozenClient(_) => { vec![Ok(())] }, diff --git a/modules/ismp/pallets/rpc/Cargo.toml b/modules/ismp/pallets/rpc/Cargo.toml index a96e9675d..f91fa3f06 100644 --- a/modules/ismp/pallets/rpc/Cargo.toml +++ b/modules/ismp/pallets/rpc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-ismp-rpc" -version = "1.15.1" +version = "1.15.2" edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" diff --git a/modules/ismp/pallets/runtime-api/Cargo.toml b/modules/ismp/pallets/runtime-api/Cargo.toml index e54a5eb9f..e74e6b502 100644 --- a/modules/ismp/pallets/runtime-api/Cargo.toml +++ b/modules/ismp/pallets/runtime-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-ismp-runtime-api" -version = "1.15.1" +version = "1.15.2" edition = "2021" authors = ["Polytope Labs "] license = "Apache-2.0" diff --git a/modules/ismp/pallets/token-gateway/Cargo.toml b/modules/ismp/pallets/token-gateway/Cargo.toml index 8a0f78288..8ff40a254 100644 --- a/modules/ismp/pallets/token-gateway/Cargo.toml +++ b/modules/ismp/pallets/token-gateway/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-token-gateway" -version = "1.15.1" +version = "1.15.2" edition = "2021" description = "A substrate implementation of the token gateway protocol" authors = ["Polytope Labs "] diff --git a/modules/ismp/pallets/token-gateway/primitives/Cargo.toml b/modules/ismp/pallets/token-gateway/primitives/Cargo.toml index db6cddddc..3b8300cbe 100644 --- a/modules/ismp/pallets/token-gateway/primitives/Cargo.toml +++ b/modules/ismp/pallets/token-gateway/primitives/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "token-gateway-primitives" -version = "1.15.1" +version = "1.15.2" edition = "2021" description = "A collection of types used by token gateway" authors = ["Polytope Labs "] From d57f735617dec00bdff4e9c34d9b10528b17ad27 Mon Sep 17 00:00:00 2001 From: Seun Lanlege Date: Mon, 9 Dec 2024 08:43:23 +0000 Subject: [PATCH 11/11] some more misc fixes --- .../sync-committee/verifier/src/crypto.rs | 10 ++++------ .../sync-committee/verifier/src/error.rs | 6 ++++++ .../sync-committee/verifier/src/lib.rs | 3 +-- modules/ismp/pallets/pallet/README.md | 4 ++-- modules/ismp/pallets/pallet/src/lib.rs | 18 ++++++++---------- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/modules/consensus/sync-committee/verifier/src/crypto.rs b/modules/consensus/sync-committee/verifier/src/crypto.rs index 357d74d27..d7d3f2eca 100644 --- a/modules/consensus/sync-committee/verifier/src/crypto.rs +++ b/modules/consensus/sync-committee/verifier/src/crypto.rs @@ -1,18 +1,16 @@ use alloc::vec::Vec; -use anyhow::anyhow; -use bls::types::G1ProjectivePoint; +use bls::{errors::BLSError, types::G1ProjectivePoint}; use sync_committee_primitives::constants::BlsPublicKey; -pub fn pubkey_to_projective(compressed_key: &BlsPublicKey) -> anyhow::Result { - let affine_point = - bls::pubkey_to_point(&compressed_key.to_vec()).map_err(|e| anyhow!("{:?}", e))?; +pub fn pubkey_to_projective(compressed_key: &BlsPublicKey) -> Result { + let affine_point = bls::pubkey_to_point(&compressed_key.to_vec())?; Ok(affine_point.into()) } pub fn subtract_points_from_aggregate( aggregate: &BlsPublicKey, points: &[BlsPublicKey], -) -> anyhow::Result { +) -> Result { let aggregate = pubkey_to_projective(aggregate)?; let points = points .iter() diff --git a/modules/consensus/sync-committee/verifier/src/error.rs b/modules/consensus/sync-committee/verifier/src/error.rs index 99acc49d3..db933c08c 100644 --- a/modules/consensus/sync-committee/verifier/src/error.rs +++ b/modules/consensus/sync-committee/verifier/src/error.rs @@ -13,6 +13,12 @@ pub enum Error { SignatureVerification, } +impl From for Error { + fn from(value: bls::errors::BLSError) -> Self { + Error::BlsError(value) + } +} + impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { match self { diff --git a/modules/consensus/sync-committee/verifier/src/lib.rs b/modules/consensus/sync-committee/verifier/src/lib.rs index 80393bb47..231fd7830 100644 --- a/modules/consensus/sync-committee/verifier/src/lib.rs +++ b/modules/consensus/sync-committee/verifier/src/lib.rs @@ -102,8 +102,7 @@ pub fn verify_sync_committee_attestation( let aggregate = subtract_points_from_aggregate( &sync_committee.aggregate_public_key, &non_participant_pubkeys, - ) - .map_err(|_| Error::SignatureVerification)?; + )?; let verify = bls::verify( &bls::point_to_pubkey(aggregate.into_affine()), diff --git a/modules/ismp/pallets/pallet/README.md b/modules/ismp/pallets/pallet/README.md index b2cfae4f8..1cde2b1af 100644 --- a/modules/ismp/pallets/pallet/README.md +++ b/modules/ismp/pallets/pallet/README.md @@ -82,8 +82,8 @@ impl pallet_ismp::Config for Runtime { // as an example, the parachain consensus client ismp_parachain::ParachainConsensusClient, ); - // Offchain database implementation. Outgoing requests and responses are - // inserted in this database, while their commitments are stored onchain. + // Offchain database implementation. Outgoing requests and responses are + // inserted in this database, while their commitments are stored onchain. type OffchainDB = TransparentOffchainDB; // Weight provider for local modules type WeightProvider = (); diff --git a/modules/ismp/pallets/pallet/src/lib.rs b/modules/ismp/pallets/pallet/src/lib.rs index 3f1f7964b..1422c3044 100644 --- a/modules/ismp/pallets/pallet/src/lib.rs +++ b/modules/ismp/pallets/pallet/src/lib.rs @@ -119,7 +119,7 @@ //! ismp_parachain::ParachainConsensusClient, //! ); //! // Offchain database implementation. Outgoing requests and responses are -//! // inserted in this database, while their commitments are stored onchain. +//! // inserted in this database, while their commitments are stored onchain. //! type OffchainDB = TransparentOffchainDB; //! // Weight provider for local modules //! type WeightProvider = (); @@ -161,7 +161,7 @@ //! //! /// Called by the ISMP hanlder, to notify module of requests that were previously //! /// sent but have now timed-out -//! fn on_timeout(&self, request: Timeout) -> Result<(), Error> { +//! fn on_timeout(&self, request: Timeout) -> Result<(), Error> { //! // revert any state changes that were made prior to dispatching the request //! Ok(()) //! } @@ -534,9 +534,8 @@ pub mod pallet { let metadata = match message.commitment { MessageCommitment::Request(commitment) => RequestCommitments::::get(commitment), - MessageCommitment::Response(commitment) => { - ResponseCommitments::::get(commitment) - }, + MessageCommitment::Response(commitment) => + ResponseCommitments::::get(commitment), }; let Some(mut metadata) = metadata else { @@ -686,11 +685,10 @@ pub mod pallet { // check that requests will be successfully dispatched // so we can not be spammed with failing txs .map(|result| match result { - MessageResult::Request(results) - | MessageResult::Response(results) - | MessageResult::Timeout(results) => { - results.into_iter().map(|result| result.map(|_| ())).collect::>() - }, + MessageResult::Request(results) | + MessageResult::Response(results) | + MessageResult::Timeout(results) => + results.into_iter().map(|result| result.map(|_| ())).collect::>(), MessageResult::ConsensusMessage(_) | MessageResult::FrozenClient(_) => { vec![Ok(())] },