Skip to content

Commit e1f47f9

Browse files
committed
Review suggestions
1 parent 0ffd18b commit e1f47f9

File tree

4 files changed

+22
-139
lines changed

4 files changed

+22
-139
lines changed

crates/cheatnet/src/runtime_extensions/call_to_blockifier_runtime_extension/execution/cheated_syscalls.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub fn deploy_syscall(
8989
deployer_address
9090
};
9191

92+
// region: Modified blockifier code
9293
let deployed_contract_address =
9394
if let Some(contract_address) = cheatnet_state.next_address_for_deployment() {
9495
contract_address
@@ -100,6 +101,7 @@ pub fn deploy_syscall(
100101
deployer_address_for_calculation,
101102
)?
102103
};
104+
// endregion
103105

104106
let ctor_context = ConstructorContext {
105107
class_hash: request.class_hash,

crates/cheatnet/src/runtime_extensions/native/deploy.rs

Lines changed: 5 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,13 @@
1-
use crate::runtime_extensions::call_to_blockifier_runtime_extension::execution::entry_point::{
2-
ExecuteCallEntryPointExtraOptions, execute_call_entry_point,
3-
};
1+
use crate::runtime_extensions::call_to_blockifier_runtime_extension::execution::cheated_syscalls::execute_deployment;
42
use crate::runtime_extensions::native::native_syscall_handler::BaseSyscallResult;
53
use crate::state::CheatnetState;
64
use blockifier::execution::call_info::CallInfo;
7-
use blockifier::execution::entry_point::{
8-
CallEntryPoint, CallType, ConstructorContext, ConstructorEntryPointExecutionResult,
9-
EntryPointExecutionContext, handle_empty_constructor,
10-
};
11-
use blockifier::execution::errors::ConstructorEntryPointExecutionError;
5+
use blockifier::execution::entry_point::ConstructorContext;
126
use blockifier::execution::syscalls::syscall_base::SyscallHandlerBase;
137
use blockifier::execution::syscalls::vm_syscall_utils::SyscallSelector;
14-
use blockifier::state::errors::StateError;
15-
use blockifier::state::state_api::State;
16-
use starknet_api::contract_class::EntryPointType;
178
use starknet_api::core::{ClassHash, ContractAddress, calculate_contract_address};
189
use starknet_api::transaction::fields::{Calldata, ContractAddressSalt};
1910

20-
// Copied from blockifer/src/execution/entry_point.rs
21-
#[allow(clippy::result_large_err)]
22-
#[expect(clippy::needless_pass_by_value)]
23-
pub fn execute_constructor_entry_point(
24-
state: &mut dyn State,
25-
// region: Modified blockifer code
26-
cheatnet_state: &mut CheatnetState,
27-
// endregion
28-
context: &mut EntryPointExecutionContext,
29-
ctor_context: ConstructorContext,
30-
calldata: Calldata,
31-
remaining_gas: &mut u64,
32-
) -> ConstructorEntryPointExecutionResult<CallInfo> {
33-
// Ensure the class is declared (by reading it).
34-
let compiled_class = state
35-
.get_compiled_class(ctor_context.class_hash)
36-
.map_err(|error| {
37-
ConstructorEntryPointExecutionError::new(error.into(), &ctor_context, None)
38-
})?;
39-
let Some(constructor_selector) = compiled_class.constructor_selector() else {
40-
// region: Modified blockifer code
41-
cheatnet_state
42-
.trace_data
43-
.add_deploy_without_constructor_node();
44-
// endregion
45-
// Contract has no constructor.
46-
return handle_empty_constructor(
47-
compiled_class,
48-
context,
49-
&ctor_context,
50-
calldata,
51-
*remaining_gas,
52-
)
53-
.map_err(|error| ConstructorEntryPointExecutionError::new(error, &ctor_context, None));
54-
};
55-
56-
let mut constructor_call = CallEntryPoint {
57-
class_hash: None,
58-
code_address: ctor_context.code_address,
59-
entry_point_type: EntryPointType::Constructor,
60-
entry_point_selector: constructor_selector,
61-
calldata,
62-
storage_address: ctor_context.storage_address,
63-
caller_address: ctor_context.caller_address,
64-
call_type: CallType::Call,
65-
initial_gas: *remaining_gas,
66-
};
67-
68-
// region: Modified blockifer code
69-
let call_info = execute_call_entry_point(
70-
&mut constructor_call,
71-
state,
72-
cheatnet_state,
73-
context,
74-
remaining_gas,
75-
&ExecuteCallEntryPointExtraOptions {
76-
trace_data_handled_by_revert_call: false,
77-
},
78-
)
79-
.map_err(|error| {
80-
ConstructorEntryPointExecutionError::new(error, &ctor_context, Some(constructor_selector))
81-
})?;
82-
83-
Ok(call_info)
84-
// endregion
85-
}
86-
87-
#[expect(clippy::result_large_err)]
88-
// Copied from blockifer/src/execution/execution_utils.rs
89-
fn execute_deployment(
90-
state: &mut dyn State,
91-
cheatnet_state: &mut CheatnetState,
92-
context: &mut EntryPointExecutionContext,
93-
ctor_context: ConstructorContext,
94-
constructor_calldata: Calldata,
95-
remaining_gas: &mut u64,
96-
) -> ConstructorEntryPointExecutionResult<CallInfo> {
97-
// Address allocation in the state is done before calling the constructor, so that it is
98-
// visible from it.
99-
let deployed_contract_address = ctor_context.storage_address;
100-
let current_class_hash =
101-
state
102-
.get_class_hash_at(deployed_contract_address)
103-
.map_err(|error| {
104-
ConstructorEntryPointExecutionError::new(error.into(), &ctor_context, None)
105-
})?;
106-
if current_class_hash != ClassHash::default() {
107-
return Err(ConstructorEntryPointExecutionError::new(
108-
StateError::UnavailableContractAddress(deployed_contract_address).into(),
109-
&ctor_context,
110-
None,
111-
));
112-
}
113-
114-
state
115-
.set_class_hash_at(deployed_contract_address, ctor_context.class_hash)
116-
.map_err(|error| {
117-
ConstructorEntryPointExecutionError::new(error.into(), &ctor_context, None)
118-
})?;
119-
120-
execute_constructor_entry_point(
121-
state,
122-
cheatnet_state,
123-
context,
124-
ctor_context,
125-
constructor_calldata,
126-
remaining_gas,
127-
)
128-
}
129-
13011
#[expect(clippy::match_bool, clippy::result_large_err)]
13112
// Copied from blockifer/src/execution/syscalls/syscall_base.rs
13213
pub fn deploy(
@@ -140,12 +21,13 @@ pub fn deploy(
14021
) -> BaseSyscallResult<(ContractAddress, CallInfo)> {
14122
syscall_handler_base
14223
.increment_syscall_linear_factor_by(&SyscallSelector::Deploy, constructor_calldata.0.len());
24+
25+
// TODO(#3790) support for reject
14326
// let versioned_constants = &syscall_handler_base
14427
// .context
14528
// .tx_context
14629
// .block_context
14730
// .versioned_constants;
148-
// TODO(#3790) support for reject
14931
// if should_reject_deploy(
15032
// versioned_constants.disable_deploy_in_validation_mode,
15133
// syscall_handler_base.context.execution_mode,
@@ -176,7 +58,7 @@ pub fn deploy(
17658
syscall_handler_base.state,
17759
cheatnet_state,
17860
syscall_handler_base.context,
179-
ctor_context,
61+
&ctor_context,
18062
constructor_calldata,
18163
remaining_gas,
18264
)?;

crates/cheatnet/src/runtime_extensions/native/execution.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,23 @@ pub(crate) fn execute_entry_point_call_native(
4848
})
4949
}
5050

51-
// Copied from blockifier
52-
// todo(rodrigo): add an `entry point not found` test for Native
51+
// Based on https://github.com/software-mansion-labs/sequencer/blob/b6d1c0b354d84225ab9c47f8ff28663d22e84d19/crates/blockifier/src/execution/native/entry_point_execution.rs#L20
5352
#[allow(clippy::result_large_err)]
54-
pub fn execute_entry_point_call(
53+
fn execute_entry_point_call(
5554
call: &ExecutableCallEntryPoint,
5655
compiled_class: &NativeCompiledClassV1,
57-
// state: &mut dyn State,
58-
// context: &mut EntryPointExecutionContext,
56+
// region: Modified blockifier code
5957
syscall_handler: &mut CheatableNativeSyscallHandler,
58+
// endregion
6059
) -> EntryPointExecutionResult<CallInfo> {
6160
let entry_point = compiled_class.get_entry_point(&call.type_and_selector())?;
6261

63-
// let mut syscall_handler: NativeSyscallHandler<'_> =
64-
// NativeSyscallHandler::new(call, state, context);
65-
6662
let gas_costs = &syscall_handler
6763
.native_syscall_handler
6864
.base
6965
.context
7066
.gas_costs();
7167
let builtin_costs = BuiltinCosts {
72-
// todo(rodrigo): Unsure of what value `const` means, but 1 is the right value.
7368
r#const: 1,
7469
pedersen: gas_costs.builtins.pedersen,
7570
bitwise: gas_costs.builtins.bitwise,
@@ -125,7 +120,7 @@ pub fn execute_entry_point_call(
125120
create_callinfo(call_result, syscall_handler)
126121
}
127122

128-
// Copied from blockifier
123+
// Copied from https://github.com/software-mansion-labs/sequencer/blob/b6d1c0b354d84225ab9c47f8ff28663d22e84d19/crates/blockifier/src/execution/native/entry_point_execution.rs#L73
129124
#[allow(clippy::result_large_err)]
130125
fn create_callinfo(
131126
call_result: ContractExecutionResult,

crates/cheatnet/src/runtime_extensions/native/native_syscall_handler.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl CheatableNativeSyscallHandler<'_> {
3838
self.native_syscall_handler.unrecoverable_error.take()
3939
}
4040

41+
// Copied from https://github.com/software-mansion-labs/sequencer/blob/b6d1c0b354d84225ab9c47f8ff28663d22e84d19/crates/blockifier/src/execution/native/syscall_handler.rs#L80
4142
/// Handles all gas-related logics, syscall usage counting and perform additional checks. In
4243
/// native, we need to explicitly call this method at the beginning of each syscall.
4344
#[allow(clippy::result_large_err)]
@@ -98,7 +99,7 @@ impl CheatableNativeSyscallHandler<'_> {
9899
Ok(())
99100
}
100101

101-
// Copied from blockifer/src/exection/native/syscall_handler.rs
102+
// Based on https://github.com/software-mansion-labs/sequencer/blob/b6d1c0b354d84225ab9c47f8ff28663d22e84d19/crates/blockifier/src/execution/native/syscall_handler.rs#L153
102103
#[allow(clippy::result_large_err)]
103104
fn execute_inner_call(
104105
&mut self,
@@ -113,7 +114,6 @@ impl CheatableNativeSyscallHandler<'_> {
113114
) -> SyscallExecutionError,
114115
) -> SyscallResult<Retdata> {
115116
let entry_point_clone = entry_point.clone();
116-
// region: Modified blockifier code
117117
let raw_data = execute_inner_call(
118118
&mut self.native_syscall_handler.base,
119119
self.cheatnet_state,
@@ -135,10 +135,10 @@ impl CheatableNativeSyscallHandler<'_> {
135135
)),
136136
)
137137
})?;
138-
// endregion
139138
Ok(Retdata(raw_data))
140139
}
141140

141+
// Copied from https://github.com/software-mansion-labs/sequencer/blob/b6d1c0b354d84225ab9c47f8ff28663d22e84d19/crates/blockifier/src/execution/native/syscall_handler.rs#L124
142142
fn handle_error(&mut self, remaining_gas: &mut u64, error: SyscallExecutionError) -> Vec<Felt> {
143143
// In case of more than one inner call and because each inner call has their own
144144
// syscall handler, if there is an unrecoverable error at call `n` it will create a
@@ -263,7 +263,7 @@ impl StarknetSyscallHandler for &mut CheatableNativeSyscallHandler<'_> {
263263
.tx_info
264264
.nonce
265265
.unwrap_or(original_data.tx_info.nonce);
266-
// TODO(#3790) impl conversions
266+
// TODO(#3790) implement conversions
267267
let resource_bounds = cheated_data.tx_info.resource_bounds.map_or(
268268
original_data.tx_info.resource_bounds,
269269
|rb| {
@@ -336,6 +336,7 @@ impl StarknetSyscallHandler for &mut CheatableNativeSyscallHandler<'_> {
336336
})
337337
}
338338

339+
// Based on https://github.com/software-mansion-labs/sequencer/blob/b6d1c0b354d84225ab9c47f8ff28663d22e84d19/crates/blockifier/src/execution/native/syscall_handler.rs#L322
339340
fn deploy(
340341
&mut self,
341342
class_hash: Felt,
@@ -355,6 +356,7 @@ impl StarknetSyscallHandler for &mut CheatableNativeSyscallHandler<'_> {
355356

356357
self.pre_execute_syscall(remaining_gas, total_gas_cost, SyscallSelector::Deploy)?;
357358

359+
// region: Modified blockifier code
358360
let (deployed_contract_address, call_info) = deploy(
359361
&mut self.native_syscall_handler.base,
360362
self.cheatnet_state,
@@ -364,6 +366,7 @@ impl StarknetSyscallHandler for &mut CheatableNativeSyscallHandler<'_> {
364366
deploy_from_zero,
365367
remaining_gas,
366368
)
369+
// endregion
367370
.map_err(|err| self.handle_error(remaining_gas, err))?;
368371

369372
let constructor_retdata = call_info.execution.retdata.0[..].to_vec();
@@ -377,7 +380,7 @@ impl StarknetSyscallHandler for &mut CheatableNativeSyscallHandler<'_> {
377380
.replace_class(class_hash, remaining_gas)
378381
}
379382

380-
// Copied from blockifier/src/execution/native/syscall_handler.rs
383+
// Based on from https://github.com/software-mansion-labs/sequencer/blob/b6d1c0b354d84225ab9c47f8ff28663d22e84d19/crates/blockifier/src/execution/native/syscall_handler.rs#L399
381384
fn library_call(
382385
&mut self,
383386
class_hash: Felt,
@@ -432,7 +435,7 @@ impl StarknetSyscallHandler for &mut CheatableNativeSyscallHandler<'_> {
432435
.0)
433436
}
434437

435-
// Copied from blockifier/src/execution/native/syscall_handler.rs
438+
// Based on https://github.com/software-mansion-labs/sequencer/blob/b6d1c0b354d84225ab9c47f8ff28663d22e84d19/crates/blockifier/src/execution/native/syscall_handler.rs#L444
436439
fn call_contract(
437440
&mut self,
438441
address: Felt,
@@ -714,6 +717,7 @@ impl StarknetSyscallHandler for &mut CheatableNativeSyscallHandler<'_> {
714717
.get_class_hash_at(contract_address, remaining_gas)
715718
}
716719

720+
// TODO(#3790) Support cheating meta_tx_v0
717721
fn meta_tx_v0(
718722
&mut self,
719723
address: Felt,

0 commit comments

Comments
 (0)