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

Add reverted transactions #813

Merged
merged 26 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c22e729
Remove mutable ref from StateReader
matias-gonz Jul 12, 2023
2ddd8ee
Fix tests
matias-gonz Jul 12, 2023
7642686
Merge branch 'main' into add_reverted_transactions
matias-gonz Jul 12, 2023
fb72c5f
Fix tests
matias-gonz Jul 12, 2023
64275e9
Fix cairo2 tests
matias-gonz Jul 12, 2023
d919779
Merge branch 'main' into add_reverted_transactions
matias-gonz Jul 12, 2023
5255679
Fix clippy
matias-gonz Jul 12, 2023
a381558
Add tmp_state
matias-gonz Jul 12, 2023
9c81834
Fix tmp_state
matias-gonz Jul 12, 2023
a8c6374
Remove unused max steps
matias-gonz Jul 13, 2023
d188af1
Revert "Remove unused max steps"
matias-gonz Jul 13, 2023
9988b5d
Add reverted Transactions
matias-gonz Jul 13, 2023
998f3ee
Add revert_error to TransactionExecutionInfo
matias-gonz Jul 13, 2023
3c6e77b
Test test_reverted_transaction_wrong_entry_point
matias-gonz Jul 13, 2023
214e2ab
Disable reverted transaction for declare verify
matias-gonz Jul 14, 2023
7765b09
Merge branch 'main' into add_reverted_transactions
matias-gonz Jul 14, 2023
c0ef66b
Merge branch 'main' into add_reverted_transactions
matias-gonz Jul 15, 2023
b0d9016
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into a…
matias-gonz Jul 17, 2023
0dac004
Replace empty for default
matias-gonz Jul 17, 2023
ca674c2
Update CachedState
matias-gonz Jul 17, 2023
5ac6c7b
Merge branch 'main' into add_reverted_transactions
matias-gonz Jul 17, 2023
2d9d9fc
Merge branch 'main' into add_reverted_transactions
matias-gonz Jul 17, 2023
91fef34
Fix tests
matias-gonz Jul 17, 2023
3c9c549
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into a…
matias-gonz Jul 17, 2023
9050219
Fix test
matias-gonz Jul 17, 2023
03ede4c
Remove unused imports
matias-gonz Jul 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bench/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use starknet_in_rust::{
transaction::{declare::Declare, Deploy, DeployAccount, InvokeFunction},
utils::Address,
};
use std::hint::black_box;
use std::{hint::black_box, sync::Arc};

lazy_static! {
// include_str! doesn't seem to work in CI
Expand Down Expand Up @@ -60,7 +60,7 @@ fn main() {
fn deploy_account() {
const RUNS: usize = 500;

let state_reader = InMemoryStateReader::default();
let state_reader = Arc::new(InMemoryStateReader::default());
let mut state = CachedState::new(state_reader, Some(Default::default()), None);

state
Expand Down Expand Up @@ -96,7 +96,7 @@ fn deploy_account() {
fn declare() {
const RUNS: usize = 5;

let state_reader = InMemoryStateReader::default();
let state_reader = Arc::new(InMemoryStateReader::default());
let state = CachedState::new(state_reader, Some(Default::default()), None);

let block_context = &Default::default();
Expand Down Expand Up @@ -128,7 +128,7 @@ fn declare() {
fn deploy() {
const RUNS: usize = 8;

let state_reader = InMemoryStateReader::default();
let state_reader = Arc::new(InMemoryStateReader::default());
let mut state = CachedState::new(state_reader, Some(Default::default()), None);

state
Expand Down Expand Up @@ -163,7 +163,7 @@ fn deploy() {
fn invoke() {
const RUNS: usize = 100;

let state_reader = InMemoryStateReader::default();
let state_reader = Arc::new(InMemoryStateReader::default());
let mut state = CachedState::new(state_reader, Some(Default::default()), None);

state
Expand Down
29 changes: 19 additions & 10 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@ use starknet_in_rust::{
block_context::BlockContext,
constants::{DECLARE_VERSION, TRANSACTION_VERSION},
},
execution::{execution_entry_point::ExecutionEntryPoint, TransactionExecutionContext},
execution::{
execution_entry_point::{ExecutionEntryPoint, ExecutionResult},
TransactionExecutionContext,
},
hash_utils::calculate_contract_address,
parser_errors::ParserError,
serde_structs::read_abi,
services::api::contract_classes::deprecated_contract_class::ContractClass,
state::{
cached_state::CachedState,
state_api::{State, StateReader},
},
state::{cached_state::CachedState, state_api::State},
state::{in_memory_state_reader::InMemoryStateReader, ExecutionResourcesManager},
transaction::InvokeFunction,
transaction::{error::TransactionError, InvokeFunction},
utils::{felt_to_hash, string_to_hash, Address},
};
use std::{collections::HashMap, path::PathBuf, sync::Mutex};
use std::{
collections::HashMap,
path::PathBuf,
sync::{Arc, Mutex},
};

#[derive(Parser)]
struct Cli {
Expand Down Expand Up @@ -248,13 +252,18 @@ fn call_parser(
None,
0,
);
let call_info = execution_entry_point.execute(
let block_context = BlockContext::default();
let ExecutionResult { call_info, .. } = execution_entry_point.execute(
cached_state,
&BlockContext::default(),
&block_context,
&mut ExecutionResourcesManager::default(),
&mut TransactionExecutionContext::default(),
false,
block_context.invoke_tx_max_n_steps(),
)?;

let call_info = call_info.ok_or(TransactionError::CallInfoIsNone)?;

Ok(call_info.retdata)
}

Expand Down Expand Up @@ -303,7 +312,7 @@ async fn call_req(data: web::Data<AppState>, args: web::Json<CallArgs>) -> HttpR
pub async fn start_devnet(port: u16) -> Result<(), std::io::Error> {
let cached_state = web::Data::new(AppState {
cached_state: Mutex::new(CachedState::<InMemoryStateReader>::new(
InMemoryStateReader::default(),
Arc::new(InMemoryStateReader::default()),
Some(HashMap::new()),
None,
)),
Expand Down
28 changes: 15 additions & 13 deletions fuzzer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate honggfuzz;
use cairo_vm::felt::Felt252;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use num_traits::Zero;
use starknet_in_rust::execution::execution_entry_point::ExecutionResult;
use starknet_in_rust::EntryPointType;
use starknet_in_rust::{
definitions::{block_context::BlockContext, constants::TRANSACTION_VERSION},
Expand All @@ -18,6 +19,7 @@ use starknet_in_rust::{
utils::{calculate_sn_keccak, Address},
};

use std::sync::Arc;
use std::{
collections::{HashMap, HashSet},
path::PathBuf,
Expand Down Expand Up @@ -124,7 +126,8 @@ fn main() {
//* Create state with previous data
//* ---------------------------------------

let mut state = CachedState::new(state_reader, Some(contract_class_cache), None);
let mut state =
CachedState::new(Arc::new(state_reader), Some(contract_class_cache), None);

//* ------------------------------------
//* Create execution entry point
Expand Down Expand Up @@ -180,18 +183,17 @@ fn main() {
..Default::default()
};

assert_eq!(
exec_entry_point
.execute(
&mut state,
&block_context,
&mut resources_manager,
&mut tx_execution_context,
false,
)
.unwrap(),
expected_call_info
);
let ExecutionResult { call_info, .. } = exec_entry_point
.execute(
&mut state,
&block_context,
&mut resources_manager,
&mut tx_execution_context,
false,
block_context.invoke_tx_max_n_steps(),
)
.unwrap();
assert_eq!(call_info.unwrap(), expected_call_info);

assert!(!state.cache().storage_writes().is_empty());
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions src/bin/fibonacci.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, path::PathBuf};
use std::{collections::HashMap, path::PathBuf, sync::Arc};

use cairo_vm::felt::{felt_str, Felt252};
use num_traits::Zero;
Expand Down Expand Up @@ -85,7 +85,7 @@ fn create_initial_state() -> CachedState<InMemoryStateReader> {
state_reader
.address_to_storage_mut()
.insert((CONTRACT_ADDRESS.clone(), [0; 32]), Felt252::zero());
state_reader
Arc::new(state_reader)
},
Some(HashMap::new()),
None,
Expand Down
4 changes: 2 additions & 2 deletions src/bin/invoke.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, path::PathBuf};
use std::{collections::HashMap, path::PathBuf, sync::Arc};

use cairo_vm::felt::{felt_str, Felt252};
use num_traits::Zero;
Expand Down Expand Up @@ -99,7 +99,7 @@ fn create_initial_state() -> CachedState<InMemoryStateReader> {
state_reader
.address_to_storage_mut()
.insert((CONTRACT_ADDRESS.clone(), [0; 32]), Felt252::zero());
state_reader
Arc::new(state_reader)
},
Some(HashMap::new()),
None,
Expand Down
4 changes: 2 additions & 2 deletions src/bin/invoke_with_cachedstate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, path::PathBuf};
use std::{collections::HashMap, path::PathBuf, sync::Arc};

use cairo_vm::felt::{felt_str, Felt252};
use num_traits::Zero;
Expand Down Expand Up @@ -106,7 +106,7 @@ fn create_initial_state() -> CachedState<InMemoryStateReader> {
state_reader
.address_to_storage_mut()
.insert((CONTRACT_ADDRESS.clone(), [0; 32]), Felt252::zero());
state_reader
Arc::new(state_reader)
},
Some(HashMap::new()),
None,
Expand Down
Loading