Skip to content

Commit

Permalink
chore(blockifier): compute valid retdata directly
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Nov 18, 2024
1 parent d6bb457 commit 4d59141
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ fn expected_validate_call_info(
) -> Option<CallInfo> {
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 {
Expand Down
9 changes: 8 additions & 1 deletion crates/starknet_api/src/transaction/constants.rs
Original file line number Diff line number Diff line change
@@ -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__";
Expand All @@ -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<Felt> =
LazyLock::new(|| ascii_as_felt("VALID").expect("Failed to parse ASCII"));

0 comments on commit 4d59141

Please sign in to comment.