diff --git a/Cargo.lock b/Cargo.lock index 881214b..c60772b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -830,6 +830,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "dunce" version = "1.0.4" @@ -3385,6 +3391,7 @@ dependencies = [ "async-stream", "base2", "bls_on_arkworks", + "dotenv", "env_logger", "ethers", "hex", diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index f80ade7..17fa0fa 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -33,4 +33,4 @@ std = [ "serde" ] mainnet = [] -testnet = [] +goerli = [] diff --git a/primitives/src/constants.rs b/primitives/src/constants.rs index 04c2430..0934398 100644 --- a/primitives/src/constants.rs +++ b/primitives/src/constants.rs @@ -76,7 +76,7 @@ pub const BLOCK_ROOTS_INDEX_LOG2: u64 = 5; pub const HISTORICAL_ROOTS_INDEX_LOG2: u64 = 5; #[cfg(feature = "testnet")] -pub use testnet::*; +pub use goerli::*; #[cfg(feature = "mainnet")] pub use mainnet::*; @@ -85,19 +85,19 @@ use crate::ssz::ByteVector; #[cfg(all(not(feature = "mainnet"), not(feature = "testnet")))] pub use devnet::*; -#[cfg(feature = "testnet")] -pub mod testnet { +#[cfg(feature = "goerli")] +pub mod goerli { use super::*; pub const SLOTS_PER_EPOCH: Slot = 32; pub const GENESIS_VALIDATORS_ROOT: [u8; 32] = - hex_literal::hex!("4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95"); - pub const BELLATRIX_FORK_VERSION: Version = [3, 0, 16, 32]; - pub const ALTAIR_FORK_VERSION: Version = [1, 0, 16, 32]; - pub const GENESIS_FORK_VERSION: Version = [0; 4]; + hex_literal::hex!("043db0d9a83813551ee2f33450d23797757d430911a9320530ad8a0eabc43efb"); + pub const BELLATRIX_FORK_VERSION: Version = hex_literal::hex!("02001020"); + pub const ALTAIR_FORK_VERSION: Version = hex_literal::hex!("01001020"); + pub const GENESIS_FORK_VERSION: Version = hex_literal::hex!("00001020"); pub const ALTAIR_FORK_EPOCH: Epoch = 36660; pub const BELLATRIX_FORK_EPOCH: Epoch = 112260; - pub const CAPELLA_FORK_EPOCH: Epoch = u64::MAX; - pub const CAPELLA_FORK_VERSION: Version = [3, 0, 16, 32]; + pub const CAPELLA_FORK_EPOCH: Epoch = 162304; + pub const CAPELLA_FORK_VERSION: Version = hex_literal::hex!("03001020"); } #[cfg(feature = "mainnet")] @@ -106,13 +106,13 @@ pub mod mainnet { pub const SLOTS_PER_EPOCH: Slot = 32; pub const GENESIS_VALIDATORS_ROOT: [u8; 32] = hex_literal::hex!("4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95"); - pub const BELLATRIX_FORK_VERSION: Version = [2, 0, 0, 0]; - pub const ALTAIR_FORK_VERSION: Version = [1, 0, 0, 0]; - pub const GENESIS_FORK_VERSION: Version = [0, 0, 0, 0]; + pub const BELLATRIX_FORK_VERSION: Version = hex_literal::hex!("02000000"); + pub const ALTAIR_FORK_VERSION: Version = hex_literal::hex!("01000000"); + pub const GENESIS_FORK_VERSION: Version = hex_literal::hex!("00000000"); pub const ALTAIR_FORK_EPOCH: Epoch = 74240; pub const BELLATRIX_FORK_EPOCH: Epoch = 144896; - pub const CAPELLA_FORK_EPOCH: Epoch = u64::MAX; - pub const CAPELLA_FORK_VERSION: Version = [3, 0, 0, 0]; + pub const CAPELLA_FORK_EPOCH: Epoch = 194048; + pub const CAPELLA_FORK_VERSION: Version = hex_literal::hex!("03000000"); } #[cfg(all(not(feature = "mainnet"), not(feature = "testnet")))] diff --git a/prover/Cargo.toml b/prover/Cargo.toml index 21ae744..5dca6e3 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -34,6 +34,7 @@ ethers = { version = "2.0.8", features = ["ws"] } tokio = { version = "1.32.0", features = ["macros", "rt-multi-thread"]} parity-scale-codec = "3.2.2" reqwest-eventsource = "0.4.0" +dotenv = "0.15.0" [features] default = ["std"] @@ -45,6 +46,6 @@ std = [ "bls_on_arkworks/std", "ark-bls12-381/std" ] -testnet = ["sync-committee-primitives/testnet", "sync-committee-verifier/testnet"] +goerli = ["sync-committee-primitives/goerli", "sync-committee-verifier/goerli"] mainnet = ["sync-committee-primitives/mainnet", "sync-committee-verifier/mainnet"] diff --git a/prover/src/test.rs b/prover/src/test.rs index de293a4..a8cd07e 100644 --- a/prover/src/test.rs +++ b/prover/src/test.rs @@ -1,9 +1,5 @@ use super::*; use base2::Base2; -use ethers::{ - prelude::{Http, Middleware, ProviderExt}, - providers::Provider, -}; use reqwest_eventsource::EventSource; use ssz_rs::{ calculate_multi_merkle_root, get_generalized_index, is_valid_merkle_branch, GeneralizedIndex, @@ -23,21 +19,11 @@ use sync_committee_verifier::{ }; use tokio_stream::StreamExt; -const CONSENSUS_NODE_URL: &'static str = "http://localhost:3500"; -const EL_NODE_URL: &'static str = "http://localhost:8545"; - -async fn wait_for_el(blocks: usize) { - let provider = Provider::::connect(EL_NODE_URL).await; - let sub = provider.watch_blocks().await.unwrap(); - let _ = sub.take(blocks).collect::>(); -} - #[cfg(test)] #[allow(non_snake_case)] #[tokio::test] async fn fetch_block_header_works() { - wait_for_el(1).await; - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); let block_header = sync_committee_prover.fetch_header("head").await; assert!(block_header.is_ok()); } @@ -46,8 +32,7 @@ async fn fetch_block_header_works() { #[allow(non_snake_case)] #[tokio::test] async fn fetch_block_works() { - wait_for_el(1).await; - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); let block = sync_committee_prover.fetch_block("head").await; assert!(block.is_ok()); } @@ -56,8 +41,7 @@ async fn fetch_block_works() { #[allow(non_snake_case)] #[tokio::test] async fn fetch_validator_works() { - wait_for_el(1).await; - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); let validator = sync_committee_prover.fetch_validator("head", "0").await; assert!(validator.is_ok()); } @@ -67,8 +51,7 @@ async fn fetch_validator_works() { #[tokio::test] #[ignore] async fn fetch_processed_sync_committee_works() { - wait_for_el(1).await; - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); let validator = sync_committee_prover.fetch_processed_sync_committee("head").await; assert!(validator.is_ok()); } @@ -78,7 +61,7 @@ async fn fetch_processed_sync_committee_works() { #[tokio::test] #[ignore] async fn generate_indexes() { - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); let beacon_state = sync_committee_prover.fetch_beacon_state("head").await.unwrap(); let execution_payload_index = get_generalized_index( &beacon_state, @@ -114,8 +97,7 @@ async fn generate_indexes() { #[allow(non_snake_case)] #[tokio::test] async fn fetch_beacon_state_works() { - wait_for_el(1).await; - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); let beacon_state = sync_committee_prover.fetch_beacon_state("head").await; assert!(beacon_state.is_ok()); } @@ -124,8 +106,7 @@ async fn fetch_beacon_state_works() { #[allow(non_snake_case)] #[tokio::test] async fn state_root_and_block_header_root_matches() { - wait_for_el(1).await; - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); let mut beacon_state = sync_committee_prover.fetch_beacon_state("head").await.unwrap(); let block_header = sync_committee_prover.fetch_header(&beacon_state.slot.to_string()).await; @@ -141,8 +122,7 @@ async fn state_root_and_block_header_root_matches() { #[allow(non_snake_case)] #[tokio::test] async fn fetch_finality_checkpoints_work() { - wait_for_el(1).await; - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); let finality_checkpoint = sync_committee_prover.fetch_finalized_checkpoint().await; assert!(finality_checkpoint.is_ok()); } @@ -151,8 +131,7 @@ async fn fetch_finality_checkpoints_work() { #[allow(non_snake_case)] #[tokio::test] async fn test_finalized_header() { - wait_for_el(1).await; - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); let mut state = sync_committee_prover.fetch_beacon_state("head").await.unwrap(); let proof = ssz_rs::generate_proof(&mut state, &vec![FINALIZED_ROOT_INDEX as usize]).unwrap(); @@ -177,9 +156,9 @@ async fn test_finalized_header() { #[cfg(test)] #[allow(non_snake_case)] #[tokio::test] +#[ignore] async fn test_execution_payload_proof() { - wait_for_el(10).await; - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); let mut finalized_state = sync_committee_prover.fetch_beacon_state("head").await.unwrap(); let block_id = finalized_state.slot.to_string(); @@ -229,8 +208,7 @@ async fn test_execution_payload_proof() { #[allow(non_snake_case)] #[tokio::test] async fn test_sync_committee_update_proof() { - wait_for_el(1).await; - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); let mut finalized_state = sync_committee_prover.fetch_beacon_state("head").await.unwrap(); let block_id = finalized_state.slot.to_string(); @@ -269,11 +247,10 @@ async fn test_prover() { .filter_module("prover", LevelFilter::Debug) .format_module_path(false) .init(); - wait_for_el(1).await; - let node_url = format!("{}/eth/v1/events?topics=finalized_checkpoint", CONSENSUS_NODE_URL); - - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); + let node_url = + format!("{}/eth/v1/events?topics=finalized_checkpoint", sync_committee_prover.node_url); let block_header = sync_committee_prover.fetch_header("head").await.unwrap(); let state = sync_committee_prover @@ -339,8 +316,7 @@ async fn test_prover() { #[allow(non_snake_case)] #[tokio::test] async fn test_sync_committee_signature_verification() { - wait_for_el(1).await; - let sync_committee_prover = SyncCommitteeProver::new(CONSENSUS_NODE_URL.to_string()); + let sync_committee_prover = setup_prover(); let block = loop { let block = sync_committee_prover.fetch_block("head").await.unwrap(); if block.slot < 16 { @@ -398,3 +374,10 @@ pub struct EventResponse { pub epoch: String, pub execution_optimistic: bool, } + +fn setup_prover() -> SyncCommitteeProver { + dotenv::dotenv().ok(); + let consensus_url = + std::env::var("CONSENSUS_NODE_URL").unwrap_or("http://localhost:3500".to_string()); + SyncCommitteeProver::new(consensus_url) +} diff --git a/verifier/Cargo.toml b/verifier/Cargo.toml index 2bfc475..8d2a6bb 100644 --- a/verifier/Cargo.toml +++ b/verifier/Cargo.toml @@ -10,7 +10,7 @@ ssz-rs = { git = "https://github.com/polytope-labs/ssz-rs", branch = "main" , de log = { version = "0.4.17", default-features = false } anyhow = { version = "1.0.75", default-features = false } ark-ec = { version = "0.4.2", default-features = false } -ark-bls12-381 = { version = "0.4.0", default-features = false } +ark-bls12-381 = { version = "0.4.0", default-features = false, features = ["curve"] } bls_on_arkworks = { version = "0.2.2", default-features = false } [features] @@ -25,7 +25,7 @@ std = [ "ark-bls12-381/std", "bls_on_arkworks/std" ] -testnet = ["sync-committee-primitives/testnet"] +goerli = ["sync-committee-primitives/goerli"] mainnet = ["sync-committee-primitives/mainnet"] [dev-dependencies]