Skip to content

Commit d42a448

Browse files
committed
fix(forge): honor --ignore runtime and anchor runtime read in no-explorer fallback
1 parent 0369ceb commit d42a448

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

crates/forge/tests/cli/verify_bytecode.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,4 +429,25 @@ forgetest_async!(can_verify_bytecode_without_explorer, |prj, cmd| {
429429

430430
assert!(stdout.contains("Runtime code matched"), "{stdout}");
431431
assert!(stderr.contains("Creation data is unavailable"), "{stderr}");
432+
433+
// `--ignore runtime` must skip the runtime fallback as well: with no creation data either,
434+
// there is nothing left to verify.
435+
let assert = cmd
436+
.forge_fuse()
437+
.args([
438+
"verify-bytecode",
439+
&address,
440+
"Counter",
441+
"--rpc-url",
442+
rpc.as_str(),
443+
"--ignore",
444+
"runtime",
445+
])
446+
.assert_success();
447+
let output = assert.get_output();
448+
let stdout = output.stdout_lossy();
449+
let stderr = output.stderr_lossy();
450+
451+
assert!(!stdout.contains("Runtime code matched"), "{stdout}");
452+
assert!(stderr.contains("Creation data is unavailable"), "{stderr}");
432453
});

crates/verify/src/bytecode.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,30 @@ impl VerifyBytecodeArgs {
334334
// code cannot be verified. Verify the runtime bytecode instead by deploying the local
335335
// creation code and comparing the resulting runtime code with the onchain one.
336336
if creation_data.is_none() {
337-
let deploy_block = if maybe_predeploy {
338-
if !shell::is_json() {
337+
if !shell::is_json() {
338+
if maybe_predeploy {
339339
sh_warn!(
340340
"Attempting to verify predeployed contract at {:?}. Ignoring creation code verification.",
341341
self.address
342342
)?;
343+
} else {
344+
sh_warn!("Creation data is unavailable. Ignoring creation code verification.")?;
345+
}
346+
}
347+
348+
// Without creation data there is nothing else to verify when the runtime bytecode is
349+
// ignored.
350+
if self.ignore.is_some_and(|b| b.is_runtime()) {
351+
if shell::is_json() {
352+
sh_println!("{}", serde_json::to_string(&json_results)?)?;
343353
}
354+
return Ok(());
355+
}
356+
357+
let deploy_block = if maybe_predeploy {
344358
// Deploy at genesis
345359
0_u64
346360
} else {
347-
if !shell::is_json() {
348-
sh_warn!("Creation data is unavailable. Ignoring creation code verification.")?;
349-
}
350361
match self.block {
351362
Some(BlockId::Number(BlockNumberOrTag::Number(block))) => block,
352363
Some(_) => eyre::bail!("Invalid block number"),
@@ -405,13 +416,15 @@ impl VerifyBytecodeArgs {
405416
kind,
406417
)?;
407418

408-
// Compare runtime bytecode
419+
// Compare runtime bytecode. The onchain code is read at `deploy_block` to stay
420+
// anchored to the same height as the local fork. Predeploys keep reading at the
421+
// latest block: their code is stable and genesis state often isn't served by RPCs.
409422
let (deployed_bytecode, onchain_runtime_code) = crate::utils::get_runtime_codes::<FEN>(
410423
&mut executor,
411424
&provider,
412425
self.address,
413426
fork_address,
414-
None,
427+
(!maybe_predeploy).then_some(deploy_block),
415428
)
416429
.await?;
417430

0 commit comments

Comments
 (0)