From 4d59141bb709a5884075de6ab948498af0ece56d Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Sun, 17 Nov 2024 15:24:42 +0200 Subject: [PATCH] chore(blockifier): compute valid retdata directly --- crates/blockifier/src/transaction/account_transaction.rs | 2 +- crates/blockifier/src/transaction/transactions_test.rs | 4 ++-- crates/starknet_api/src/transaction/constants.rs | 9 ++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index e66b4c8de8..9ccf699740 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -939,7 +939,7 @@ impl ValidatableTransaction for AccountTransaction { if is_cairo1(&contract_class) { // The account contract class is a Cairo 1.0 contract; the `validate` entry point should // return `VALID`. - let expected_retdata = retdata![Felt::from_hex(constants::VALIDATE_RETDATA)?]; + let expected_retdata = retdata![*constants::VALIDATE_RETDATA]; if validate_call_info.execution.failed { return Err(TransactionExecutionError::PanicInValidate { diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index a63dda06c3..6dd3b6fc69 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -199,9 +199,9 @@ fn expected_validate_call_info( ) -> Option { let retdata = match cairo_version { CairoVersion::Cairo0 => Retdata::default(), - CairoVersion::Cairo1 => retdata!(felt!(constants::VALIDATE_RETDATA)), + CairoVersion::Cairo1 => retdata!(*constants::VALIDATE_RETDATA), #[cfg(feature = "cairo_native")] - CairoVersion::Native => retdata!(felt!(constants::VALIDATE_RETDATA)), + CairoVersion::Native => retdata!(*constants::VALIDATE_RETDATA), }; // Extra range check in regular (invoke) validate call, due to passing the calldata as an array. let n_range_checks = match cairo_version { diff --git a/crates/starknet_api/src/transaction/constants.rs b/crates/starknet_api/src/transaction/constants.rs index 0e54e54af6..36b013616e 100644 --- a/crates/starknet_api/src/transaction/constants.rs +++ b/crates/starknet_api/src/transaction/constants.rs @@ -1,3 +1,9 @@ +use std::sync::LazyLock; + +use starknet_types_core::felt::Felt; + +use crate::core::ascii_as_felt; + pub const EXECUTE_ENTRY_POINT_NAME: &str = "__execute__"; pub const TRANSFER_ENTRY_POINT_NAME: &str = "transfer"; pub const VALIDATE_ENTRY_POINT_NAME: &str = "__validate__"; @@ -12,4 +18,5 @@ pub const FELT_FALSE: u64 = 0; pub const FELT_TRUE: u64 = 1; // Expected return value of a `validate` entry point: `VALID`. -pub const VALIDATE_RETDATA: &str = "0x56414c4944"; +pub static VALIDATE_RETDATA: LazyLock = + LazyLock::new(|| ascii_as_felt("VALID").expect("Failed to parse ASCII"));