Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
feat: change constructor error variant in TransactionExecutionError (#…
Browse files Browse the repository at this point in the history
…1844)

Signed-off-by: Dori Medini <[email protected]>
  • Loading branch information
dorimedini-starkware authored May 2, 2024
1 parent 8417325 commit 9cd740b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 65 deletions.
9 changes: 0 additions & 9 deletions crates/blockifier/src/execution/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,6 @@ impl ConstructorEntryPointExecutionError {
}
}

// TODO(Dori, 5/5/2024): Delete this converter.
impl From<ConstructorEntryPointExecutionError> for EntryPointExecutionError {
fn from(value: ConstructorEntryPointExecutionError) -> Self {
match value {
ConstructorEntryPointExecutionError::ExecutionError { error, .. } => error,
}
}
}

#[derive(Debug, Error)]
pub enum ContractClassError {
#[error(
Expand Down
63 changes: 32 additions & 31 deletions crates/blockifier/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,32 +243,41 @@ macro_rules! check_entry_point_execution_error_for_custom_hint {

#[macro_export]
macro_rules! check_transaction_execution_error_inner {
($error:expr, $expected_hint:expr, $variant:ident $(,)?) => {
match $error {
$crate::transaction::errors::TransactionExecutionError::$variant { error, .. } => {
$crate::check_entry_point_execution_error!(error, $expected_hint)
($error:expr, $expected_hint:expr, $validate_constructor:expr $(,)?) => {
if $validate_constructor {
match $error {
$crate::transaction::errors::TransactionExecutionError::
ContractConstructorExecutionFailed(
$crate::execution::errors::ConstructorEntryPointExecutionError::ExecutionError {
error, ..
}
) => {
$crate::check_entry_point_execution_error!(error, $expected_hint)
}
_ => panic!("Unexpected structure for error: {:?}", $error),
}
} else {
match $error {
$crate::transaction::errors::TransactionExecutionError::ValidateTransactionError {
error,
..
} => {
$crate::check_entry_point_execution_error!(error, $expected_hint)
}
_ => panic!("Unexpected structure for error: {:?}", $error),
}
_ => panic!("Unexpected structure for error: {:?}", $error),
}
};
}

#[macro_export]
macro_rules! check_transaction_execution_error_for_custom_hint {
($error:expr, $expected_hint:expr, $validate_constructor:expr $(,)?) => {
if $validate_constructor {
$crate::check_transaction_execution_error_inner!(
$error,
Some($expected_hint),
ContractConstructorExecutionFailed,
);
} else {
$crate::check_transaction_execution_error_inner!(
$error,
Some($expected_hint),
ValidateTransactionError,
);
}
$crate::check_transaction_execution_error_inner!(
$error,
Some($expected_hint),
$validate_constructor,
);
};
}

Expand All @@ -279,19 +288,11 @@ macro_rules! check_transaction_execution_error_for_invalid_scenario {
($cairo_version:expr, $error:expr, $validate_constructor:expr $(,)?) => {
match $cairo_version {
CairoVersion::Cairo0 => {
if $validate_constructor {
$crate::check_transaction_execution_error_inner!(
$error,
None::<&str>,
ContractConstructorExecutionFailed,
);
} else {
$crate::check_transaction_execution_error_inner!(
$error,
None::<&str>,
ValidateTransactionError,
);
}
$crate::check_transaction_execution_error_inner!(
$error,
None::<&str>,
$validate_constructor,
);
}
CairoVersion::Cairo1 => {
if let $crate::transaction::errors::TransactionExecutionError::ValidateTransactionError {
Expand Down
13 changes: 6 additions & 7 deletions crates/blockifier/src/transaction/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use starknet_api::StarknetApiError;
use thiserror::Error;

use crate::execution::call_info::Retdata;
use crate::execution::errors::{gen_transaction_execution_error_trace, EntryPointExecutionError};
use crate::execution::errors::{
gen_transaction_execution_error_trace, ConstructorEntryPointExecutionError,
EntryPointExecutionError,
};
use crate::fee::fee_checks::FeeCheckError;
use crate::state::errors::StateError;

Expand Down Expand Up @@ -56,12 +59,8 @@ pub enum TransactionExecutionError {
version {cairo_version:?}."
)]
ContractClassVersionMismatch { declare_version: TransactionVersion, cairo_version: u64 },
#[error("Contract constructor execution has failed: {error}")]
ContractConstructorExecutionFailed {
error: EntryPointExecutionError,
class_hash: ClassHash,
storage_address: ContractAddress,
},
#[error(transparent)]
ContractConstructorExecutionFailed(#[from] ConstructorEntryPointExecutionError),
#[error("Class with hash {class_hash:?} is already declared.")]
DeclareTransactionError { class_hash: ClassHash },
#[error("Transaction execution has failed:\n{}", gen_transaction_execution_error_trace(self))]
Expand Down
12 changes: 2 additions & 10 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,14 @@ impl<S: State> Executable<S> for DeployAccountTransaction {
storage_address: self.contract_address,
caller_address: ContractAddress::default(),
};
let deployment_result = execute_deployment(
let call_info = execute_deployment(
state,
resources,
context,
ctor_context,
self.constructor_calldata(),
*remaining_gas,
);
let call_info = deployment_result.map_err(|error| {
TransactionExecutionError::ContractConstructorExecutionFailed {
// TODO(Dori, 5/5/2024): Add the constructor error to the error enum.
error: error.into(),
class_hash,
storage_address: self.contract_address,
}
})?;
)?;
update_remaining_gas(remaining_gas, &call_info);

Ok(Some(call_info))
Expand Down
25 changes: 17 additions & 8 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::execution::call_info::{
CallExecution, CallInfo, MessageToL1, OrderedEvent, OrderedL2ToL1Message, Retdata,
};
use crate::execution::entry_point::{CallEntryPoint, CallType};
use crate::execution::errors::EntryPointExecutionError;
use crate::execution::errors::{ConstructorEntryPointExecutionError, EntryPointExecutionError};
use crate::execution::execution_utils::{felt_to_stark_felt, stark_felt_to_felt};
use crate::execution::syscalls::hint_processor::EmitEventError;
use crate::execution::syscalls::SyscallSelector;
Expand Down Expand Up @@ -1362,10 +1362,14 @@ fn test_deploy_account_tx(
let error = account_tx.execute(state, block_context, true, true).unwrap_err();
assert_matches!(
error,
TransactionExecutionError::ContractConstructorExecutionFailed {
error: EntryPointExecutionError::StateError(StateError::UnavailableContractAddress(_)),
..
}
TransactionExecutionError::ContractConstructorExecutionFailed(
ConstructorEntryPointExecutionError::ExecutionError {
error: EntryPointExecutionError::StateError(
StateError::UnavailableContractAddress(_)
),
..
}
)
);
}

Expand Down Expand Up @@ -1394,9 +1398,14 @@ fn test_fail_deploy_account_undeclared_class_hash(block_context: BlockContext) {
let error = account_tx.execute(state, block_context, true, true).unwrap_err();
assert_matches!(
error,
TransactionExecutionError::ContractConstructorExecutionFailed{
error: EntryPointExecutionError::StateError(StateError::UndeclaredClassHash(class_hash)), ..
}
TransactionExecutionError::ContractConstructorExecutionFailed(
ConstructorEntryPointExecutionError::ExecutionError {
error: EntryPointExecutionError::StateError(
StateError::UndeclaredClassHash(class_hash)
),
..
}
)
if class_hash == undeclared_hash
);
}
Expand Down

0 comments on commit 9cd740b

Please sign in to comment.