diff --git a/Cargo.lock b/Cargo.lock index 032a06c77..9a1edf6e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,11 +235,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4436e0292ab1bb631b42973c61205e704475fe8126af845c8d923c0996328127" -[[package]] -name = "amcl" -version = "0.3.0" -source = "git+https://github.com/sigp/milagro_bls#d3fc0a40cfe8b72ccda46ba050ee6786a59ce753" - [[package]] name = "android-tzdata" version = "0.1.1" @@ -333,6 +328,124 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" +[[package]] +name = "ark-bls12-381" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c775f0d12169cba7aae4caeb547bb6a50781c7449a8aa53793827c9ec4abf488" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", +] + +[[package]] +name = "ark-ec" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" +dependencies = [ + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", + "itertools 0.10.5", + "num-traits", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "digest 0.10.7", + "itertools 0.10.5", + "num-bigint", + "num-traits", + "paste", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-poly" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-serialize-derive", + "ark-std", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + [[package]] name = "array-bytes" version = "4.2.0" @@ -830,6 +943,23 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" +[[package]] +name = "bls_on_arkworks" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffc35f5286b3fa350a0a77df5166c034c5a12dc4a3ee13bf2126ac9e9109ef8e" +dependencies = [ + "ark-bls12-381", + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", + "hkdf", + "hmac 0.12.1", + "libm", + "sha2 0.10.7", +] + [[package]] name = "bounded-collections" version = "0.1.8" @@ -2938,21 +3068,6 @@ dependencies = [ "tiny-keccak", ] -[[package]] -name = "ethereum-consensus" -version = "0.1.1" -source = "git+https://github.com/polytope-labs/ethereum-consensus?branch=main#48335b5c8074d63553ee4681993e294eba947f88" -dependencies = [ - "bs58 0.4.0", - "hashbrown 0.13.2", - "integer-sqrt", - "milagro_bls", - "multihash 0.16.3", - "rand 0.8.5", - "sha2 0.9.9", - "ssz-rs", -] - [[package]] name = "ethereum-trie" version = "0.1.0" @@ -6166,16 +6281,6 @@ dependencies = [ "thrift", ] -[[package]] -name = "milagro_bls" -version = "1.5.1" -source = "git+https://github.com/sigp/milagro_bls#d3fc0a40cfe8b72ccda46ba050ee6786a59ce753" -dependencies = [ - "amcl", - "rand 0.8.5", - "zeroize", -] - [[package]] name = "mime" version = "0.3.17" @@ -13225,12 +13330,15 @@ dependencies = [ [[package]] name = "ssz-rs" version = "0.8.0" -source = "git+https://github.com/polytope-labs/ssz-rs?branch=main#96f9a89ccc56ab2abb4c3a83eaedb415034ada49" +source = "git+https://github.com/polytope-labs/ssz-rs?branch=main#81e9f63c93ca33f5f484ac301553f04912f2de23" dependencies = [ "as-any", "bitvec", + "hex", "itertools 0.10.5", "num-bigint", + "parity-scale-codec", + "serde", "sha2 0.9.9", "ssz-rs-derive", ] @@ -13238,7 +13346,7 @@ dependencies = [ [[package]] name = "ssz-rs-derive" version = "0.8.0" -source = "git+https://github.com/polytope-labs/ssz-rs?branch=main#96f9a89ccc56ab2abb4c3a83eaedb415034ada49" +source = "git+https://github.com/polytope-labs/ssz-rs?branch=main#81e9f63c93ca33f5f484ac301553f04912f2de23" dependencies = [ "proc-macro2", "quote", @@ -13548,20 +13656,29 @@ dependencies = [ [[package]] name = "sync-committee-primitives" version = "0.1.0" -source = "git+https://github.com/polytope-labs/sync-committee-rs?branch=main#c5afca4fbb92cb60dde29c3a89454c288b022d97" +source = "git+https://github.com/polytope-labs/sync-committee-rs?branch=main#13f2034529aa2be5e6bc59d11c1586b0ce3d2fe1" dependencies = [ - "ethereum-consensus", + "anyhow", + "ark-bls12-381", + "ark-ec", + "bls_on_arkworks", + "hex", "hex-literal 0.4.1", "parity-scale-codec", + "primitive-types", + "serde", "ssz-rs", ] [[package]] name = "sync-committee-verifier" version = "0.1.0" -source = "git+https://github.com/polytope-labs/sync-committee-rs?branch=main#c5afca4fbb92cb60dde29c3a89454c288b022d97" +source = "git+https://github.com/polytope-labs/sync-committee-rs?branch=main#13f2034529aa2be5e6bc59d11c1586b0ce3d2fe1" dependencies = [ - "ethereum-consensus", + "anyhow", + "ark-bls12-381", + "ark-ec", + "bls_on_arkworks", "log", "ssz-rs", "sync-committee-primitives", diff --git a/parachain/modules/consensus/sync-committee/src/beacon_client.rs b/parachain/modules/consensus/sync-committee/src/beacon_client.rs index 527bba5b8..302cfa1e8 100644 --- a/parachain/modules/consensus/sync-committee/src/beacon_client.rs +++ b/parachain/modules/consensus/sync-committee/src/beacon_client.rs @@ -26,15 +26,14 @@ use crate::{ prelude::*, utils::{get_value_from_proof, get_values_from_proof}, }; -use sync_committee_verifier::BlsVerify; pub const BEACON_CONSENSUS_ID: ConsensusClientId = *b"BEAC"; #[derive(Default, Clone)] -pub struct SyncCommitteeConsensusClient(core::marker::PhantomData, V); +pub struct SyncCommitteeConsensusClient(core::marker::PhantomData); -impl ConsensusClient - for SyncCommitteeConsensusClient +impl ConsensusClient + for SyncCommitteeConsensusClient { fn verify_consensus( &self, @@ -66,12 +65,11 @@ impl ConsensusClien )) })?; - let new_light_client_state = - sync_committee_verifier::verify_sync_committee_attestation::( - no_codec_light_client_state, - no_codec_light_client_update, - ) - .map_err(|_| Error::ConsensusProofVerificationFailed { id: BEACON_CONSENSUS_ID })?; + let new_light_client_state = sync_committee_verifier::verify_sync_committee_attestation( + no_codec_light_client_state, + no_codec_light_client_update, + ) + .map_err(|_| Error::ConsensusProofVerificationFailed { id: BEACON_CONSENSUS_ID })?; let mut state_machine_map: BTreeMap> = BTreeMap::new(); @@ -82,7 +80,7 @@ impl ConsensusClien BEACON_CONSENSUS_ID, consensus_update.execution_payload.block_number, consensus_update.execution_payload.timestamp, - &state_root, + &state_root[..], )?; let ethereum_state_commitment_height = StateCommitmentHeight { @@ -98,7 +96,7 @@ impl ConsensusClien if let Some(optimism_payload) = optimism_payload { let state = verify_optimism_payload::( optimism_payload, - &state_root, + &state_root[..], consensus_state.l2_oracle_address, )?; @@ -114,7 +112,7 @@ impl ConsensusClien if let Some(arbitrum_payload) = arbitrum_payload { let state = verify_arbitrum_payload::( arbitrum_payload, - &state_root, + &state_root[..], consensus_state.rollup_core_address, )?; diff --git a/parachain/modules/consensus/sync-committee/src/lib.rs b/parachain/modules/consensus/sync-committee/src/lib.rs index f58eb428a..734187ce1 100644 --- a/parachain/modules/consensus/sync-committee/src/lib.rs +++ b/parachain/modules/consensus/sync-committee/src/lib.rs @@ -17,3 +17,5 @@ pub mod presets; mod tests; pub mod types; pub mod utils; + +pub use beacon_client::*; diff --git a/parachain/modules/consensus/sync-committee/src/types.rs b/parachain/modules/consensus/sync-committee/src/types.rs index e72692607..dd085c3ce 100644 --- a/parachain/modules/consensus/sync-committee/src/types.rs +++ b/parachain/modules/consensus/sync-committee/src/types.rs @@ -6,7 +6,7 @@ use ethabi::ethereum_types::{H160, H256}; use hash256_std_hasher::Hash256StdHasher; use hash_db::Hasher; use ismp::host::{IsmpHost, StateMachine}; -use sync_committee_primitives::derived_types::{LightClientState, LightClientUpdate}; +use sync_committee_primitives::types::{LightClientState, LightClientUpdate}; pub struct KeccakHasher(core::marker::PhantomData); diff --git a/parachain/runtime/src/lib.rs b/parachain/runtime/src/lib.rs index fd36e7c9c..172fa3561 100644 --- a/parachain/runtime/src/lib.rs +++ b/parachain/runtime/src/lib.rs @@ -495,21 +495,18 @@ pub struct ConsensusProvider; impl ConsensusClientProvider for ConsensusProvider { fn consensus_client(id: ConsensusClientId) -> Result, Error> { - let client = match id { + match id { ismp_parachain::consensus::PARACHAIN_CONSENSUS_ID => { let parachain = ParachainConsensusClient::::default(); - Box::new(parachain) + Ok(Box::new(parachain)) + }, + ismp_sync_committee::BEACON_CONSENSUS_ID => { + let sync_committee = + ismp_sync_committee::SyncCommitteeConsensusClient::>::default(); + Ok(Box::new(sync_committee)) }, - // ismp_sync_committee::BEACON_CONSENSUS_ID => { - // use ismp_sync_committee::{SignatureVerifier, SyncCommitteeConsensusClient}; - // let sync_committee = - // SyncCommitteeConsensusClient::, SignatureVerifier>::default(); - // Box::new(sync_committee) - // }, _ => Err(Error::ImplementationSpecific("Unknown consensus client".into()))?, - }; - - Ok(client) + } } }