From fdb86fab627c668c42a0241b62dae7a3d2eafe22 Mon Sep 17 00:00:00 2001 From: Hubert Ritzdorf Date: Thu, 12 Jun 2025 12:31:03 +0200 Subject: [PATCH 1/3] Consistently treat code errors --- lib/bytecode_verification/verify_bytecode.rs | 30 ++++++++++++++++++-- src/dvf.rs | 20 +++++++++---- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/lib/bytecode_verification/verify_bytecode.rs b/lib/bytecode_verification/verify_bytecode.rs index 6e41d1fe..5f0b05dd 100644 --- a/lib/bytecode_verification/verify_bytecode.rs +++ b/lib/bytecode_verification/verify_bytecode.rs @@ -79,10 +79,15 @@ pub fn write_out_bytecodes( let mut on_chain_file = File::create("on_chain_bytecode.txt").expect("Could not create file"); compiled_file - .write_all(project_info.compiled_bytecode.as_bytes()) + .write_all( + project_info + .compiled_bytecode + .trim_start_matches("0x") + .as_bytes(), + ) .unwrap(); on_chain_file - .write_all(on_chain_bytecode.as_bytes()) + .write_all(on_chain_bytecode.trim_start_matches("0x").as_bytes()) .unwrap(); table.add_row(row![ @@ -91,6 +96,27 @@ pub fn write_out_bytecodes( ]); } +pub fn write_out_initcodes( + project_info: &ProjectInfo, + on_chain_initcode: &String, + table: &mut Table, +) { + let mut compiled_file = File::create("compiled_initcode.txt").expect("Could not create file"); + let mut on_chain_file = File::create("on_chain_initcode.txt").expect("Could not create file"); + + compiled_file + .write_all(project_info.init_code.trim_start_matches("0x").as_bytes()) + .unwrap(); + on_chain_file + .write_all(on_chain_initcode.trim_start_matches("0x").as_bytes()) + .unwrap(); + + table.add_row(row![ + "output files", + format!("{}\n{}", "compiled_initcode.txt", "on_chain_initcode.txt") + ]); +} + pub fn print_generation_summary( project_dir: &String, contract_name: &String, diff --git a/src/dvf.rs b/src/dvf.rs index dd23b7f3..28ec65eb 100644 --- a/src/dvf.rs +++ b/src/dvf.rs @@ -895,14 +895,24 @@ fn process(matches: ArgMatches) -> Result<(), ValidationError> { } } - print_progress("Comparing init code.", &mut pc, &progress_mode); + print_progress("Comparing initcode.", &mut pc, &progress_mode); let compare_init = CompareInitCode::compare(&mut project_info, &init_code, factory_mode); if !compare_init.matched { - return Err(ValidationError::Error(format!( - "Init code not matched for contract {:?}", - dumped.address - ))); + if matches.get_count("verbose") > 0 { + let mut error_info_table = Table::new(); + verify_bytecode::write_out_initcodes( + &project_info, + &init_code, + &mut error_info_table, + ); + error_info_table.printstd(); + } else { + println!("Initcode mismatch. Run in verbose mode for more info."); + } + return Err(ValidationError::from( + "Initcode mismatch. Consider running with --factory if this is a factory contract.", + )); } // immutable values are set in CompareBytecode::compare so this has to be after the call dumped.copy_immutables(&project_info, &pretty_printer); From 6170f80fd1602ccac9a320065631777de5d94144 Mon Sep 17 00:00:00 2001 From: Hubert Ritzdorf Date: Thu, 12 Jun 2025 13:26:49 +0200 Subject: [PATCH 2/3] Fix test --- tests/test_end_to_end.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_end_to_end.rs b/tests/test_end_to_end.rs index c623d61d..479d6eb8 100644 --- a/tests/test_end_to_end.rs +++ b/tests/test_end_to_end.rs @@ -1451,7 +1451,7 @@ mod tests { println!("{}", &output); // The expected output should be Error occurred: Init code not matched for contract 0xa16e02e87b7454126e5e10d957a927a7f5b5d2be - assert!(output.contains("Error occurred: Init code not matched for contract 0xa16e02e87b7454126e5e10d957a927a7f5b5d2be"), "The string does not contain the required text."); + assert!(output.contains("Error occurred: Initcode mismatch."), "The string does not contain the required text."); drop(local_client); } } From fc519e70a08e551dc2cc346e2f138eb696f9d6ad Mon Sep 17 00:00:00 2001 From: Hubert Ritzdorf Date: Thu, 12 Jun 2025 13:52:02 +0200 Subject: [PATCH 3/3] fmt --- tests/test_end_to_end.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_end_to_end.rs b/tests/test_end_to_end.rs index 479d6eb8..b70bcbe1 100644 --- a/tests/test_end_to_end.rs +++ b/tests/test_end_to_end.rs @@ -1451,7 +1451,10 @@ mod tests { println!("{}", &output); // The expected output should be Error occurred: Init code not matched for contract 0xa16e02e87b7454126e5e10d957a927a7f5b5d2be - assert!(output.contains("Error occurred: Initcode mismatch."), "The string does not contain the required text."); + assert!( + output.contains("Error occurred: Initcode mismatch."), + "The string does not contain the required text." + ); drop(local_client); } }