diff --git a/client/src/eth/handlers/roundup_relay_handler.rs b/client/src/eth/handlers/roundup_relay_handler.rs index 8902a028..8ffbaac6 100644 --- a/client/src/eth/handlers/roundup_relay_handler.rs +++ b/client/src/eth/handlers/roundup_relay_handler.rs @@ -1,7 +1,6 @@ use std::{sync::Arc, time::Duration}; use alloy::{ - dyn_abi::DynSolValue, network::{primitives::ReceiptResponse as _, AnyNetwork}, primitives::{Address, PrimitiveSignature, B256, U256}, providers::{fillers::TxFiller, Provider, WalletProvider}, @@ -25,7 +24,7 @@ use br_primitives::{ }, eth::{BootstrapState, RoundUpEventStatus}, tx::{TxRequestMetadata, VSPPhase2Metadata}, - utils::{recover_message, sub_display_format}, + utils::{encode_roundup_param, recover_message, sub_display_format}, }; use crate::eth::{ @@ -197,17 +196,6 @@ where Ok(log.log_decode::()?.inner.data) } - /// Encodes the given round and new relayers to bytes. - fn encode_relayer_array(&self, round: U256, new_relayers: &[Address]) -> Vec { - DynSolValue::Tuple(vec![ - DynSolValue::Uint(round, 256), - DynSolValue::Array( - new_relayers.iter().map(|address| DynSolValue::Address(*address)).collect(), - ), - ]) - .abi_encode() - } - /// Get the submitted signatures of the updated round. async fn get_sorted_signatures( &self, @@ -225,7 +213,7 @@ where let mut signature_vec = Vec::::from(signatures); signature_vec - .sort_by_key(|k| recover_message(*k, &self.encode_relayer_array(round, new_relayers))); + .sort_by_key(|k| recover_message(*k, &encode_roundup_param(round, &new_relayers))); Ok(Signatures::from(signature_vec)) } diff --git a/periodic/src/roundup_emitter.rs b/periodic/src/roundup_emitter.rs index d54c2a29..751cca26 100644 --- a/periodic/src/roundup_emitter.rs +++ b/periodic/src/roundup_emitter.rs @@ -1,5 +1,4 @@ use alloy::{ - dyn_abi::DynSolValue, network::AnyNetwork, primitives::{Address, U256}, providers::{fillers::TxFiller, Provider, WalletProvider}, @@ -25,7 +24,7 @@ use br_primitives::{ }, eth::{BootstrapState, RoundUpEventStatus}, tx::{TxRequestMetadata, VSPPhase1Metadata}, - utils::sub_display_format, + utils::{encode_roundup_param, sub_display_format}, }; use eyre::Result; @@ -157,13 +156,7 @@ where round: U256, new_relayers: Vec
, ) -> Result { - let encoded_msg = DynSolValue::Tuple(vec![ - DynSolValue::Uint(round, 256), - DynSolValue::Array( - new_relayers.iter().map(|address| DynSolValue::Address(*address)).collect(), - ), - ]) - .abi_encode(); + let encoded_msg = encode_roundup_param(round, &new_relayers); let sigs = Signatures::from(self.client.sign_message(&encoded_msg).await?); let round_up_submit = Round_Up_Submit { round, new_relayers, sigs }; diff --git a/primitives/src/utils.rs b/primitives/src/utils.rs index e130198a..b6c1e205 100644 --- a/primitives/src/utils.rs +++ b/primitives/src/utils.rs @@ -1,4 +1,7 @@ -use alloy::primitives::{keccak256, Address, PrimitiveSignature, B256}; +use alloy::{ + dyn_abi::DynSolValue, + primitives::{keccak256, Address, PrimitiveSignature, B256, U256}, +}; use k256::{ecdsa::VerifyingKey, elliptic_curve::sec1::ToEncodedPoint}; use rand::Rng as _; use sha3::{Digest, Keccak256}; @@ -13,6 +16,17 @@ pub fn generate_delay() -> u64 { rand::thread_rng().gen_range(0..=12000) } +/// Encodes the given round and new relayers to bytes. +pub fn encode_roundup_param(round: U256, new_relayers: &[Address]) -> Vec { + DynSolValue::Tuple(vec![ + DynSolValue::Uint(round, 256), + DynSolValue::Array( + new_relayers.iter().map(|address| DynSolValue::Address(*address)).collect(), + ), + ]) + .abi_encode_params() +} + impl From for EthereumSignature { fn from(signature: PrimitiveSignature) -> Self { let sig: [u8; 65] = signature.into();