From 147843adbfa58d6327198dd71bb2ed672d469a2a Mon Sep 17 00:00:00 2001 From: Dori Medini Date: Sat, 19 Oct 2024 18:10:07 +0300 Subject: [PATCH] test(blockifier): add class hash (if set) to cairo1 revert trace --- .../blockifier/src/execution/stack_trace.rs | 7 ++- .../src/execution/stack_trace_test.rs | 55 ++++++++++--------- .../syscalls/syscall_tests/failure_format.rs | 2 +- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/crates/blockifier/src/execution/stack_trace.rs b/crates/blockifier/src/execution/stack_trace.rs index 9380217e67..bce3b80862 100644 --- a/crates/blockifier/src/execution/stack_trace.rs +++ b/crates/blockifier/src/execution/stack_trace.rs @@ -207,8 +207,13 @@ pub fn extract_trailing_cairo1_revert_trace(root_call: &CallInfo) -> String { .iter() .map(|call_info| { format!( - "Error in contract (contract address: {:#064x}, selector: {:#064x}):", + "Error in contract (contract address: {:#064x}, class hash: {}, selector: \ + {:#064x}):", call_info.call.storage_address.0.key(), + match call_info.call.class_hash { + Some(class_hash) => format!("{:#064x}", class_hash.0), + None => "_".to_string(), + }, call_info.call.entry_point_selector.0, ) }) diff --git a/crates/blockifier/src/execution/stack_trace_test.rs b/crates/blockifier/src/execution/stack_trace_test.rs index 7d5b8e1d20..d3a20f94d0 100644 --- a/crates/blockifier/src/execution/stack_trace_test.rs +++ b/crates/blockifier/src/execution/stack_trace_test.rs @@ -214,12 +214,12 @@ An ASSERT_EQ instruction failed: 1 != 0. 0: Error in the called contract (contract address: {account_address_felt:#064x}, class hash: \ {account_contract_hash:#064x}, selector: {execute_selector_felt:#064x}): Execution failed. Failure reason: -Error in contract (contract address: {account_address_felt:#064x}, selector: \ - {execute_selector_felt:#064x}): -Error in contract (contract address: {test_contract_address_felt:#064x}, selector: \ - {external_entry_point_selector_felt:#064x}): -Error in contract (contract address: {test_contract_address_2_felt:#064x}, selector: \ - {inner_entry_point_selector_felt:#064x}): +Error in contract (contract address: {account_address_felt:#064x}, class hash: \ + {account_contract_hash:#064x}, selector: {execute_selector_felt:#064x}): +Error in contract (contract address: {test_contract_address_felt:#064x}, class hash: \ + {test_contract_hash:#064x}, selector: {external_entry_point_selector_felt:#064x}): +Error in contract (contract address: {test_contract_address_2_felt:#064x}, class hash: \ + {test_contract_hash:#064x}, selector: {inner_entry_point_selector_felt:#064x}): 0x6661696c ('fail'). " ); @@ -337,12 +337,12 @@ Unknown location (pc=0:{expected_pc1}) 0: Error in the called contract (contract address: {account_address_felt:#064x}, class hash: \ {account_contract_hash:#064x}, selector: {execute_selector_felt:#064x}): Execution failed. Failure reason: -Error in contract (contract address: {account_address_felt:#064x}, selector: \ - {execute_selector_felt:#064x}): -Error in contract (contract address: {contract_address_felt:#064x}, selector: \ - {invoke_call_chain_selector_felt:#064x}): -Error in contract (contract address: {contract_address_felt:#064x}, selector: \ - {invoke_call_chain_selector_felt:#064x}): +Error in contract (contract address: {account_address_felt:#064x}, class hash: \ + {account_contract_hash:#064x}, selector: {execute_selector_felt:#064x}): +Error in contract (contract address: {contract_address_felt:#064x}, class hash: \ + {test_contract_hash:#064x}, selector: {invoke_call_chain_selector_felt:#064x}): +Error in contract (contract address: {contract_address_felt:#064x}, class hash: \ + {test_contract_hash:#064x}, selector: {invoke_call_chain_selector_felt:#064x}): {expected_error}. " ) @@ -490,14 +490,14 @@ Unknown location (pc=0:{expected_pc3}) 0: Error in the called contract (contract address: {account_address_felt:#064x}, class hash: \ {account_contract_hash:#064x}, selector: {execute_selector_felt:#064x}): Execution failed. Failure reason: -Error in contract (contract address: {account_address_felt:#064x}, selector: \ - {execute_selector_felt:#064x}): -Error in contract (contract address: {address_felt:#064x}, selector: \ - {invoke_call_chain_selector_felt:#064x}): -Error in contract (contract address: {address_felt:#064x}, selector: \ - {invoke_call_chain_selector_felt:#064x}): -Error in contract (contract address: {address_felt:#064x}, selector: \ - {last_func_selector_felt:#064x}): +Error in contract (contract address: {account_address_felt:#064x}, class hash: \ + {account_contract_hash:#064x}, selector: {execute_selector_felt:#064x}): +Error in contract (contract address: {address_felt:#064x}, class hash: {test_contract_hash:#064x}, \ + selector: {invoke_call_chain_selector_felt:#064x}): +Error in contract (contract address: {address_felt:#064x}, class hash: {test_contract_hash:#064x}, \ + selector: {invoke_call_chain_selector_felt:#064x}): +Error in contract (contract address: {address_felt:#064x}, class hash: {test_contract_hash:#064x}, \ + selector: {last_func_selector_felt:#064x}): {expected_error}. " ) @@ -597,8 +597,10 @@ An ASSERT_EQ instruction failed: 1 != 0. ), CairoVersion::Cairo1 => format!( "The `validate` entry point panicked with: -Error in contract (contract address: {contract_address:#064x}, selector: {selector:#064x}): -0x496e76616c6964207363656e6172696f ('Invalid scenario')." +Error in contract (contract address: {contract_address:#064x}, class hash: {:#064x}, selector: \ + {selector:#064x}): +0x496e76616c6964207363656e6172696f ('Invalid scenario').", + class_hash.0 ), }; @@ -665,10 +667,11 @@ An ASSERT_EQ instruction failed: 1 != 0. .to_string(), CairoVersion::Cairo1 => format!( "Execution failed. Failure reason: -Error in contract (contract address: {expected_address:#064x}, selector: \ +Error in contract (contract address: {expected_address:#064x}, class hash: {:#064x}, selector: \ {expected_selector:#064x}): 0x496e76616c6964207363656e6172696f ('Invalid scenario'). -" +", + class_hash.0 ) .to_string(), }; @@ -798,11 +801,13 @@ Error at pc=0:{}: Error at pc=0:{}: {frame_2} Execution failed. Failure reason: -Error in contract (contract address: {expected_address:#064x}, selector: {:#064x}): +Error in contract (contract address: {expected_address:#064x}, class hash: {:#064x}, selector: \ + {:#064x}): 0x496e76616c6964207363656e6172696f ('Invalid scenario'). ", execute_offset + 205, deploy_offset + 194, + faulty_class_hash.0, ctor_selector.0 ) } diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/failure_format.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/failure_format.rs index ccb823cf1e..aed94c351f 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/failure_format.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/failure_format.rs @@ -20,7 +20,7 @@ fn test_syscall_failure_format() { error.to_string(), format!( "Execution failed. Failure reason: -Error in contract (contract address: {:#064x}, selector: {:#064x}): +Error in contract (contract address: {:#064x}, class hash: _, selector: {:#064x}): {execution_failure} ('Execution failure').", ContractAddress::default().0.key(), EntryPointSelector::default().0