diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index 2de06dfe4..5bd0a35b9 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -103,11 +103,7 @@ impl BatchState { self.batch_queue .iter() .map(|(entry, _)| entry) - .find(|entry| { - entry.sender == sender - && U256::from_big_endian(entry.nonced_verification_data.nonce.as_slice()) - == nonce - }) + .find(|entry| entry.sender == sender && entry.nonced_verification_data.nonce == nonce) } /// Checks if the entry is valid @@ -122,8 +118,7 @@ impl BatchState { replacement_entry: BatchQueueEntry, ) -> Option { let replacement_max_fee = replacement_entry.nonced_verification_data.max_fee; - let nonce = - U256::from_big_endian(replacement_entry.nonced_verification_data.nonce.as_slice()); + let nonce = replacement_entry.nonced_verification_data.nonce; let sender = replacement_entry.sender; debug!( @@ -134,7 +129,7 @@ impl BatchState { // it is a valid entry only if there is no entry with the same sender, lower nonce and a lower fee let is_valid = !self.batch_queue.iter().any(|(entry, _)| { entry.sender == sender - && U256::from_big_endian(entry.nonced_verification_data.nonce.as_slice()) < nonce + && entry.nonced_verification_data.nonce < nonce && entry.nonced_verification_data.max_fee < replacement_max_fee }); @@ -439,7 +434,7 @@ impl Batcher { info!( "Received message with nonce: {}", - U256::from_big_endian(client_msg.verification_data.nonce.as_slice()) + client_msg.verification_data.nonce ); if client_msg.verification_data.chain_id != self.chain_id { @@ -495,7 +490,7 @@ impl Batcher { } // Nonce and max fee verification - let nonce = U256::from_big_endian(nonced_verification_data.nonce.as_slice()); + let nonce = nonced_verification_data.nonce; let max_fee = nonced_verification_data.max_fee; if max_fee < U256::from(MIN_FEE_PER_PROOF) { @@ -644,7 +639,7 @@ impl Batcher { return false; } - let nonce = U256::from_big_endian(&nonced_verification_data.nonce); + let nonce = nonced_verification_data.nonce; batch_state.user_nonces.insert(addr, nonce + U256::one()); batch_state.user_min_fee.insert(addr, max_fee); @@ -678,7 +673,7 @@ impl Batcher { expected_user_nonce: U256, ) -> bool { let replacement_max_fee = nonced_verification_data.max_fee; - let nonce = U256::from_big_endian(&nonced_verification_data.nonce); + let nonce = nonced_verification_data.nonce; let mut replacement_entry = match batch_state.get_entry(addr, nonce) { Some(entry) => { @@ -761,7 +756,7 @@ impl Batcher { info!("Adding verification data to batch..."); let max_fee = verification_data.max_fee; - let nonce = U256::from_big_endian(verification_data.nonce.as_slice()); + let nonce = verification_data.nonce; batch_state.batch_queue.push( BatchQueueEntry::new( @@ -1254,15 +1249,15 @@ impl Batcher { } }; - debug!("non paying nonce: {:?}", nonpaying_nonce); + info!("non paying nonce: {:?}", nonpaying_nonce); + + let nonce_value = *nonpaying_nonce; - let mut nonce_bytes = [0u8; 32]; - nonpaying_nonce.to_big_endian(&mut nonce_bytes); *nonpaying_nonce += U256::one(); NoncedVerificationData::new( client_msg.verification_data.verification_data.clone(), - nonce_bytes, + nonce_value, DEFAULT_MAX_FEE_PER_PROOF.into(), // 13_000 gas per proof * 100 gwei gas price (upper bound) self.chain_id, self.payment_service.address(), diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 6f90d4ed8..336cabe2f 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -41,18 +41,14 @@ pub async fn send_messages( let mut ws_write = ws_write.lock().await; - let mut nonce_bytes = [0u8; 32]; - let mut response_stream = response_stream.lock().await; let chain_id = U256::from(wallet.chain_id()); for (idx, verification_data) in verification_data.iter().enumerate() { - nonce.to_big_endian(&mut nonce_bytes); - let verification_data = NoncedVerificationData::new( verification_data.clone(), - nonce_bytes, + nonce, max_fees[idx], chain_id, payment_service_addr, diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index 57cd1d846..29dfa5852 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -19,7 +19,7 @@ use super::errors::VerifySignatureError; // we don't have the fields of VerificationData, we only have the hash of the VerificationData. // chain_id is not included in the type because it is now part of the domain. const NONCED_VERIFICATION_DATA_TYPE: &[u8] = - b"NoncedVerificationData(bytes32 verification_data_hash,bytes32 nonce,uint256 max_fee)"; + b"NoncedVerificationData(bytes32 verification_data_hash,uint256 nonce,uint256 max_fee)"; #[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq)] #[repr(u8)] @@ -47,7 +47,7 @@ pub struct VerificationData { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct NoncedVerificationData { pub verification_data: VerificationData, - pub nonce: [u8; 32], + pub nonce: U256, pub max_fee: U256, pub chain_id: U256, pub payment_service_addr: Address, @@ -56,7 +56,7 @@ pub struct NoncedVerificationData { impl NoncedVerificationData { pub fn new( verification_data: VerificationData, - nonce: [u8; 32], + nonce: U256, max_fee: U256, chain_id: U256, payment_service_addr: Address, @@ -218,7 +218,9 @@ impl Eip712 for NoncedVerificationData { hasher.update(NONCED_VERIFICATION_DATA_TYPE); let nonced_verification_data_type_hash = hasher.finalize_reset(); - hasher.update(self.nonce); + let mut nonce_bytes = [0u8; 32]; + self.nonce.to_big_endian(&mut nonce_bytes); + hasher.update(nonce_bytes); let nonce_hash = hasher.finalize_reset(); let mut max_fee_bytes = [0u8; 32]; diff --git a/batcher/aligned-sdk/src/eth/batcher_payment_service.rs b/batcher/aligned-sdk/src/eth/batcher_payment_service.rs index cc3fb782a..d5e7f6786 100644 --- a/batcher/aligned-sdk/src/eth/batcher_payment_service.rs +++ b/batcher/aligned-sdk/src/eth/batcher_payment_service.rs @@ -24,7 +24,7 @@ pub async fn batcher_payment_service( } impl SignatureData { - pub fn new(signature: &Signature, nonce: [u8; 32], max_fee: U256) -> Self { + pub fn new(signature: &Signature, nonce: U256, max_fee: U256) -> Self { let mut signature_bytes = [0u8; 65]; signature.r.to_big_endian(&mut signature_bytes[0..32]); @@ -33,8 +33,6 @@ impl SignatureData { signature_bytes[64] = signature.v as u8; - let nonce = U256::from_big_endian(nonce.as_slice()); - let signature_bytes = Bytes::from(signature_bytes); SignatureData { diff --git a/contracts/script/deploy/config/devnet/batcher-payment-service.devnet.config.json b/contracts/script/deploy/config/devnet/batcher-payment-service.devnet.config.json index e933a82d0..03d903564 100644 --- a/contracts/script/deploy/config/devnet/batcher-payment-service.devnet.config.json +++ b/contracts/script/deploy/config/devnet/batcher-payment-service.devnet.config.json @@ -12,6 +12,6 @@ "owner": "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955" }, "eip712": { - "noncedVerificationDataTypeHash": "2194895b48bd1793cdc112d96441a9e5291ef6151d5aa0e8e2386c81bdc61624" + "noncedVerificationDataTypeHash": "41817b5c5b0c3dcda70ccb43ba175fdcd7e586f9e0484422a2c6bba678fdf4a3" } } diff --git a/contracts/script/deploy/config/holesky/batcher-payment-service.holesky.config.json b/contracts/script/deploy/config/holesky/batcher-payment-service.holesky.config.json index ad04acec0..45b479530 100644 --- a/contracts/script/deploy/config/holesky/batcher-payment-service.holesky.config.json +++ b/contracts/script/deploy/config/holesky/batcher-payment-service.holesky.config.json @@ -11,6 +11,6 @@ "owner": "" }, "eip712": { - "noncedVerificationDataTypeHash": "2194895b48bd1793cdc112d96441a9e5291ef6151d5aa0e8e2386c81bdc61624" + "noncedVerificationDataTypeHash": "41817b5c5b0c3dcda70ccb43ba175fdcd7e586f9e0484422a2c6bba678fdf4a3" } }