Skip to content

Commit

Permalink
Add --disable-code-size-limit flag for anvil (#8646)
Browse files Browse the repository at this point in the history
Add --disable-code-size-limit flag
  • Loading branch information
krzkaczor authored Aug 12, 2024
1 parent a0a0020 commit 515a4cc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
29 changes: 27 additions & 2 deletions crates/anvil/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ impl NodeArgs {
.with_auto_impersonate(self.evm_opts.auto_impersonate)
.with_ipc(self.ipc)
.with_code_size_limit(self.evm_opts.code_size_limit)
.disable_code_size_limit(self.evm_opts.disable_code_size_limit)
.set_pruned_history(self.prune_history)
.with_init_state(self.load_state.or_else(|| self.state.and_then(|s| s.state)))
.with_transaction_block_keeper(self.transaction_block_keeper)
Expand Down Expand Up @@ -495,11 +496,20 @@ pub struct AnvilEvmArgs {
)]
pub disable_block_gas_limit: bool,

/// EIP-170: Contract code size limit in bytes. Useful to increase this because of tests. By
/// default, it is 0x6000 (~25kb).
/// EIP-170: Contract code size limit in bytes. Useful to increase this because of tests. To
/// disable entirely, use `--disable-code-size-limit`. By default, it is 0x6000 (~25kb).
#[arg(long, value_name = "CODE_SIZE", help_heading = "Environment config")]
pub code_size_limit: Option<usize>,

/// Disable EIP-170: Contract code size limit.
#[arg(
long,
value_name = "DISABLE_CODE_SIZE_LIMIT",
conflicts_with = "code_size_limit",
help_heading = "Environment config"
)]
pub disable_code_size_limit: bool,

/// The gas price.
#[arg(long, help_heading = "Environment config")]
pub gas_price: Option<u128>,
Expand Down Expand Up @@ -805,6 +815,21 @@ mod tests {
assert!(args.is_err());
}

#[test]
fn can_parse_disable_code_size_limit() {
let args: NodeArgs = NodeArgs::parse_from(["anvil", "--disable-code-size-limit"]);
assert!(args.evm_opts.disable_code_size_limit);

let args = NodeArgs::try_parse_from([
"anvil",
"--disable-code-size-limit",
"--code-size-limit",
"100",
]);
// can't be used together
assert!(args.is_err());
}

#[test]
fn can_parse_host() {
let args = NodeArgs::parse_from(["anvil"]);
Expand Down
8 changes: 8 additions & 0 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ impl NodeConfig {
self.code_size_limit = code_size_limit;
self
}
/// Disables code size limit
#[must_use]
pub fn disable_code_size_limit(mut self, disable_code_size_limit: bool) -> Self {
if disable_code_size_limit {
self.code_size_limit = Some(usize::MAX);
}
self
}

/// Sets the init state if any
#[must_use]
Expand Down

0 comments on commit 515a4cc

Please sign in to comment.