Skip to content

Commit

Permalink
RPC 0.8.0: restructure errors (#627)
Browse files Browse the repository at this point in the history
* Move and rename tx status struct; add failure_reason

* Rename InsufficientMaxFee to InsufficientResourcesForValidate

* Improve panicking_contract: compile with 2.8.0, add method for distant panic
  • Loading branch information
FabijanC authored Oct 21, 2024
1 parent fb8a645 commit 9e5bc95
Show file tree
Hide file tree
Showing 26 changed files with 1,185 additions and 269 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
Compiled using cairo 2.2.0
Compiled using cairo 2.8.0
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
use core::starknet::ContractAddress;

#[starknet::interface]
trait IPanickingContract<TContractState> {
fn create_panic(self: @TContractState, panic_reason: felt252);
fn create_panic_in_another_contract(self: @TContractState, address: ContractAddress, panic_reason: felt252);
}

#[starknet::contract]
mod PanickingContract {
use core::starknet::{ContractAddress, call_contract_syscall};

#[storage]
struct Storage {}

#[external(v0)]
#[abi(embed_v0)]
impl PanickingContract of super::IPanickingContract<ContractState> {
fn create_panic(self: @ContractState, panic_reason: felt252) {
panic_with_felt252(panic_reason);
}

fn create_panic_in_another_contract(self: @ContractState, address: ContractAddress, panic_reason: felt252) {
call_contract_syscall(
address,
selector!("create_panic"),
array![panic_reason].span()
).unwrap();
}
}
}

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/starknet-devnet-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ description = "Starknet core logic for devnet"
[dependencies]
blockifier = { workspace = true, features = ["testing"] }
cairo-lang-starknet-classes = { workspace = true }
cairo-vm = { workspace = true }
clap = { workspace = true }
ethers = { workspace = true }
starknet_api = { workspace = true, features = ["testing"] }
Expand Down
22 changes: 14 additions & 8 deletions crates/starknet-devnet-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use starknet_types::contract_address::ContractAddress;
use starknet_types::contract_storage_key::ContractStorageKey;
use thiserror::Error;

use crate::stack_trace::{gen_tx_execution_error_trace, ErrorStack};

#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
Expand All @@ -12,12 +14,10 @@ pub enum Error {
StateError(#[from] StateError),
#[error(transparent)]
BlockifierStateError(#[from] blockifier::state::errors::StateError),
#[error(transparent)]
BlockifierTransactionError(#[from] blockifier::transaction::errors::TransactionExecutionError),
#[error(transparent)]
BlockifierExecutionError(#[from] blockifier::execution::errors::EntryPointExecutionError),
#[error("{revert_error}")]
ExecutionError { revert_error: String },
#[error("{0:?}")]
ContractExecutionError(ErrorStack),
#[error("Execution error in simulating transaction no. {failure_index}: {error_stack:?}")]
ContractExecutionErrorInSimulation { failure_index: u64, error_stack: ErrorStack },
#[error("Types error: {0}")]
TypesError(#[from] starknet_types::error::Error),
#[error("I/O error: {0}")]
Expand Down Expand Up @@ -78,6 +78,12 @@ impl From<starknet_types_core::felt::FromStrError> for Error {
}
}

impl From<blockifier::transaction::errors::TransactionExecutionError> for Error {
fn from(e: blockifier::transaction::errors::TransactionExecutionError) -> Self {
Self::ContractExecutionError(gen_tx_execution_error_trace(&e))
}
}

#[derive(Debug, Error)]
pub enum StateError {
#[error("No class hash {0:x} found")]
Expand All @@ -94,8 +100,8 @@ pub enum StateError {

#[derive(Debug, Error)]
pub enum TransactionValidationError {
#[error("Provided max fee is not enough to cover the transaction cost.")]
InsufficientMaxFee,
#[error("The transaction's resources don't cover validation or the minimal transaction fee.")]
InsufficientResourcesForValidate,
#[error("Account transaction nonce is invalid.")]
InvalidTransactionNonce,
#[error("Account balance is not enough to cover the transaction cost.")]
Expand Down
1 change: 1 addition & 0 deletions crates/starknet-devnet-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod error;
pub mod messaging;
mod predeployed_accounts;
pub mod raw_execution;
pub mod stack_trace;
pub mod starknet;
mod state;
mod system_contract;
Expand Down
Loading

0 comments on commit 9e5bc95

Please sign in to comment.