From b812c781e45d26af796c03eedc0422a450b76ce6 Mon Sep 17 00:00:00 2001 From: Jeff Zhao Date: Mon, 6 Nov 2023 17:26:49 -0500 Subject: [PATCH] add fork_version field --- src/client/guardian.rs | 7 ++++++- src/client/keygen.rs | 3 +++ src/client/secure_signer.rs | 7 ++++++- src/client/tests/guardian.rs | 3 +++ src/client/tests/mod.rs | 4 ++++ src/client/tests/validator.rs | 4 ++++ src/client/validator.rs | 7 ++++++- src/enclave/types.rs | 1 + src/enclave/validator/handlers/attest_fresh_bls_key.rs | 2 +- 9 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/client/guardian.rs b/src/client/guardian.rs index 30dc96f..ceb55ba 100644 --- a/src/client/guardian.rs +++ b/src/client/guardian.rs @@ -7,7 +7,12 @@ pub struct GuardianClient { impl GuardianClient { pub async fn health(&self) -> bool { - let Ok(resp) = self.client.get(format!("{}/upcheck", self.url)).send().await else { + let Ok(resp) = self + .client + .get(format!("{}/upcheck", self.url)) + .send() + .await + else { return false; }; resp.status() == reqwest::StatusCode::OK diff --git a/src/client/keygen.rs b/src/client/keygen.rs index 9e5ab65..530ae76 100644 --- a/src/client/keygen.rs +++ b/src/client/keygen.rs @@ -77,6 +77,8 @@ fn generate_bls_keystore( #[cfg(test)] mod tests { + use crate::eth2::eth_types::GENESIS_FORK_VERSION; + use super::*; #[test] @@ -91,6 +93,7 @@ mod tests { guardian_pubkeys: vec![g_pk.clone()], withdrawal_credentials: withdrawal_credentials.clone(), threshold, + fork_version: GENESIS_FORK_VERSION, do_remote_attestation: false, }; let payload = generate_bls_keystore_handler(payload, &password).unwrap(); diff --git a/src/client/secure_signer.rs b/src/client/secure_signer.rs index b77bc1d..e1e449a 100644 --- a/src/client/secure_signer.rs +++ b/src/client/secure_signer.rs @@ -7,7 +7,12 @@ pub struct SecureSignerClient { impl SecureSignerClient { pub async fn health(&self) -> bool { - let Ok(resp) = self.client.get(format!("{}/upcheck", self.url)).send().await else { + let Ok(resp) = self + .client + .get(format!("{}/upcheck", self.url)) + .send() + .await + else { return false; }; resp.status() == reqwest::StatusCode::OK diff --git a/src/client/tests/guardian.rs b/src/client/tests/guardian.rs index ac8b39d..aeb14c3 100644 --- a/src/client/tests/guardian.rs +++ b/src/client/tests/guardian.rs @@ -1,3 +1,5 @@ +use crate::eth2::eth_types::GENESIS_FORK_VERSION; + #[tokio::test] async fn call_health_with_success() { let client = super::build_client(); @@ -49,6 +51,7 @@ async fn call_validate_custody_with_success() { guardian_pubkeys: g_pks, withdrawal_credentials: [1; 32], threshold: 7, + fork_version: GENESIS_FORK_VERSION, do_remote_attestation: false, }; diff --git a/src/client/tests/mod.rs b/src/client/tests/mod.rs index ef0ad63..fd33557 100644 --- a/src/client/tests/mod.rs +++ b/src/client/tests/mod.rs @@ -2,6 +2,8 @@ mod guardian; mod secure_signer; mod validator; +use crate::eth2::eth_types::GENESIS_FORK_VERSION; + fn build_client() -> super::Client { let builder = super::ClientBuilder::new(); builder @@ -44,6 +46,7 @@ async fn registration_flow_succeeds() { guardian_pubkeys: vec![guardian_pk.clone()], withdrawal_credentials: withdrawal_credentials.clone(), threshold: threshold, + fork_version: GENESIS_FORK_VERSION, do_remote_attestation: verify_remote_attestation, }; @@ -108,6 +111,7 @@ async fn test_cli_keygen_verified_by_guardians() { guardian_pubkeys: vec![guardian_pk.clone()], withdrawal_credentials: withdrawal_credentials.clone(), threshold: threshold, + fork_version: GENESIS_FORK_VERSION, do_remote_attestation: verify_remote_attestation, }; let bls_keygen_payload = dbg!(crate::client::keygen::generate_bls_keystore_handler( diff --git a/src/client/tests/validator.rs b/src/client/tests/validator.rs index 49dedd7..fa1921d 100644 --- a/src/client/tests/validator.rs +++ b/src/client/tests/validator.rs @@ -1,3 +1,5 @@ +use crate::eth2::eth_types::GENESIS_FORK_VERSION; + #[tokio::test] async fn call_health_with_success() { let client = super::build_client(); @@ -16,6 +18,7 @@ async fn call_attest_fresh_bls_key_with_success() { ], withdrawal_credentials: [0; 32], threshold: 3, + fork_version: GENESIS_FORK_VERSION, do_remote_attestation: true, }; client @@ -52,6 +55,7 @@ async fn call_attest_fresh_bls_key_and_decrypt() { guardian_pubkeys: g_pks, withdrawal_credentials: [1; 32], threshold: 3, + fork_version: GENESIS_FORK_VERSION, do_remote_attestation: true, }; diff --git a/src/client/validator.rs b/src/client/validator.rs index 99ba31a..697bf24 100644 --- a/src/client/validator.rs +++ b/src/client/validator.rs @@ -6,7 +6,12 @@ pub struct ValidatorClient { impl ValidatorClient { pub async fn health(&self) -> bool { - let Ok(resp) = self.client.get(format!("{}/upcheck", self.url)).send().await else { + let Ok(resp) = self + .client + .get(format!("{}/upcheck", self.url)) + .send() + .await + else { return false; }; resp.status() == reqwest::StatusCode::OK diff --git a/src/enclave/types.rs b/src/enclave/types.rs index 9c52261..511e7b8 100644 --- a/src/enclave/types.rs +++ b/src/enclave/types.rs @@ -310,6 +310,7 @@ pub struct AttestFreshBlsKeyPayload { )] pub withdrawal_credentials: [u8; 32], pub threshold: usize, + pub fork_version: crate::eth2::eth_types::Version, pub do_remote_attestation: bool, } diff --git a/src/enclave/validator/handlers/attest_fresh_bls_key.rs b/src/enclave/validator/handlers/attest_fresh_bls_key.rs index c4d0667..89d5212 100644 --- a/src/enclave/validator/handlers/attest_fresh_bls_key.rs +++ b/src/enclave/validator/handlers/attest_fresh_bls_key.rs @@ -9,7 +9,7 @@ pub async fn handler( keygen_payload.withdrawal_credentials, keygen_payload.guardian_pubkeys, keygen_payload.threshold, - crate::eth2::eth_types::GENESIS_FORK_VERSION, + keygen_payload.fork_version, keygen_payload.do_remote_attestation, ) { Ok(keygen_result) => {