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

Commit ef8d42b

Browse files
authored
Merge branch 'main' into syscall_response_doc
2 parents fd4cf9c + 5448721 commit ef8d42b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1195
-840
lines changed

bench/internals.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use starknet_in_rust::{
1717
transaction::{declare::Declare, Deploy, DeployAccount, InvokeFunction},
1818
utils::Address,
1919
};
20-
use std::hint::black_box;
20+
use std::{hint::black_box, sync::Arc};
2121

2222
lazy_static! {
2323
// include_str! doesn't seem to work in CI
@@ -60,7 +60,7 @@ fn main() {
6060
fn deploy_account() {
6161
const RUNS: usize = 500;
6262

63-
let state_reader = InMemoryStateReader::default();
63+
let state_reader = Arc::new(InMemoryStateReader::default());
6464
let mut state = CachedState::new(state_reader, Some(Default::default()), None);
6565

6666
state
@@ -96,7 +96,7 @@ fn deploy_account() {
9696
fn declare() {
9797
const RUNS: usize = 5;
9898

99-
let state_reader = InMemoryStateReader::default();
99+
let state_reader = Arc::new(InMemoryStateReader::default());
100100
let state = CachedState::new(state_reader, Some(Default::default()), None);
101101

102102
let block_context = &Default::default();
@@ -128,7 +128,7 @@ fn declare() {
128128
fn deploy() {
129129
const RUNS: usize = 8;
130130

131-
let state_reader = InMemoryStateReader::default();
131+
let state_reader = Arc::new(InMemoryStateReader::default());
132132
let mut state = CachedState::new(state_reader, Some(Default::default()), None);
133133

134134
state
@@ -163,7 +163,7 @@ fn deploy() {
163163
fn invoke() {
164164
const RUNS: usize = 100;
165165

166-
let state_reader = InMemoryStateReader::default();
166+
let state_reader = Arc::new(InMemoryStateReader::default());
167167
let mut state = CachedState::new(state_reader, Some(Default::default()), None);
168168

169169
state

cli/src/main.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,24 @@ use starknet_in_rust::{
1616
block_context::BlockContext,
1717
constants::{DECLARE_VERSION, TRANSACTION_VERSION},
1818
},
19-
execution::{execution_entry_point::ExecutionEntryPoint, TransactionExecutionContext},
19+
execution::{
20+
execution_entry_point::{ExecutionEntryPoint, ExecutionResult},
21+
TransactionExecutionContext,
22+
},
2023
hash_utils::calculate_contract_address,
2124
parser_errors::ParserError,
2225
serde_structs::read_abi,
2326
services::api::contract_classes::deprecated_contract_class::ContractClass,
24-
state::{
25-
cached_state::CachedState,
26-
state_api::{State, StateReader},
27-
},
27+
state::{cached_state::CachedState, state_api::State},
2828
state::{in_memory_state_reader::InMemoryStateReader, ExecutionResourcesManager},
29-
transaction::InvokeFunction,
29+
transaction::{error::TransactionError, InvokeFunction},
3030
utils::{felt_to_hash, string_to_hash, Address},
3131
};
32-
use std::{collections::HashMap, path::PathBuf, sync::Mutex};
32+
use std::{
33+
collections::HashMap,
34+
path::PathBuf,
35+
sync::{Arc, Mutex},
36+
};
3337

3438
#[derive(Parser)]
3539
struct Cli {
@@ -248,13 +252,18 @@ fn call_parser(
248252
None,
249253
0,
250254
);
251-
let call_info = execution_entry_point.execute(
255+
let block_context = BlockContext::default();
256+
let ExecutionResult { call_info, .. } = execution_entry_point.execute(
252257
cached_state,
253-
&BlockContext::default(),
258+
&block_context,
254259
&mut ExecutionResourcesManager::default(),
255260
&mut TransactionExecutionContext::default(),
256261
false,
262+
block_context.invoke_tx_max_n_steps(),
257263
)?;
264+
265+
let call_info = call_info.ok_or(TransactionError::CallInfoIsNone)?;
266+
258267
Ok(call_info.retdata)
259268
}
260269

@@ -303,7 +312,7 @@ async fn call_req(data: web::Data<AppState>, args: web::Json<CallArgs>) -> HttpR
303312
pub async fn start_devnet(port: u16) -> Result<(), std::io::Error> {
304313
let cached_state = web::Data::new(AppState {
305314
cached_state: Mutex::new(CachedState::<InMemoryStateReader>::new(
306-
InMemoryStateReader::default(),
315+
Arc::new(InMemoryStateReader::default()),
307316
Some(HashMap::new()),
308317
None,
309318
)),

fuzzer/src/main.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern crate honggfuzz;
66
use cairo_vm::felt::Felt252;
77
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
88
use num_traits::Zero;
9+
use starknet_in_rust::execution::execution_entry_point::ExecutionResult;
910
use starknet_in_rust::EntryPointType;
1011
use starknet_in_rust::{
1112
definitions::{block_context::BlockContext, constants::TRANSACTION_VERSION},
@@ -18,6 +19,7 @@ use starknet_in_rust::{
1819
utils::{calculate_sn_keccak, Address},
1920
};
2021

22+
use std::sync::Arc;
2123
use std::{
2224
collections::{HashMap, HashSet},
2325
path::PathBuf,
@@ -124,7 +126,8 @@ fn main() {
124126
//* Create state with previous data
125127
//* ---------------------------------------
126128

127-
let mut state = CachedState::new(state_reader, Some(contract_class_cache), None);
129+
let mut state =
130+
CachedState::new(Arc::new(state_reader), Some(contract_class_cache), None);
128131

129132
//* ------------------------------------
130133
//* Create execution entry point
@@ -180,18 +183,17 @@ fn main() {
180183
..Default::default()
181184
};
182185

183-
assert_eq!(
184-
exec_entry_point
185-
.execute(
186-
&mut state,
187-
&block_context,
188-
&mut resources_manager,
189-
&mut tx_execution_context,
190-
false,
191-
)
192-
.unwrap(),
193-
expected_call_info
194-
);
186+
let ExecutionResult { call_info, .. } = exec_entry_point
187+
.execute(
188+
&mut state,
189+
&block_context,
190+
&mut resources_manager,
191+
&mut tx_execution_context,
192+
false,
193+
block_context.invoke_tx_max_n_steps(),
194+
)
195+
.unwrap();
196+
assert_eq!(call_info.unwrap(), expected_call_info);
195197

196198
assert!(!state.cache().storage_writes().is_empty());
197199
assert_eq!(

src/bin/fibonacci.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashMap, path::PathBuf};
1+
use std::{collections::HashMap, path::PathBuf, sync::Arc};
22

33
use cairo_vm::felt::{felt_str, Felt252};
44
use num_traits::Zero;
@@ -85,7 +85,7 @@ fn create_initial_state() -> CachedState<InMemoryStateReader> {
8585
state_reader
8686
.address_to_storage_mut()
8787
.insert((CONTRACT_ADDRESS.clone(), [0; 32]), Felt252::zero());
88-
state_reader
88+
Arc::new(state_reader)
8989
},
9090
Some(HashMap::new()),
9191
None,

src/bin/invoke.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashMap, path::PathBuf};
1+
use std::{collections::HashMap, path::PathBuf, sync::Arc};
22

33
use cairo_vm::felt::{felt_str, Felt252};
44
use num_traits::Zero;
@@ -99,7 +99,7 @@ fn create_initial_state() -> CachedState<InMemoryStateReader> {
9999
state_reader
100100
.address_to_storage_mut()
101101
.insert((CONTRACT_ADDRESS.clone(), [0; 32]), Felt252::zero());
102-
state_reader
102+
Arc::new(state_reader)
103103
},
104104
Some(HashMap::new()),
105105
None,

src/bin/invoke_with_cachedstate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashMap, path::PathBuf};
1+
use std::{collections::HashMap, path::PathBuf, sync::Arc};
22

33
use cairo_vm::felt::{felt_str, Felt252};
44
use num_traits::Zero;
@@ -106,7 +106,7 @@ fn create_initial_state() -> CachedState<InMemoryStateReader> {
106106
state_reader
107107
.address_to_storage_mut()
108108
.insert((CONTRACT_ADDRESS.clone(), [0; 32]), Felt252::zero());
109-
state_reader
109+
Arc::new(state_reader)
110110
},
111111
Some(HashMap::new()),
112112
None,

src/definitions/constants.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ lazy_static! {
2222
pub(crate) const LOG_MSG_TO_L1_ENCODED_DATA_SIZE: usize =
2323
(L2_TO_L1_MSG_HEADER_SIZE + 1) - LOG_MSG_TO_L1_N_TOPICS;
2424

25+
/// Fee factor used for the final fee calculation:
26+
/// actual_fee = min(max_fee, consumed_resources) * FEE_FACTOR
27+
pub(crate) const FEE_FACTOR: u128 = 1;
28+
2529
/// The (empirical) L1 gas cost of each Cairo step.
2630
pub(crate) const N_STEPS_FEE_WEIGHT: f64 = 0.01;
2731

0 commit comments

Comments
 (0)