Skip to content

Commit 515a4cc

Browse files
authored
Add --disable-code-size-limit flag for anvil (#8646)
Add --disable-code-size-limit flag
1 parent a0a0020 commit 515a4cc

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

crates/anvil/src/cmd.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ impl NodeArgs {
246246
.with_auto_impersonate(self.evm_opts.auto_impersonate)
247247
.with_ipc(self.ipc)
248248
.with_code_size_limit(self.evm_opts.code_size_limit)
249+
.disable_code_size_limit(self.evm_opts.disable_code_size_limit)
249250
.set_pruned_history(self.prune_history)
250251
.with_init_state(self.load_state.or_else(|| self.state.and_then(|s| s.state)))
251252
.with_transaction_block_keeper(self.transaction_block_keeper)
@@ -495,11 +496,20 @@ pub struct AnvilEvmArgs {
495496
)]
496497
pub disable_block_gas_limit: bool,
497498

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

504+
/// Disable EIP-170: Contract code size limit.
505+
#[arg(
506+
long,
507+
value_name = "DISABLE_CODE_SIZE_LIMIT",
508+
conflicts_with = "code_size_limit",
509+
help_heading = "Environment config"
510+
)]
511+
pub disable_code_size_limit: bool,
512+
503513
/// The gas price.
504514
#[arg(long, help_heading = "Environment config")]
505515
pub gas_price: Option<u128>,
@@ -805,6 +815,21 @@ mod tests {
805815
assert!(args.is_err());
806816
}
807817

818+
#[test]
819+
fn can_parse_disable_code_size_limit() {
820+
let args: NodeArgs = NodeArgs::parse_from(["anvil", "--disable-code-size-limit"]);
821+
assert!(args.evm_opts.disable_code_size_limit);
822+
823+
let args = NodeArgs::try_parse_from([
824+
"anvil",
825+
"--disable-code-size-limit",
826+
"--code-size-limit",
827+
"100",
828+
]);
829+
// can't be used together
830+
assert!(args.is_err());
831+
}
832+
808833
#[test]
809834
fn can_parse_host() {
810835
let args = NodeArgs::parse_from(["anvil"]);

crates/anvil/src/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,14 @@ impl NodeConfig {
482482
self.code_size_limit = code_size_limit;
483483
self
484484
}
485+
/// Disables code size limit
486+
#[must_use]
487+
pub fn disable_code_size_limit(mut self, disable_code_size_limit: bool) -> Self {
488+
if disable_code_size_limit {
489+
self.code_size_limit = Some(usize::MAX);
490+
}
491+
self
492+
}
485493

486494
/// Sets the init state if any
487495
#[must_use]

0 commit comments

Comments
 (0)