Skip to content

feat(anvil): bypass authorization signatures for testing #11178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/anvil/core/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@ pub enum EthRequest {
/// Set the executor (sponsor) wallet
#[serde(rename = "anvil_setExecutor", with = "sequence")]
AnvilSetExecutor(String),

/// Enable or disable bypass for authorization list signature checks
#[serde(rename = "anvil_setBypassAuthorizationChecks", with = "sequence")]
AnvilSetBypassAuthorizationChecks(bool),
}

/// Represents ethereum JSON-RPC API
Expand Down
12 changes: 12 additions & 0 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ impl EthApi {
EthRequest::AnvilSetExecutor(executor_pk) => {
self.anvil_set_executor(executor_pk).to_rpc_result()
}
EthRequest::AnvilSetBypassAuthorizationChecks(enabled) => {
self.anvil_set_bypass_authorization_checks(enabled).await.to_rpc_result()
}
};

if let ResponseResult::Error(err) = &response {
Expand Down Expand Up @@ -1821,6 +1824,15 @@ impl EthApi {
Ok(())
}

/// Enables or disables bypass for authorization list signature checks
///
/// Handler for ETH RPC call: `anvil_setBypassAuthorizationChecks`
pub async fn anvil_set_bypass_authorization_checks(&self, enabled: bool) -> Result<()> {
node_info!("anvil_setBypassAuthorizationChecks");
self.backend.set_bypass_authorization_checks(enabled);
Ok(())
}

/// Returns true if auto mining is enabled, and false.
///
/// Handler for ETH RPC call: `anvil_getAutomine`
Expand Down
14 changes: 14 additions & 0 deletions crates/anvil/src/eth/backend/cheats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ impl CheatsManager {
pub fn impersonated_accounts(&self) -> AddressHashSet {
self.state.read().impersonated_accounts.clone()
}


/// Enables or disables bypass for authorization list signature checks
pub fn set_bypass_authorization_checks(&self, enabled: bool) {
trace!(target: "cheats", "Bypass authorization checks set to {:?}", enabled);
self.state.write().bypass_authorization_checks = enabled;
}

/// Returns true if authorization list signature checks should be bypassed
pub fn bypass_authorization_checks(&self) -> bool {
self.state.read().bypass_authorization_checks
}
}

/// Container type for all the state variables
Expand All @@ -70,4 +82,6 @@ pub struct CheatsState {
pub impersonated_accounts: AddressHashSet,
/// If set to true will make the `is_impersonated` function always return true
pub auto_impersonate_accounts: bool,
/// If set to true, bypass signature verification on authorization lists
pub bypass_authorization_checks: bool,
}
16 changes: 15 additions & 1 deletion crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,11 @@ impl Backend {
self.cheats.set_auto_impersonate_account(enabled);
}

/// Sets whether to bypass authorization list signature checks
pub fn set_bypass_authorization_checks(&self, enabled: bool) {
self.cheats.set_bypass_authorization_checks(enabled);
}

/// Returns the configured fork, if any
pub fn get_fork(&self) -> Option<ClientFork> {
self.fork.read().clone()
Expand Down Expand Up @@ -1584,7 +1589,16 @@ impl Backend {
blob_hashes,
..Default::default()
};
base.set_signed_authorization(authorization_list.unwrap_or_default());

// If bypass is enabled, skip setting authorization list to bypass signature validation
match self.cheats.bypass_authorization_checks() {
true => {
base.set_signed_authorization(Vec::new());
}
false => {
base.set_signed_authorization(authorization_list.unwrap_or_default());
}
}
env.tx = OpTransaction { base, ..Default::default() };

if let Some(nonce) = nonce {
Expand Down
1 change: 1 addition & 0 deletions crates/anvil/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod proof;
mod pubsub;
mod revert;
mod sign;
mod signature_bypass;
mod simulate;
mod state;
mod traces;
Expand Down