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

Add comments to syscalls/deprecated_business_logic_syscall_handler module #884

Merged
Merged
Changes from 2 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
320fae2
added comments to syscalls/deprecated_business_logic_syscall_handler.rs
Aug 3, 2023
7b2a895
Merge branch 'main' into document-syscalls/deprecated_business_logic_…
fguthmann Aug 4, 2023
3bb5b48
Merge branch 'main' into document-syscalls/deprecated_business_logic_…
fguthmann Aug 10, 2023
c47e7f4
corrected comments
Aug 10, 2023
831b5f8
added informations on system calls
Aug 10, 2023
16b0b96
Merge branch 'main' into document-syscalls/deprecated_business_logic_…
Aug 11, 2023
19368fd
change comments
Aug 11, 2023
b01235c
Merge branch 'main' into document-syscalls/deprecated_business_logic_…
juanbono Aug 28, 2023
d19dc79
Added Starknet API / Blockifier RPC State Reader (#927)
juanbono Aug 29, 2023
b740b92
Deserialize transactions too on the block info for the Rpc Reader SN …
edg-l Aug 30, 2023
d6c7d91
Unify deprecated and casm contract caches. (#937)
azteca1998 Aug 30, 2023
e7ad24d
Update README with Telegram group link and badge (#843)
juanbono Aug 30, 2023
05c0efe
From/TryFrom starknet api types (#962)
mmsc2 Aug 30, 2023
27ffa5d
Fix gas/fee price type consistency (to `u128`). (#987)
azteca1998 Aug 31, 2023
8cfd3b5
Fix `ExecutionResources::increment_syscall_counter` (#971)
fmoletta Sep 1, 2023
d939ece
minor code cleanup (#968)
edg-l Sep 1, 2023
74b3486
Added fee transfer storage update into `count_actual_storage_changes(…
xqft Sep 1, 2023
5c44880
Remove missing unwrap from codebase. (#1000)
azteca1998 Sep 4, 2023
11ce41b
refactor/ fix TryFrom InvokeTransaction into a standalone method on I…
edg-l Sep 4, 2023
3a71b9f
Deprecate old RPC StateReader in favor of `starknet_api` compatible o…
xqft Sep 4, 2023
b697c58
perf: remove clone from compute_sierra_class_hash (#1008)
Oppen Sep 5, 2023
a7493d1
fix: Read before writing when executing the deprecated version of `st…
fmoletta Sep 5, 2023
2dd1c8f
BREAKING: `StateReader::get_storage_at` return zero by default (#1011)
fmoletta Sep 5, 2023
5924395
BREAKING: `StateReader::get_class_hash_at` return zero by default (#1…
fmoletta Sep 6, 2023
820a336
RPC use test_case with local cache and add more tests (#970)
edg-l Sep 6, 2023
1b3c72f
Update cache initial values with write-only accesses in `CachedState:…
fmoletta Sep 6, 2023
f01ad8f
Refactor new RPC into several files (#1007)
edg-l Sep 6, 2023
87785e2
Fix storage changes count for transactions with fee transfers (#1015)
fmoletta Sep 6, 2023
ecc714e
fix estimate fee missing casmclasscache (#916)
marioiordanov Sep 7, 2023
6c47599
fix: declare v0 requires max_fee=0, consider for simulation (#1017)
Oppen Sep 7, 2023
4a16bcb
Remove redundant `tx_type` field from transactions. (#1019)
azteca1998 Sep 8, 2023
680798f
remove files and rename the new one (#1020)
juanbono Sep 8, 2023
c431027
Add contract class cache stats (#958)
fguthmann Sep 9, 2023
c1b1272
add tests and remove ignore on fixed ones (#1021)
juanbono Sep 12, 2023
affa012
perf: refactor substract_mappings and friends to avoid clones (#1023)
edg-l Sep 12, 2023
6046d75
Fix transactions bypassing the max_fee by introducing new revert logi…
xqft Sep 13, 2023
bdaaa95
fix get_sorted_events issue (#1024)
juanbono Sep 13, 2023
941a899
pin version (#1026)
juanbono Sep 13, 2023
2e7ee52
update version (#1028)
juanbono Sep 13, 2023
b8640a0
Fix coverage control mechanism. (#1035)
azteca1998 Sep 18, 2023
4eef09b
Fix SIR RPC get compiled class hash (#1032)
juanbono Sep 18, 2023
62c3b20
remove unneeded added set_compiled_class_hash (#1031)
edg-l Sep 18, 2023
d4fcd9d
Fix missing events (#1034)
edg-l Sep 18, 2023
7ec5494
fix wrong from_address in deprecated execute_constructor_entry_point …
edg-l Sep 20, 2023
7c1c1e6
remove testing, move erc20 test, update fibonacci bin (#1038)
edg-l Sep 21, 2023
21dab2c
Remove `serde_json_pythonic`. (#1047)
azteca1998 Sep 26, 2023
9c92f99
Add debug logging. (#1018)
azteca1998 Sep 26, 2023
9388df0
Fix skip validate (#1053)
juanbono Sep 29, 2023
8a5b75c
resolve merge conflict
Oct 2, 2023
e389bb7
resolve merge
Nov 20, 2023
f15fee7
Merge branch 'main' into document-syscalls/deprecated_business_logic_…
juanbono Nov 21, 2023
470323f
Merge branch 'main' into document-syscalls/deprecated_business_logic_…
fguthmann Nov 23, 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
61 changes: 57 additions & 4 deletions src/syscalls/deprecated_business_logic_syscall_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,34 @@ use num_traits::{One, ToPrimitive, Zero};
/// Deprecated version of BusinessLogicSyscallHandler.
#[derive(Debug)]
pub struct DeprecatedBLSyscallHandler<'a, S: StateReader> {
/// Context of the transaction being executed
pub(crate) tx_execution_context: TransactionExecutionContext,
/// Events emitted by the current contract call.
pub(crate) events: Vec<OrderedEvent>,
/// A list of dynamically allocated segments that are expected to be read-only.
pub(crate) read_only_segments: Vec<(Relocatable, MaybeRelocatable)>,
/// Manages execution resources
pub(crate) resources_manager: ExecutionResourcesManager,
/// Address of the contract
pub(crate) contract_address: Address,
/// Address of the caller
pub(crate) caller_address: Address,
/// Messages from L2 to L1
pub(crate) l2_to_l1_messages: Vec<OrderedL2ToL1Message>,
/// Context information related to the current block
pub(crate) block_context: BlockContext,
/// Pointer to transaction information
pub(crate) tx_info_ptr: Option<MaybeRelocatable>,
/// State of the storage related to Starknet contract
pub(crate) starknet_storage_state: ContractStorageState<'a, S>,
/// Information about internal calls
fguthmann marked this conversation as resolved.
Show resolved Hide resolved
pub(crate) internal_calls: Vec<CallInfo>,
/// Pointer to the expected system call
fguthmann marked this conversation as resolved.
Show resolved Hide resolved
pub(crate) expected_syscall_ptr: Relocatable,
}

impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
/// Constructor creates a new DeprecatedBLSyscallHandler instance
fguthmann marked this conversation as resolved.
Show resolved Hide resolved
pub fn new(
tx_execution_context: TransactionExecutionContext,
state: &'a mut CachedState<S>,
Expand Down Expand Up @@ -100,6 +111,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
}
}

/// Constructor with default values, used for testing
pub fn default_with(state: &'a mut CachedState<S>) -> Self {
DeprecatedBLSyscallHandler::new_for_testing(BlockInfo::default(), Default::default(), state)
}
Expand All @@ -110,6 +122,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
.increment_syscall_counter(syscall_name, 1);
}

/// Constructor for testing purposes
pub fn new_for_testing(
block_info: BlockInfo,
_contract_address: Address,
Expand Down Expand Up @@ -181,6 +194,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(())
}

/// Checks if constructor entry points are empty
fn constructor_entry_points_empty(
&self,
contract_class: CompiledClass,
Expand All @@ -195,6 +209,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
}
}

/// Executes a constructor entry point
fn execute_constructor_entry_point(
&mut self,
contract_address: &Address,
Expand Down Expand Up @@ -247,16 +262,18 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
}

impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
/// Emit an event.
pub(crate) fn emit_event(
&mut self,
vm: &VirtualMachine,
syscall_ptr: Relocatable,
) -> Result<(), SyscallHandlerError> {
// Read and validate the syscall request for emitting an event.
let request = match self.read_and_validate_syscall_request("emit_event", vm, syscall_ptr) {
Ok(DeprecatedSyscallRequest::EmitEvent(emit_event_struct)) => emit_event_struct,
_ => return Err(SyscallHandlerError::InvalidSyscallReadRequest),
};

// Extract keys and data.
let keys_len = request.keys_len;
let data_len = request.data_len;
let order = self.tx_execution_context.n_emitted_events;
Expand All @@ -269,6 +286,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(())
}

/// Allocate a segment in memory.
pub(crate) fn allocate_segment(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -283,6 +301,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(segment_start)
}

/// Deploy a contract.
pub(crate) fn syscall_deploy(
&mut self,
vm: &VirtualMachine,
Expand Down Expand Up @@ -343,6 +362,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(deploy_contract_address)
}

/// Call a contract.
pub(crate) fn syscall_call_contract(
&mut self,
syscall_name: &str,
Expand Down Expand Up @@ -461,10 +481,12 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(retdata)
}

/// Returns the block information associated with the current context.
pub(crate) fn get_block_info(&self) -> &BlockInfo {
&self.block_context.block_info
}

/// Get the caller's address from a virtual machine, using the syscall pointer.
pub(crate) fn syscall_get_caller_address(
&mut self,
vm: &VirtualMachine,
Expand All @@ -483,6 +505,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(self.caller_address.clone())
}

/// Handles the delegation of an L1 handler call.
pub(crate) fn delegate_l1_handler(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -491,6 +514,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
self.call_contract_and_write_response("delegate_l1_handler", vm, syscall_ptr)
}

/// Get the contract address from a virtual machine, using the syscall pointer.
pub(crate) fn syscall_get_contract_address(
&mut self,
vm: &VirtualMachine,
Expand All @@ -509,6 +533,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(self.contract_address.clone())
}

/// Sends a message from L2 to L1, including the destination address and payload.
pub(crate) fn send_message_to_l1(
&mut self,
vm: &VirtualMachine,
Expand Down Expand Up @@ -538,6 +563,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(())
}

/// Get the pointer to transaction information.
pub(crate) fn syscall_get_tx_info_ptr(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -564,6 +590,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(tx_info_ptr_temp)
}

/// Performs a storage read operation.
pub(crate) fn storage_read(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -586,6 +613,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
response.write_syscall_response(vm, syscall_ptr)
}

/// Performs a storage write operation.
pub(crate) fn storage_write(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -607,6 +635,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(())
}

/// Deploys a contract to the virtual machine.
pub(crate) fn deploy(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -627,7 +656,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(())
}

// Executes the contract call and fills the DeprecatedCallContractResponse struct.
/// Executes the contract call and fills the DeprecatedCallContractResponse struct.
pub(crate) fn call_contract_and_write_response(
&mut self,
syscall_name: &str,
Expand All @@ -649,7 +678,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {

self.write_syscall_response(&response, vm, syscall_ptr)
}

/// Writes the response of a syscall to the virtual machine.
pub(crate) fn write_syscall_response<R: DeprecatedWriteSyscallResponse>(
&self,
response: &R,
Expand All @@ -659,6 +688,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
response.write_syscall_response(vm, syscall_ptr)
}

/// Get the block number
pub(crate) fn get_block_number(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -669,6 +699,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
.write_syscall_response(vm, syscall_ptr)
}

/// Get the transactino info.
fguthmann marked this conversation as resolved.
Show resolved Hide resolved
pub(crate) fn get_tx_info(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -686,6 +717,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
response.write_syscall_response(vm, syscall_ptr)
}

/// Get the transaction signature.
pub(crate) fn get_tx_signature(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -709,6 +741,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
response.write_syscall_response(vm, syscall_ptr)
}

/// Get the time stamp of the block.
pub(crate) fn get_block_timestamp(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -731,6 +764,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
response.write_syscall_response(vm, syscall_ptr)
}

/// Get the caller address.
pub(crate) fn get_caller_address(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -741,6 +775,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
response.write_syscall_response(vm, syscall_ptr)
}

/// Get the contract address
pub(crate) fn get_contract_address(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -751,6 +786,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
response.write_syscall_response(vm, syscall_ptr)
}

/// Get the sequencer address
pub(crate) fn get_sequencer_address(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -773,6 +809,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
response.write_syscall_response(vm, syscall_ptr)
}

/// Executes a library call
pub(crate) fn library_call(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -781,6 +818,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
self.call_contract_and_write_response("library_call", vm, syscall_ptr)
}

/// Executes a library call specific to an L1 handler
pub(crate) fn library_call_l1_handler(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -789,6 +827,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
self.call_contract_and_write_response("library_call_l1_handler", vm, syscall_ptr)
}

/// Executes a contract call
pub(crate) fn call_contract(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -797,6 +836,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
self.call_contract_and_write_response("call_contract", vm, syscall_ptr)
}

/// Executes a delegate call
pub(crate) fn delegate_call(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -805,6 +845,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
self.call_contract_and_write_response("delegate_call", vm, syscall_ptr)
}

/// Reads a value from the storage state using the specified address.
pub(crate) fn syscall_storage_read(
&mut self,
address: Address,
Expand All @@ -814,6 +855,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
.read(&felt_to_hash(&address.0))?)
}

/// Writes a value to the storage state using the specified address.
pub(crate) fn syscall_storage_write(
&mut self,
address: Address,
Expand All @@ -825,6 +867,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(())
}

/// Reads and validates a syscall request, and updates the expected syscall pointer offset.
pub(crate) fn read_and_validate_syscall_request(
&mut self,
syscall_name: &str,
Expand All @@ -838,6 +881,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
Ok(syscall_request)
}

/// Reads and validates syscall requests. Matches syscall names to their corresponding requests.
pub(crate) fn read_syscall_request(
&self,
syscall_name: &str,
Expand Down Expand Up @@ -876,6 +920,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
}
}

/// Replaces class at the specified address with a new one based on the request.
pub(crate) fn replace_class(
&mut self,
vm: &mut VirtualMachine,
Expand All @@ -897,7 +942,8 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {

Ok(())
}

/// Performs validation after the Virtual Machine run. Validates that the stopping pointer is as expected,
/// and validates that the read only segments have not been altered.
pub(crate) fn post_run(
&self,
runner: &mut VirtualMachine,
Expand All @@ -914,6 +960,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
}
}

/// Test module for the syscalls.
#[cfg(test)]
mod tests {
use crate::{
Expand Down Expand Up @@ -941,6 +988,7 @@ mod tests {
type DeprecatedBLSyscallHandler<'a> =
super::DeprecatedBLSyscallHandler<'a, InMemoryStateReader>;

/// Tests that the hint application doesn't allow inconsistency in memory.
#[test]
fn run_alloc_hint_ap_is_not_empty() {
let hint_code = "memory[ap] = segments.add()";
Expand All @@ -958,6 +1006,7 @@ mod tests {
);
}

/// Tests error handling when trying to deploy from address zero.
#[test]
fn deploy_from_zero_error() {
let mut state = CachedState::<InMemoryStateReader>::default();
Expand All @@ -984,6 +1033,7 @@ mod tests {
)
}

/// Tests if a segment can be allocated successfully.
#[test]
fn can_allocate_segment() {
let mut state = CachedState::<InMemoryStateReader>::default();
Expand All @@ -1000,6 +1050,7 @@ mod tests {
assert_eq!(expected_value, 7.into());
}

/// Tests if the block number can be retrieved successfully.
#[test]
fn test_get_block_number() {
let mut state = CachedState::<InMemoryStateReader>::default();
Expand All @@ -1020,6 +1071,7 @@ mod tests {
);
}

/// Tests if the contract address can be retrieved successfully.
#[test]
fn test_get_contract_address_ok() {
let mut state = CachedState::<InMemoryStateReader>::default();
Expand All @@ -1037,6 +1089,7 @@ mod tests {
)
}

/// Tests if the empty storage read returns zero.
#[test]
fn test_storage_read_empty() {
let mut state = CachedState::<InMemoryStateReader>::default();
Expand Down