Skip to content

Commit a5930b4

Browse files
committed
feat(anvil): bypass EIP-7702 authorization signatures for testing
1 parent 79d4ab2 commit a5930b4

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

crates/anvil/core/src/eth/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,10 @@ pub enum EthRequest {
689689
/// Set the executor (sponsor) wallet
690690
#[serde(rename = "anvil_setExecutor", with = "sequence")]
691691
AnvilSetExecutor(String),
692+
693+
/// Enable or disable bypass for authorization list signature checks
694+
#[serde(rename = "anvil_setBypassAuthorizationChecks", with = "sequence")]
695+
AnvilSetBypassAuthorizationChecks(bool),
692696
}
693697

694698
/// Represents ethereum JSON-RPC API

crates/anvil/src/eth/api.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,9 @@ impl EthApi {
509509
EthRequest::AnvilSetExecutor(executor_pk) => {
510510
self.anvil_set_executor(executor_pk).to_rpc_result()
511511
}
512+
EthRequest::AnvilSetBypassAuthorizationChecks(enabled) => {
513+
self.anvil_set_bypass_authorization_checks(enabled).await.to_rpc_result()
514+
}
512515
};
513516

514517
if let ResponseResult::Error(err) = &response {
@@ -1821,6 +1824,15 @@ impl EthApi {
18211824
Ok(())
18221825
}
18231826

1827+
/// Enables or disables bypass for authorization list signature checks
1828+
///
1829+
/// Handler for ETH RPC call: `anvil_setBypassAuthorizationChecks`
1830+
pub async fn anvil_set_bypass_authorization_checks(&self, enabled: bool) -> Result<()> {
1831+
node_info!("anvil_setBypassAuthorizationChecks");
1832+
self.backend.set_bypass_authorization_checks(enabled);
1833+
Ok(())
1834+
}
1835+
18241836
/// Returns true if auto mining is enabled, and false.
18251837
///
18261838
/// Handler for ETH RPC call: `anvil_getAutomine`

crates/anvil/src/eth/backend/cheats.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ impl CheatsManager {
6161
pub fn impersonated_accounts(&self) -> AddressHashSet {
6262
self.state.read().impersonated_accounts.clone()
6363
}
64+
65+
66+
/// Enables or disables bypass for authorization list signature checks
67+
pub fn set_bypass_authorization_checks(&self, enabled: bool) {
68+
trace!(target: "cheats", "Bypass authorization checks set to {:?}", enabled);
69+
self.state.write().bypass_authorization_checks = enabled;
70+
}
71+
72+
/// Returns true if authorization list signature checks should be bypassed
73+
pub fn bypass_authorization_checks(&self) -> bool {
74+
self.state.read().bypass_authorization_checks
75+
}
6476
}
6577

6678
/// Container type for all the state variables
@@ -70,4 +82,6 @@ pub struct CheatsState {
7082
pub impersonated_accounts: AddressHashSet,
7183
/// If set to true will make the `is_impersonated` function always return true
7284
pub auto_impersonate_accounts: bool,
85+
/// If set to true, bypass signature verification on authorization lists
86+
pub bypass_authorization_checks: bool,
7387
}

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,11 @@ impl Backend {
509509
self.cheats.set_auto_impersonate_account(enabled);
510510
}
511511

512+
/// Sets whether to bypass authorization list signature checks
513+
pub fn set_bypass_authorization_checks(&self, enabled: bool) {
514+
self.cheats.set_bypass_authorization_checks(enabled);
515+
}
516+
512517
/// Returns the configured fork, if any
513518
pub fn get_fork(&self) -> Option<ClientFork> {
514519
self.fork.read().clone()
@@ -1584,7 +1589,16 @@ impl Backend {
15841589
blob_hashes,
15851590
..Default::default()
15861591
};
1587-
base.set_signed_authorization(authorization_list.unwrap_or_default());
1592+
1593+
// If bypass is enabled, skip setting authorization list to bypass signature validation
1594+
match self.cheats.bypass_authorization_checks() {
1595+
true => {
1596+
base.set_signed_authorization(Vec::new());
1597+
}
1598+
false => {
1599+
base.set_signed_authorization(authorization_list.unwrap_or_default());
1600+
}
1601+
}
15881602
env.tx = OpTransaction { base, ..Default::default() };
15891603

15901604
if let Some(nonce) = nonce {

crates/anvil/tests/it/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ mod proof;
1515
mod pubsub;
1616
mod revert;
1717
mod sign;
18+
mod signature_bypass;
1819
mod simulate;
1920
mod state;
2021
mod traces;

0 commit comments

Comments
 (0)