From d46a65a463509099707e75836b7c460e6f566d61 Mon Sep 17 00:00:00 2001 From: mikhailUshakoff Date: Sun, 5 Jan 2025 00:59:45 +0100 Subject: [PATCH 1/5] Use blst crate for bls-service --- Node/Cargo.lock | 1 + Node/Cargo.toml | 1 + Node/src/bls/mod.rs | 102 +++++++++--------------- Node/src/ethereum_l1/execution_layer.rs | 35 ++++---- Node/src/mev_boost/constraints.rs | 28 +++++-- Node/src/mev_boost/mod.rs | 2 +- Node/src/registration/tests.rs | 4 +- 7 files changed, 83 insertions(+), 90 deletions(-) diff --git a/Node/Cargo.lock b/Node/Cargo.lock index 1aef33b..b8483f8 100644 --- a/Node/Cargo.lock +++ b/Node/Cargo.lock @@ -7755,6 +7755,7 @@ dependencies = [ "beacon-api-client", "bincode", "bls_on_arkworks", + "blst", "chrono", "clap", "dotenv", diff --git a/Node/Cargo.toml b/Node/Cargo.toml index ae73e25..dbc1f4e 100644 --- a/Node/Cargo.toml +++ b/Node/Cargo.toml @@ -42,6 +42,7 @@ rand = "0.8" tree_hash = "0.6.0" tree_hash_derive = "0.6.0" reth-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "5dd5555c5c7d8e43420e273e7005b8af63a847a5" } +blst = "0.3" [dev-dependencies] mockall_double = "0.3" diff --git a/Node/src/bls/mod.rs b/Node/src/bls/mod.rs index 79a97f4..f1b3751 100644 --- a/Node/src/bls/mod.rs +++ b/Node/src/bls/mod.rs @@ -1,10 +1,7 @@ use alloy::primitives::U256; use anyhow::Error; -use bls::types::{G1AffinePoint, G2AffinePoint, PublicKey, SecretKey, Signature}; -use bls_on_arkworks as bls; -use ethereum_consensus::crypto::{PublicKey as EthereumPublicKey, SecretKey as EthereumSecretKey}; -use ethereum_consensus::primitives::BlsSignature; -use num_bigint::BigUint; + +use blst::min_pk::{PublicKey, SecretKey, Signature}; #[cfg(test)] #[cfg(not(feature = "use_mock"))] use rand_core::{OsRng, RngCore}; @@ -12,87 +9,66 @@ use rand_core::{OsRng, RngCore}; pub struct BLSService { pk: PublicKey, sk: SecretKey, - eth_secret_key: EthereumSecretKey, - eth_public_key: EthereumPublicKey, } impl BLSService { pub fn new(private_key: &str) -> Result { let pk_bytes = alloy::hex::decode(private_key) - .map_err(|e| anyhow::anyhow!("BLSService: failed to decode private key: {}", e))?; - let sk = bls::os2ip(&pk_bytes); - let public_key = bls::sk_to_pk(sk); - - let eth_secret_key = EthereumSecretKey::try_from(private_key.to_string()) - .map_err(|e| anyhow::anyhow!("Invalid secret key: {:?}", e))?; - let eth_public_key = eth_secret_key.public_key(); - - tracing::info!( - "BLSService: public key: {}", - hex::encode(public_key.clone()) - ); - - Ok(Self { - pk: public_key, - sk, - eth_public_key, - eth_secret_key, - }) + .map_err(|e| anyhow::anyhow!("BLSService: failed to decode secret key: {}", e))?; + let sk = SecretKey::from_bytes(&pk_bytes).map_err(|e| { + anyhow::anyhow!( + "BLSService: failed to create secret key from bytes: {:?}", + e + ) + })?; + let pk = sk.sk_to_pk(); + + Ok(Self { pk, sk }) } #[cfg(test)] #[cfg(not(feature = "use_mock"))] - pub fn generate_key() -> Self { + pub fn generate_key() -> Result { let mut ikm = [0u8; 64]; OsRng.fill_bytes(&mut ikm); - let sk = bls::keygen(&ikm.to_vec()); - let pk = bls::sk_to_pk(sk); - - let eth_secret_key = EthereumSecretKey::random(&mut OsRng).unwrap(); - let eth_public_key = eth_secret_key.public_key(); - - Self { - pk, - sk, - eth_public_key, - eth_secret_key, - } - } + let sk = SecretKey::key_gen(&ikm.to_vec(), &[]) + .map_err(|e| anyhow::anyhow!("BLSService: failed to generate secret key: {:?}", e))?; + let pk = sk.sk_to_pk(); - pub fn sign(&self, message: &Vec, dst: &Vec) -> Signature { - bls::sign(self.sk, message, dst).unwrap() + Ok(Self { pk, sk }) } - pub fn sign_as_point(&self, message: &Vec, dst: &Vec) -> G2AffinePoint { - let sign = self.sign(message, dst); - bls::signature_to_point(&sign).unwrap() + pub fn sign(&self, message: &[u8], dst: &[u8]) -> Signature { + self.sk.sign(message, dst, &[]) } - pub fn biguint_to_u256_array(biguint: BigUint) -> [U256; 2] { - let s = format!("{:0>96x}", biguint); - let res1 = U256::from_str_radix(&s[0..32], 16).unwrap(); - let res2 = U256::from_str_radix(&s[32..96], 16).unwrap(); - + fn to_contract_layout(value: &[u8; 48]) -> [U256; 2] { + let mut buffer = [0u8; 32]; + buffer[16..32].copy_from_slice(&value[0..16]); + let res1: alloy::primitives::Uint<256, 4> = U256::from_be_bytes::<32>(buffer); + let res2: alloy::primitives::Uint<256, 4> = + U256::from_be_bytes::<32>(value[16..48].try_into().unwrap()); [res1, res2] } - #[cfg(test)] - #[cfg(not(feature = "use_mock"))] - pub fn get_public_key_compressed(&self) -> PublicKey { - self.pk.clone() + pub fn pubkey_to_g1_point(&self) -> [[U256; 2]; 2] { + let pk = self.get_public_key().serialize(); + let x = Self::to_contract_layout(pk[0..48].try_into().unwrap()); + let y = Self::to_contract_layout(pk[48..96].try_into().unwrap()); + return [x, y]; } - pub fn get_public_key(&self) -> G1AffinePoint { - bls::pubkey_to_point(&self.pk).unwrap() + pub fn signature_to_g2_point(&self, signature: &Signature) -> [[U256; 2]; 4] { + let signature = signature.serialize(); + let x = Self::to_contract_layout(signature[0..48].try_into().unwrap()); + let x_i = Self::to_contract_layout(signature[48..96].try_into().unwrap()); + let y = Self::to_contract_layout(signature[96..144].try_into().unwrap()); + let y_i = Self::to_contract_layout(signature[144..192].try_into().unwrap()); + return [x, x_i, y, y_i]; } - pub fn get_ethereum_public_key(&self) -> EthereumPublicKey { - self.eth_public_key.clone() - } - - pub fn sign_with_ethereum_secret_key(&self, message: &[u8]) -> Result { - let signature = self.eth_secret_key.sign(message); - Ok(signature) + pub fn get_public_key(&self) -> PublicKey { + self.pk.clone() } } diff --git a/Node/src/ethereum_l1/execution_layer.rs b/Node/src/ethereum_l1/execution_layer.rs index 371ca75..8a084ca 100644 --- a/Node/src/ethereum_l1/execution_layer.rs +++ b/Node/src/ethereum_l1/execution_layer.rs @@ -28,7 +28,6 @@ use futures_util::StreamExt; use k256::Secp256k1; #[cfg(test)] use mockall::automock; -use num_bigint::BigUint; use rand_core::{OsRng, RngCore}; use std::str::FromStr; use std::sync::Arc; @@ -622,20 +621,21 @@ impl ExecutionLayer { let message = data.abi_encode_packed(); // Convert bls public key to G1Point - let pk_point = self.bls_service.get_public_key(); + let pk_point = self.bls_service.pubkey_to_g1_point(); let pubkey = PreconfRegistry::G1Point { - x: BLSService::biguint_to_u256_array(BigUint::from(pk_point.x)), - y: BLSService::biguint_to_u256_array(BigUint::from(pk_point.y)), + x: pk_point[0], + y: pk_point[1], }; + let signature = self.bls_service.sign(&message, &vec![]); // Sign message and convert to G2Point - let signature_point = self.bls_service.sign_as_point(&message, &vec![]); + let signature_point = self.bls_service.signature_to_g2_point(&signature); let signature = PreconfRegistry::G2Point { - x: BLSService::biguint_to_u256_array(BigUint::from(signature_point.x.c0)), - x_I: BLSService::biguint_to_u256_array(BigUint::from(signature_point.x.c1)), - y: BLSService::biguint_to_u256_array(BigUint::from(signature_point.y.c0)), - y_I: BLSService::biguint_to_u256_array(BigUint::from(signature_point.y.c1)), + x: signature_point[0], + x_I: signature_point[1], + y: signature_point[2], + y_I: signature_point[3], }; // Call contract @@ -680,20 +680,21 @@ impl ExecutionLayer { let message = data.abi_encode_packed(); // Convert bls public key to G1Point - let pk_point = self.bls_service.get_public_key(); + let pk_point = self.bls_service.pubkey_to_g1_point(); let pubkey = PreconfRegistry::G1Point { - x: BLSService::biguint_to_u256_array(BigUint::from(pk_point.x)), - y: BLSService::biguint_to_u256_array(BigUint::from(pk_point.y)), + x: pk_point[0], + y: pk_point[1], }; + let signature = self.bls_service.sign(&message, &vec![]); // Sign message and convert to G2Point - let signature_point = self.bls_service.sign_as_point(&message, &vec![]); + let signature_point = self.bls_service.signature_to_g2_point(&signature); let signature = PreconfRegistry::G2Point { - x: BLSService::biguint_to_u256_array(BigUint::from(signature_point.x.c0)), - x_I: BLSService::biguint_to_u256_array(BigUint::from(signature_point.x.c1)), - y: BLSService::biguint_to_u256_array(BigUint::from(signature_point.y.c0)), - y_I: BLSService::biguint_to_u256_array(BigUint::from(signature_point.y.c1)), + x: signature_point[0], + x_I: signature_point[1], + y: signature_point[2], + y_I: signature_point[3], }; // Call contract diff --git a/Node/src/mev_boost/constraints.rs b/Node/src/mev_boost/constraints.rs index 86e2b15..f29aaf7 100644 --- a/Node/src/mev_boost/constraints.rs +++ b/Node/src/mev_boost/constraints.rs @@ -1,10 +1,10 @@ use crate::bls::BLSService; use alloy::signers::k256::sha2::{Digest, Sha256}; use anyhow::Error; -use ethereum_consensus::crypto::PublicKey; -use ethereum_consensus::primitives::BlsSignature; +use blst::min_pk::{PublicKey, Signature}; use ethereum_consensus::state_transition::Context; use reth_primitives::PooledTransactionsElement; +use serde::ser::Serializer; use serde::Serialize; use std::sync::Arc; use tree_hash::TreeHash; @@ -12,14 +12,22 @@ use tree_hash_derive::TreeHash; pub const GENESIS_VALIDATORS_ROOT: [u8; 32] = [0; 32]; pub const COMMIT_BOOST_DOMAIN: [u8; 4] = [109, 109, 111, 67]; +const BLS_DST: &[u8] = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_"; #[derive(Debug, Clone, Serialize, Eq, PartialEq)] pub struct ConstraintsMessage { + #[serde(serialize_with = "serialize_publickey")] pub pubkey: PublicKey, pub slot: u64, pub top: bool, pub transactions: Vec>, } +fn serialize_publickey(data: &PublicKey, serializer: S) -> Result +where + S: Serializer, +{ + serializer.serialize_bytes(&data.serialize()) +} impl ConstraintsMessage { pub fn new(pubkey: PublicKey, slot: u64, transactions: Vec>) -> Self { @@ -33,7 +41,7 @@ impl ConstraintsMessage { fn digest(&self) -> Result<[u8; 32], Error> { let mut hasher = Sha256::new(); - hasher.update(self.pubkey.to_vec()); + hasher.update(self.pubkey.compress()); hasher.update(self.slot.to_le_bytes()); hasher.update((self.top as u8).to_le_bytes()); for tx in self.transactions.iter() { @@ -50,7 +58,15 @@ impl ConstraintsMessage { #[derive(Debug, Clone, Serialize)] pub struct SignedConstraints { pub message: ConstraintsMessage, - pub signature: BlsSignature, + #[serde(serialize_with = "serialize_signature")] + pub signature: Signature, +} + +fn serialize_signature(data: &Signature, serializer: S) -> Result +where + S: Serializer, +{ + serializer.serialize_bytes(&data.serialize()) } impl SignedConstraints { @@ -108,9 +124,7 @@ impl SignedConstraints { let signing_root = Self::compute_signing_root_custom(digest.tree_hash_root().0, domain); // Sign message - let signature = bls - .sign_with_ethereum_secret_key(&signing_root) - .map_err(|e| anyhow::anyhow!("Sign_with_domain error: {}", e))?; + let signature = bls.sign(&signing_root, BLS_DST); Ok(Self { message, signature }) } diff --git a/Node/src/mev_boost/mod.rs b/Node/src/mev_boost/mod.rs index a7a2647..0d679bd 100644 --- a/Node/src/mev_boost/mod.rs +++ b/Node/src/mev_boost/mod.rs @@ -48,7 +48,7 @@ impl MevBoost { bls_service: Arc, ) -> Result<(), Error> { // Prepare the message - let pubkey = bls_service.get_ethereum_public_key(); + let pubkey = bls_service.get_public_key(); let message = ConstraintsMessage::new(pubkey, slot_id, constraints); let signed = SignedConstraints::new(message, bls_service, self.genesis_fork_version)?; diff --git a/Node/src/registration/tests.rs b/Node/src/registration/tests.rs index ec683ee..ef773ad 100644 --- a/Node/src/registration/tests.rs +++ b/Node/src/registration/tests.rs @@ -156,7 +156,7 @@ mod tests { let preconf_task_manager = get_contract_address(&output, "Preconf Task Manager"); // Create a new BLSService with a random private key - let bls_service = Arc::new(BLSService::generate_key()); + let bls_service = Arc::new(BLSService::generate_key().unwrap()); // Create AVS contract addresses let avs_contracts = AvsContractAddresses { @@ -221,7 +221,7 @@ mod tests { } // Copy logic form smart contract to get public key hash - let pk_compressed = bls_service.get_public_key_compressed(); + let pk_compressed = bls_service.get_public_key().compress(); let mut res_arr: [u8; 32] = [0; 32]; res_arr[16..32].copy_from_slice(&pk_compressed[0..16]); let res1 = U256::from_be_bytes(res_arr); From eccd0ec9ba622b5cbcc555cb14c271eae7da667b Mon Sep 17 00:00:00 2001 From: mikhailUshakoff Date: Sun, 5 Jan 2025 01:05:17 +0100 Subject: [PATCH 2/5] Update Cargo.toml --- Node/Cargo.lock | 133 +++--------------------------------------------- Node/Cargo.toml | 4 -- 2 files changed, 7 insertions(+), 130 deletions(-) diff --git a/Node/Cargo.lock b/Node/Cargo.lock index b8483f8..ddda898 100644 --- a/Node/Cargo.lock +++ b/Node/Cargo.lock @@ -143,11 +143,11 @@ dependencies = [ [[package]] name = "alloy-chains" -version = "0.1.51" +version = "0.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4e0f0136c085132939da6b753452ebed4efaa73fe523bb855b10c199c2ebfaf" +checksum = "56f15afc5993458b42739ab3b69bdb6b4c8112acd3997dbea9bc092c9517137c" dependencies = [ - "alloy-primitives 0.8.16", + "alloy-primitives 0.8.18", "num_enum", "strum 0.26.3", ] @@ -364,29 +364,17 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.16" +version = "0.8.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0540fd0355d400b59633c27bd4b42173e59943f28e9d3376b77a24771d432d04" +checksum = "788bb18e8f61d5d9340b52143f27771daf7e1dccbaf2741621d2493f9debf52e" dependencies = [ - "alloy-rlp", "bytes", "cfg-if", "const-hex", "derive_more 1.0.0", - "foldhash", - "hashbrown 0.15.2", - "hex-literal", - "indexmap 2.7.0", "itoa", - "k256 0.13.4", - "keccak-asm", "paste", - "proptest", - "rand 0.8.5", "ruint", - "rustc-hash 2.1.0", - "serde", - "sha3", "tiny-keccak", ] @@ -854,35 +842,6 @@ version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" -[[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 0.4.2", - "ark-serialize 0.4.2", - "ark-std 0.4.0", -] - -[[package]] -name = "ark-ec" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" -dependencies = [ - "ark-ff 0.4.2", - "ark-poly", - "ark-serialize 0.4.2", - "ark-std 0.4.0", - "derivative", - "hashbrown 0.13.2", - "itertools 0.10.5", - "num-traits", - "zeroize", -] - [[package]] name = "ark-ff" version = "0.3.0" @@ -966,19 +925,6 @@ dependencies = [ "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 0.4.2", - "ark-serialize 0.4.2", - "ark-std 0.4.0", - "derivative", - "hashbrown 0.13.2", -] - [[package]] name = "ark-serialize" version = "0.3.0" @@ -995,23 +941,11 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" dependencies = [ - "ark-serialize-derive", "ark-std 0.4.0", "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.3.0" @@ -1602,23 +1536,6 @@ dependencies = [ "piper", ] -[[package]] -name = "bls_on_arkworks" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4107cadb31de0d0c1282dd57efe395706b1d81feb697799871f95c3324af7c44" -dependencies = [ - "ark-bls12-381", - "ark-ec", - "ark-ff 0.4.2", - "ark-serialize 0.4.2", - "ark-std 0.4.0", - "hkdf", - "hmac 0.12.1", - "libm", - "sha2 0.10.8", -] - [[package]] name = "blst" version = "0.3.13" @@ -2701,29 +2618,6 @@ dependencies = [ "sha2 0.10.8", ] -[[package]] -name = "ethereum_ssz" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e999563461faea0ab9bc0024e5e66adcee35881f3d5062f52f31a4070fe1522" -dependencies = [ - "alloy-primitives 0.8.16", - "itertools 0.13.0", - "smallvec", -] - -[[package]] -name = "ethereum_ssz_derive" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3deae99c8e74829a00ba7a92d49055732b3c1f093f2ccfa3cbc621679b6fa91" -dependencies = [ - "darling 0.20.10", - "proc-macro2", - "quote", - "syn 2.0.94", -] - [[package]] name = "ethers-core" version = "2.0.14" @@ -3224,15 +3118,6 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hashbrown" version = "0.14.5" @@ -7754,7 +7639,6 @@ dependencies = [ "anyhow", "beacon-api-client", "bincode", - "bls_on_arkworks", "blst", "chrono", "clap", @@ -7762,8 +7646,6 @@ dependencies = [ "ecdsa 0.16.9", "elliptic-curve 0.13.8", "ethereum-consensus", - "ethereum_ssz", - "ethereum_ssz_derive", "futures-util", "hex", "jsonrpsee", @@ -7772,7 +7654,6 @@ dependencies = [ "mockall", "mockall_double", "mockito", - "num-bigint", "p2p-network", "rand 0.8.5", "rand_core 0.6.4", @@ -8811,9 +8692,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.21" +version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6f5bb5257f2407a5425c6e749bfd9692192a73e70a6060516ac04f889087d68" +checksum = "39281189af81c07ec09db316b302a3e67bf9bd7cbf6c820b50e35fee9c2fa980" dependencies = [ "memchr", ] diff --git a/Node/Cargo.toml b/Node/Cargo.toml index dbc1f4e..762942d 100644 --- a/Node/Cargo.toml +++ b/Node/Cargo.toml @@ -34,10 +34,6 @@ bincode = "1.3" serde_bytes = "0.11" clap = "4.5" futures-util = "0.3" -ethereum_ssz = "0.7" -ethereum_ssz_derive = "0.7" -bls_on_arkworks = "0.3.0" -num-bigint = "0.4.6" rand = "0.8" tree_hash = "0.6.0" tree_hash_derive = "0.6.0" From 70d31695b33d445c5777f273987090baa2498711 Mon Sep 17 00:00:00 2001 From: mikhailUshakoff Date: Sun, 5 Jan 2025 11:04:00 +0100 Subject: [PATCH 3/5] Fix constraints serialization --- Node/src/mev_boost/constraints.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Node/src/mev_boost/constraints.rs b/Node/src/mev_boost/constraints.rs index f29aaf7..f3382ef 100644 --- a/Node/src/mev_boost/constraints.rs +++ b/Node/src/mev_boost/constraints.rs @@ -26,7 +26,8 @@ fn serialize_publickey(data: &PublicKey, serializer: S) -> Result(data: &Signature, serializer: S) -> Result Date: Sun, 5 Jan 2025 12:25:30 +0100 Subject: [PATCH 4/5] Add tests --- Node/src/mev_boost/constraints.rs | 36 +++++++++++++++++++++++++++++++ Node/src/mev_boost/mod.rs | 23 ++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/Node/src/mev_boost/constraints.rs b/Node/src/mev_boost/constraints.rs index f3382ef..c0ddcf7 100644 --- a/Node/src/mev_boost/constraints.rs +++ b/Node/src/mev_boost/constraints.rs @@ -131,3 +131,39 @@ impl SignedConstraints { Ok(Self { message, signature }) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_constraints_message_digest() { + let constraints = vec![vec![2,249,3,213,131,48,24,36,6,132,59,154,202,0,133,4,168,23,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,188,101,74,119,65,102,81,67,67,47,47,104,55,117,72,107,67,43,72,97,68,65,111,120,89,65,89,82,51,78,90,81,65,104,81,98,56,73,54,119,65,103,119,77,48,85,74,82,83,107,97,85,53,70,48,101,70,43,116,121,84,55,47,54,99,110,79,116,54,86,72,71,97,53,73,99,86,85,80,102,99,112,119,65,65,103,77,65,66,111,75,114,75,88,82,69,106,104,98,106,115,115,104,112,50,119,104,83,102,54,47,117,79,101,70,110,69,82,56,113,57,52,99,80,119,103,120,116,108,51,110,79,78,111,67,82,115,53,98,70,52,108,87,85,113,101,118,122,121,109,106,50,75,81,71,74,106,57,117,87,54,107,110,74,101,85,86,68,112,47,81,43,83,65,49,78,74,65,81,65,65,47,47,56,97,57,84,57,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,1,160,175,154,114,57,217,247,104,167,114,56,70,166,250,175,140,155,4,255,254,185,177,119,184,80,186,72,127,32,38,28,186,156,160,63,77,214,119,203,52,47,233,31,158,227,102,147,186,40,117,153,98,44,15,194,109,222,72,181,48,135,170,91,85,51,123]]; + let slot_id = 17; + let pubkey = PublicKey::from_bytes(&alloy::hex::decode("908d6f98b5eaf6ac1b632c6b80b304612d48afd9c104874f9025960accdae128028119608b0d95a7e141390101fba669").unwrap()).unwrap(); + + let message = ConstraintsMessage::new(pubkey, slot_id, constraints); + + assert_eq!(message.digest().unwrap(),[9, 87, 0, 71, 187, 129, 0, 133, 126, 114, 244, 187, 129, 105, 194, 105, 195, 115, 27, 220, 144, 157, 88, 34, 184, 108, 130, 34, 84, 248, 88, 125]); + } + + #[test] + fn test_signed_constraints_compute_domain_custom() { + let mut context = Context::for_minimal(); + context.genesis_fork_version = [16, 0, 0, 56]; + + let domain = SignedConstraints::compute_domain_custom(&context, COMMIT_BOOST_DOMAIN); + + assert_eq!(domain, [109, 109, 111, 67, 11, 65, 190, 76, 219, 52, 209, 131, 221, 220, 165, 57, 131, 55, 98, 109, 205, 207, 175, 23, 32, 193, 32, 45, 59, 149, 248, 78]); + } + + #[test] + fn test_signed_constraints_compute_signing_root_custom() { + let digest = [9, 87, 0, 71, 187, 129, 0, 133, 126, 114, 244, 187, 129, 105, 194, 105, 195, 115, 27, 220, 144, 157, 88, 34, 184, 108, 130, 34, 84, 248, 88, 125]; + let domain = [109, 109, 111, 67, 11, 65, 190, 76, 219, 52, 209, 131, 221, 220, 165, 57, 131, 55, 98, 109, 205, 207, 175, 23, 32, 193, 32, 45, 59, 149, 248, 78]; + + let signing_root = SignedConstraints::compute_signing_root_custom(digest.tree_hash_root().0, domain); + + assert_eq!(signing_root, [46, 115, 119, 45, 23, 162, 89, 198, 203, 58, 165, 97, 28, 21, 0, 117, 149, 27, 106, 219, 120, 115, 115, 227, 114, 157, 221, 247, 183, 14, 65, 54]); + } +} \ No newline at end of file diff --git a/Node/src/mev_boost/mod.rs b/Node/src/mev_boost/mod.rs index 0d679bd..640d1cc 100644 --- a/Node/src/mev_boost/mod.rs +++ b/Node/src/mev_boost/mod.rs @@ -61,3 +61,26 @@ impl MevBoost { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_mev_boost() { + let constraints = vec![vec![2,249,3,213,131,48,24,36,6,132,59,154,202,0,133,4,168,23,200,0,131,15,66,64,148,96,100,247,86,247,243,220,130,128,193,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,188,101,74,119,65,102,81,67,67,47,47,104,55,117,72,107,67,43,72,97,68,65,111,120,89,65,89,82,51,78,90,81,65,104,81,98,56,73,54,119,65,103,119,77,48,85,74,82,83,107,97,85,53,70,48,101,70,43,116,121,84,55,47,54,99,110,79,116,54,86,72,71,97,53,73,99,86,85,80,102,99,112,119,65,65,103,77,65,66,111,75,114,75,88,82,69,106,104,98,106,115,115,104,112,50,119,104,83,102,54,47,117,79,101,70,110,69,82,56,113,57,52,99,80,119,103,120,116,108,51,110,79,78,111,67,82,115,53,98,70,52,108,87,85,113,101,118,122,121,109,106,50,75,81,71,74,106,57,117,87,54,107,110,74,101,85,86,68,112,47,81,43,83,65,49,78,74,65,81,65,65,47,47,56,97,57,84,57,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,1,160,175,154,114,57,217,247,104,167,114,56,70,166,250,175,140,155,4,255,254,185,177,119,184,80,186,72,127,32,38,28,186,156,160,63,77,214,119,203,52,47,233,31,158,227,102,147,186,40,117,153,98,44,15,194,109,222,72,181,48,135,170,91,85,51,123]]; + let slot_id = 11; + let genesis_fork_version = [16, 0, 0, 56]; + let bls_service = Arc::new(BLSService::new("108e47e28c6c6027eac478d742cbb5ef675e20fdb6cbfcbf2bf0cd725b649813").unwrap()); + let pubkey = bls_service.get_public_key(); + let message = ConstraintsMessage::new(pubkey, slot_id, constraints); + let signed = SignedConstraints::new(message, bls_service, genesis_fork_version).unwrap(); + + let json_data = serde_json::to_value([&signed]).unwrap(); + + assert_eq!(json_data[0]["message"]["pubkey"], "0x908d6f98b5eaf6ac1b632c6b80b304612d48afd9c104874f9025960accdae128028119608b0d95a7e141390101fba669"); + assert_eq!(json_data[0]["message"]["slot"], 11); + assert_eq!(json_data[0]["signature"],"0x952d6076a21d43069b883b84e015fb3f56d4333b069bda1a120243e020d560b5f0b4af297d32e2cba69e9c67bb4a320a0e980df34b3934c4554a6fb32e3490d568d885217b4d5657fc58cefb30f30209f40c0223480c897600313a650fa29ab2"); + + } +} From 649fa23f7ca72851ea7d884882eb39e89a6d8ef9 Mon Sep 17 00:00:00 2001 From: mikhailUshakoff Date: Sun, 5 Jan 2025 12:30:33 +0100 Subject: [PATCH 5/5] Fix code style --- Node/src/bls/mod.rs | 6 +- Node/src/ethereum_l1/execution_layer.rs | 4 +- Node/src/mev_boost/constraints.rs | 86 ++++++++++++++++++++++--- Node/src/mev_boost/mod.rs | 49 +++++++++++++- 4 files changed, 127 insertions(+), 18 deletions(-) diff --git a/Node/src/bls/mod.rs b/Node/src/bls/mod.rs index f1b3751..79b0963 100644 --- a/Node/src/bls/mod.rs +++ b/Node/src/bls/mod.rs @@ -56,7 +56,7 @@ impl BLSService { let pk = self.get_public_key().serialize(); let x = Self::to_contract_layout(pk[0..48].try_into().unwrap()); let y = Self::to_contract_layout(pk[48..96].try_into().unwrap()); - return [x, y]; + [x, y] } pub fn signature_to_g2_point(&self, signature: &Signature) -> [[U256; 2]; 4] { @@ -65,10 +65,10 @@ impl BLSService { let x_i = Self::to_contract_layout(signature[48..96].try_into().unwrap()); let y = Self::to_contract_layout(signature[96..144].try_into().unwrap()); let y_i = Self::to_contract_layout(signature[144..192].try_into().unwrap()); - return [x, x_i, y, y_i]; + [x, x_i, y, y_i] } pub fn get_public_key(&self) -> PublicKey { - self.pk.clone() + self.pk } } diff --git a/Node/src/ethereum_l1/execution_layer.rs b/Node/src/ethereum_l1/execution_layer.rs index 8a084ca..aff0965 100644 --- a/Node/src/ethereum_l1/execution_layer.rs +++ b/Node/src/ethereum_l1/execution_layer.rs @@ -627,7 +627,7 @@ impl ExecutionLayer { y: pk_point[1], }; - let signature = self.bls_service.sign(&message, &vec![]); + let signature = self.bls_service.sign(&message, &[]); // Sign message and convert to G2Point let signature_point = self.bls_service.signature_to_g2_point(&signature); @@ -686,7 +686,7 @@ impl ExecutionLayer { y: pk_point[1], }; - let signature = self.bls_service.sign(&message, &vec![]); + let signature = self.bls_service.sign(&message, &[]); // Sign message and convert to G2Point let signature_point = self.bls_service.signature_to_g2_point(&signature); diff --git a/Node/src/mev_boost/constraints.rs b/Node/src/mev_boost/constraints.rs index c0ddcf7..0811af6 100644 --- a/Node/src/mev_boost/constraints.rs +++ b/Node/src/mev_boost/constraints.rs @@ -138,13 +138,60 @@ mod tests { #[test] fn test_constraints_message_digest() { - let constraints = vec![vec![2,249,3,213,131,48,24,36,6,132,59,154,202,0,133,4,168,23,200,0,131,15,66,64,148,96,100,247,86,247,243,220,130,128,193,207,160,28,228,26,55,181,241,109,241,128,185,3,100,242,118,107,125,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,97,69,97,210,209,67,98,30,18,110,135,131,26,239,40,118,120,180,66,184,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,188,101,74,119,65,102,81,67,67,47,47,104,55,117,72,107,67,43,72,97,68,65,111,120,89,65,89,82,51,78,90,81,65,104,81,98,56,73,54,119,65,103,119,77,48,85,74,82,83,107,97,85,53,70,48,101,70,43,116,121,84,55,47,54,99,110,79,116,54,86,72,71,97,53,73,99,86,85,80,102,99,112,119,65,65,103,77,65,66,111,75,114,75,88,82,69,106,104,98,106,115,115,104,112,50,119,104,83,102,54,47,117,79,101,70,110,69,82,56,113,57,52,99,80,119,103,120,116,108,51,110,79,78,111,67,82,115,53,98,70,52,108,87,85,113,101,118,122,121,109,106,50,75,81,71,74,106,57,117,87,54,107,110,74,101,85,86,68,112,47,81,43,83,65,49,78,74,65,81,65,65,47,47,56,97,57,84,57,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,1,160,175,154,114,57,217,247,104,167,114,56,70,166,250,175,140,155,4,255,254,185,177,119,184,80,186,72,127,32,38,28,186,156,160,63,77,214,119,203,52,47,233,31,158,227,102,147,186,40,117,153,98,44,15,194,109,222,72,181,48,135,170,91,85,51,123]]; + let constraints = vec![vec![ + 2, 249, 3, 213, 131, 48, 24, 36, 6, 132, 59, 154, 202, 0, 133, 4, 168, 23, 200, 0, 131, + 15, 66, 64, 148, 96, 100, 247, 86, 247, 243, 220, 130, 128, 193, 207, 160, 28, 228, 26, + 55, 181, 241, 109, 241, 128, 185, 3, 100, 242, 118, 107, 125, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 96, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 3, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 188, 101, 74, 119, 65, 102, 81, 67, 67, 47, 47, 104, 55, 117, 72, + 107, 67, 43, 72, 97, 68, 65, 111, 120, 89, 65, 89, 82, 51, 78, 90, 81, 65, 104, 81, 98, + 56, 73, 54, 119, 65, 103, 119, 77, 48, 85, 74, 82, 83, 107, 97, 85, 53, 70, 48, 101, + 70, 43, 116, 121, 84, 55, 47, 54, 99, 110, 79, 116, 54, 86, 72, 71, 97, 53, 73, 99, 86, + 85, 80, 102, 99, 112, 119, 65, 65, 103, 77, 65, 66, 111, 75, 114, 75, 88, 82, 69, 106, + 104, 98, 106, 115, 115, 104, 112, 50, 119, 104, 83, 102, 54, 47, 117, 79, 101, 70, 110, + 69, 82, 56, 113, 57, 52, 99, 80, 119, 103, 120, 116, 108, 51, 110, 79, 78, 111, 67, 82, + 115, 53, 98, 70, 52, 108, 87, 85, 113, 101, 118, 122, 121, 109, 106, 50, 75, 81, 71, + 74, 106, 57, 117, 87, 54, 107, 110, 74, 101, 85, 86, 68, 112, 47, 81, 43, 83, 65, 49, + 78, 74, 65, 81, 65, 65, 47, 47, 56, 97, 57, 84, 57, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 1, + 160, 175, 154, 114, 57, 217, 247, 104, 167, 114, 56, 70, 166, 250, 175, 140, 155, 4, + 255, 254, 185, 177, 119, 184, 80, 186, 72, 127, 32, 38, 28, 186, 156, 160, 63, 77, 214, + 119, 203, 52, 47, 233, 31, 158, 227, 102, 147, 186, 40, 117, 153, 98, 44, 15, 194, 109, + 222, 72, 181, 48, 135, 170, 91, 85, 51, 123, + ]]; let slot_id = 17; let pubkey = PublicKey::from_bytes(&alloy::hex::decode("908d6f98b5eaf6ac1b632c6b80b304612d48afd9c104874f9025960accdae128028119608b0d95a7e141390101fba669").unwrap()).unwrap(); let message = ConstraintsMessage::new(pubkey, slot_id, constraints); - assert_eq!(message.digest().unwrap(),[9, 87, 0, 71, 187, 129, 0, 133, 126, 114, 244, 187, 129, 105, 194, 105, 195, 115, 27, 220, 144, 157, 88, 34, 184, 108, 130, 34, 84, 248, 88, 125]); + assert_eq!( + message.digest().unwrap(), + [ + 9, 87, 0, 71, 187, 129, 0, 133, 126, 114, 244, 187, 129, 105, 194, 105, 195, 115, + 27, 220, 144, 157, 88, 34, 184, 108, 130, 34, 84, 248, 88, 125 + ] + ); } #[test] @@ -154,16 +201,35 @@ mod tests { let domain = SignedConstraints::compute_domain_custom(&context, COMMIT_BOOST_DOMAIN); - assert_eq!(domain, [109, 109, 111, 67, 11, 65, 190, 76, 219, 52, 209, 131, 221, 220, 165, 57, 131, 55, 98, 109, 205, 207, 175, 23, 32, 193, 32, 45, 59, 149, 248, 78]); + assert_eq!( + domain, + [ + 109, 109, 111, 67, 11, 65, 190, 76, 219, 52, 209, 131, 221, 220, 165, 57, 131, 55, + 98, 109, 205, 207, 175, 23, 32, 193, 32, 45, 59, 149, 248, 78 + ] + ); } #[test] fn test_signed_constraints_compute_signing_root_custom() { - let digest = [9, 87, 0, 71, 187, 129, 0, 133, 126, 114, 244, 187, 129, 105, 194, 105, 195, 115, 27, 220, 144, 157, 88, 34, 184, 108, 130, 34, 84, 248, 88, 125]; - let domain = [109, 109, 111, 67, 11, 65, 190, 76, 219, 52, 209, 131, 221, 220, 165, 57, 131, 55, 98, 109, 205, 207, 175, 23, 32, 193, 32, 45, 59, 149, 248, 78]; - - let signing_root = SignedConstraints::compute_signing_root_custom(digest.tree_hash_root().0, domain); - - assert_eq!(signing_root, [46, 115, 119, 45, 23, 162, 89, 198, 203, 58, 165, 97, 28, 21, 0, 117, 149, 27, 106, 219, 120, 115, 115, 227, 114, 157, 221, 247, 183, 14, 65, 54]); + let digest = [ + 9, 87, 0, 71, 187, 129, 0, 133, 126, 114, 244, 187, 129, 105, 194, 105, 195, 115, 27, + 220, 144, 157, 88, 34, 184, 108, 130, 34, 84, 248, 88, 125, + ]; + let domain = [ + 109, 109, 111, 67, 11, 65, 190, 76, 219, 52, 209, 131, 221, 220, 165, 57, 131, 55, 98, + 109, 205, 207, 175, 23, 32, 193, 32, 45, 59, 149, 248, 78, + ]; + + let signing_root = + SignedConstraints::compute_signing_root_custom(digest.tree_hash_root().0, domain); + + assert_eq!( + signing_root, + [ + 46, 115, 119, 45, 23, 162, 89, 198, 203, 58, 165, 97, 28, 21, 0, 117, 149, 27, 106, + 219, 120, 115, 115, 227, 114, 157, 221, 247, 183, 14, 65, 54 + ] + ); } -} \ No newline at end of file +} diff --git a/Node/src/mev_boost/mod.rs b/Node/src/mev_boost/mod.rs index 640d1cc..bcce988 100644 --- a/Node/src/mev_boost/mod.rs +++ b/Node/src/mev_boost/mod.rs @@ -68,10 +68,54 @@ mod tests { #[test] fn test_mev_boost() { - let constraints = vec![vec![2,249,3,213,131,48,24,36,6,132,59,154,202,0,133,4,168,23,200,0,131,15,66,64,148,96,100,247,86,247,243,220,130,128,193,207,160,28,228,26,55,181,241,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,188,101,74,119,65,102,81,67,67,47,47,104,55,117,72,107,67,43,72,97,68,65,111,120,89,65,89,82,51,78,90,81,65,104,81,98,56,73,54,119,65,103,119,77,48,85,74,82,83,107,97,85,53,70,48,101,70,43,116,121,84,55,47,54,99,110,79,116,54,86,72,71,97,53,73,99,86,85,80,102,99,112,119,65,65,103,77,65,66,111,75,114,75,88,82,69,106,104,98,106,115,115,104,112,50,119,104,83,102,54,47,117,79,101,70,110,69,82,56,113,57,52,99,80,119,103,120,116,108,51,110,79,78,111,67,82,115,53,98,70,52,108,87,85,113,101,118,122,121,109,106,50,75,81,71,74,106,57,117,87,54,107,110,74,101,85,86,68,112,47,81,43,83,65,49,78,74,65,81,65,65,47,47,56,97,57,84,57,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,1,160,175,154,114,57,217,247,104,167,114,56,70,166,250,175,140,155,4,255,254,185,177,119,184,80,186,72,127,32,38,28,186,156,160,63,77,214,119,203,52,47,233,31,158,227,102,147,186,40,117,153,98,44,15,194,109,222,72,181,48,135,170,91,85,51,123]]; + let constraints = vec![vec![ + 2, 249, 3, 213, 131, 48, 24, 36, 6, 132, 59, 154, 202, 0, 133, 4, 168, 23, 200, 0, 131, + 15, 66, 64, 148, 96, 100, 247, 86, 247, 243, 220, 130, 128, 193, 207, 160, 28, 228, 26, + 55, 181, 241, 109, 241, 128, 185, 3, 100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81, 65, 104, 81, 98, + 56, 73, 54, 119, 65, 103, 119, 77, 48, 85, 74, 82, 83, 107, 97, 85, 53, 70, 48, 101, + 70, 43, 116, 121, 84, 55, 47, 54, 99, 110, 79, 116, 54, 86, 72, 71, 97, 53, 73, 99, 86, + 85, 80, 102, 99, 112, 119, 65, 65, 103, 77, 65, 66, 111, 75, 114, 75, 88, 82, 69, 106, + 104, 98, 106, 115, 115, 104, 112, 50, 119, 104, 83, 102, 54, 47, 117, 79, 101, 70, 110, + 69, 82, 56, 113, 57, 52, 99, 80, 119, 103, 120, 116, 108, 51, 110, 79, 78, 111, 67, 82, + 115, 53, 98, 70, 52, 108, 87, 85, 113, 101, 118, 122, 121, 109, 106, 50, 75, 81, 71, + 74, 106, 57, 117, 87, 54, 107, 110, 74, 101, 85, 86, 68, 112, 47, 81, 43, 83, 65, 49, + 78, 74, 65, 81, 65, 65, 47, 47, 56, 97, 57, 84, 57, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 1, + 160, 175, 154, 114, 57, 217, 247, 104, 167, 114, 56, 70, 166, 250, 175, 140, 155, 4, + 255, 254, 185, 177, 119, 184, 80, 186, 72, 127, 32, 38, 28, 186, 156, 160, 63, 77, 214, + 119, 203, 52, 47, 233, 31, 158, 227, 102, 147, 186, 40, 117, 153, 98, 44, 15, 194, 109, + 222, 72, 181, 48, 135, 170, 91, 85, 51, 123, + ]]; let slot_id = 11; let genesis_fork_version = [16, 0, 0, 56]; - let bls_service = Arc::new(BLSService::new("108e47e28c6c6027eac478d742cbb5ef675e20fdb6cbfcbf2bf0cd725b649813").unwrap()); + let bls_service = Arc::new( + BLSService::new("108e47e28c6c6027eac478d742cbb5ef675e20fdb6cbfcbf2bf0cd725b649813") + .unwrap(), + ); let pubkey = bls_service.get_public_key(); let message = ConstraintsMessage::new(pubkey, slot_id, constraints); let signed = SignedConstraints::new(message, bls_service, genesis_fork_version).unwrap(); @@ -81,6 +125,5 @@ mod tests { assert_eq!(json_data[0]["message"]["pubkey"], "0x908d6f98b5eaf6ac1b632c6b80b304612d48afd9c104874f9025960accdae128028119608b0d95a7e141390101fba669"); assert_eq!(json_data[0]["message"]["slot"], 11); assert_eq!(json_data[0]["signature"],"0x952d6076a21d43069b883b84e015fb3f56d4333b069bda1a120243e020d560b5f0b4af297d32e2cba69e9c67bb4a320a0e980df34b3934c4554a6fb32e3490d568d885217b4d5657fc58cefb30f30209f40c0223480c897600313a650fa29ab2"); - } }