Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Update constants for mainnet and goerli (#31)
Browse files Browse the repository at this point in the history
* fix constants

* nit
  • Loading branch information
Wizdave97 authored Sep 30, 2023
1 parent 106f53e commit c22405c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 58 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ std = [
"serde"
]
mainnet = []
testnet = []
goerli = []
28 changes: 14 additions & 14 deletions primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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")]
Expand All @@ -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")))]
Expand Down
3 changes: 2 additions & 1 deletion prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]

63 changes: 23 additions & 40 deletions prover/src/test.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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::<Http>::connect(EL_NODE_URL).await;
let sub = provider.watch_blocks().await.unwrap();
let _ = sub.take(blocks).collect::<Vec<_>>();
}

#[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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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,
Expand Down Expand Up @@ -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());
}
Expand All @@ -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;
Expand All @@ -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());
}
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit c22405c

Please sign in to comment.