Skip to content

Commit 9cb1163

Browse files
always fetch latest nonce for 7702 authorizations (#20)
1 parent 2f2daf1 commit 9cb1163

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

core/src/signer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ pub trait AccountSigner {
194194
options: Self::SigningOptions,
195195
chain_id: u64,
196196
address: Address,
197-
nonce: alloy::primitives::U256,
197+
nonce: u64,
198198
credentials: &SigningCredential,
199199
) -> impl std::future::Future<Output = Result<SignedAuthorization, EngineError>> + Send;
200200
}
@@ -355,14 +355,14 @@ impl AccountSigner for EoaSigner {
355355
options: EoaSigningOptions,
356356
chain_id: u64,
357357
address: Address,
358-
nonce: U256,
358+
nonce: u64,
359359
credentials: &SigningCredential,
360360
) -> Result<SignedAuthorization, EngineError> {
361361
// Create the Authorization struct that both clients expect
362362
let authorization = Authorization {
363363
chain_id: U256::from(chain_id),
364364
address,
365-
nonce: nonce.to::<u64>(),
365+
nonce,
366366
};
367367
match credentials {
368368
SigningCredential::Vault(auth_method) => {

executors/src/eip7702_executor/send.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ pub enum Eip7702SendError {
9696
inner_error: Option<EngineError>,
9797
},
9898

99+
#[error("Failed to fetch nonce: {message}")]
100+
#[serde(rename_all = "camelCase")]
101+
NonceFetchError {
102+
message: String,
103+
inner_error: Option<EngineError>,
104+
},
105+
99106
#[error("Failed to call bundler: {message}")]
100107
BundlerCallError { message: String },
101108

@@ -264,7 +271,13 @@ where
264271

265272
// 5. Sign authorization if needed
266273
let authorization = if !is_minimal_account {
267-
let nonce = job_data.nonce.unwrap_or_default();
274+
let nonce = get_eoa_nonce(&chain, job_data.eoa_address)
275+
.await
276+
.map_err(|e| Eip7702SendError::NonceFetchError {
277+
message: format!("Failed to fetch nonce: {e}"),
278+
inner_error: Some(e),
279+
})
280+
.map_err_fail()?;
268281

269282
let auth = self
270283
.eoa_signer
@@ -511,3 +524,18 @@ async fn check_is_7702_minimal_account(
511524

512525
Ok(is_delegated)
513526
}
527+
528+
async fn get_eoa_nonce(chain: &impl Chain, eoa_address: Address) -> Result<u64, EngineError> {
529+
chain
530+
.provider()
531+
.get_transaction_count(eoa_address)
532+
.await
533+
.map_err(|e| EngineError::RpcError {
534+
chain_id: chain.chain_id(),
535+
rpc_url: chain.rpc_url().to_string(),
536+
message: format!("Failed to get nonce for address {}: {}", eoa_address, e),
537+
kind: RpcErrorKind::InternalError {
538+
message: e.to_string(),
539+
},
540+
})
541+
}

0 commit comments

Comments
 (0)