Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions crates/blockifier/src/execution/call_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::ops::Add;

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use serde::Serialize;
use starknet_api::core::{ClassHash, ContractAddress, EthAddress, PatriciaKey};
use starknet_api::core::{ClassHash, ContractAddress, PatriciaKey};
use starknet_api::state::StorageKey;
use starknet_api::transaction::{EventContent, L2ToL1Payload};
use starknet_api::{felt, patricia_key};
Expand Down Expand Up @@ -55,7 +55,7 @@ impl MessageL1CostInfo {

#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct MessageToL1 {
pub to_address: EthAddress,
pub to_address: Felt,
pub payload: L2ToL1Payload,
}

Expand Down Expand Up @@ -144,7 +144,7 @@ impl TestExecutionSummary {
.map(|i| OrderedL2ToL1Message {
order: i,
message: MessageToL1 {
to_address: EthAddress::default(),
to_address: Felt::default(),
payload: L2ToL1Payload(vec![Felt::default()]),
},
})
Expand Down
31 changes: 6 additions & 25 deletions crates/blockifier/src/execution/deprecated_syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,26 @@ use cairo_vm::vm::vm_core::VirtualMachine;
use serde::Deserialize;
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::core::{
calculate_contract_address,
ClassHash,
ContractAddress,
EntryPointSelector,
EthAddress,
calculate_contract_address, ClassHash, ContractAddress, EntryPointSelector,
};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::state::StorageKey;
use starknet_api::transaction::{
Calldata,
ContractAddressSalt,
EventContent,
EventData,
EventKey,
L2ToL1Payload,
Calldata, ContractAddressSalt, EventContent, EventData, EventKey, L2ToL1Payload,
};
use starknet_types_core::felt::Felt;
use strum_macros::EnumIter;

use self::hint_processor::{
execute_inner_call,
execute_library_call,
felt_to_bool,
read_call_params,
read_calldata,
read_felt_array,
DeprecatedSyscallExecutionError,
DeprecatedSyscallHintProcessor,
execute_inner_call, execute_library_call, felt_to_bool, read_call_params, read_calldata,
read_felt_array, DeprecatedSyscallExecutionError, DeprecatedSyscallHintProcessor,
};
use super::syscalls::exceeds_event_size_limit;
use crate::execution::call_info::{MessageToL1, OrderedEvent, OrderedL2ToL1Message};
use crate::execution::common_hints::ExecutionMode;
use crate::execution::entry_point::{CallEntryPoint, CallType, ConstructorContext};
use crate::execution::execution_utils::{
execute_deployment,
felt_from_ptr,
write_felt,
write_maybe_relocatable,
ReadOnlySegment,
execute_deployment, felt_from_ptr, write_felt, write_maybe_relocatable, ReadOnlySegment,
};

#[cfg(test)]
Expand Down Expand Up @@ -676,7 +657,7 @@ impl SyscallRequest for SendMessageToL1Request {
vm: &VirtualMachine,
ptr: &mut Relocatable,
) -> DeprecatedSyscallResult<SendMessageToL1Request> {
let to_address = EthAddress::try_from(felt_from_ptr(vm, ptr)?)?;
let to_address = felt_from_ptr(vm, ptr)?;
let payload = L2ToL1Payload(read_felt_array::<DeprecatedSyscallExecutionError>(vm, ptr)?);

Ok(SendMessageToL1Request { message: MessageToL1 { to_address, payload } })
Expand Down
41 changes: 11 additions & 30 deletions crates/blockifier/src/execution/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,27 @@ use cairo_vm::vm::vm_core::VirtualMachine;
use num_traits::ToPrimitive;
use starknet_api::block::{BlockHash, BlockNumber};
use starknet_api::core::{
calculate_contract_address,
ClassHash,
ContractAddress,
EntryPointSelector,
EthAddress,
calculate_contract_address, ClassHash, ContractAddress, EntryPointSelector,
};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::state::StorageKey;
use starknet_api::transaction::{
Calldata,
ContractAddressSalt,
EventContent,
EventData,
EventKey,
L2ToL1Payload,
Calldata, ContractAddressSalt, EventContent, EventData, EventKey, L2ToL1Payload,
};
use starknet_types_core::felt::Felt;

use self::hint_processor::{
create_retdata_segment,
execute_inner_call,
execute_library_call,
felt_to_bool,
read_call_params,
read_calldata,
read_felt_array,
write_segment,
EmitEventError,
SyscallExecutionError,
SyscallHintProcessor,
BLOCK_NUMBER_OUT_OF_RANGE_ERROR,
create_retdata_segment, execute_inner_call, execute_library_call, felt_to_bool,
read_call_params, read_calldata, read_felt_array, write_segment, EmitEventError,
SyscallExecutionError, SyscallHintProcessor, BLOCK_NUMBER_OUT_OF_RANGE_ERROR,
};
use crate::abi::constants;
use crate::execution::call_info::{MessageToL1, OrderedEvent, OrderedL2ToL1Message};
use crate::execution::contract_class::ContractClass;
use crate::execution::deprecated_syscalls::DeprecatedSyscallSelector;
use crate::execution::entry_point::{CallEntryPoint, CallType, ConstructorContext};
use crate::execution::execution_utils::{
execute_deployment,
felt_from_ptr,
write_felt,
write_maybe_relocatable,
ReadOnlySegment,
execute_deployment, felt_from_ptr, write_felt, write_maybe_relocatable, ReadOnlySegment,
};
use crate::execution::syscalls::hint_processor::{INVALID_INPUT_LENGTH_ERROR, OUT_OF_GAS_ERROR};
use crate::transaction::transaction_utils::update_remaining_gas;
Expand All @@ -57,6 +35,9 @@ pub mod secp;
#[cfg(test)]
#[path = "syscalls_test.rs"]
pub mod syscalls_test;
#[cfg(test)]
#[path = "syscalls_test_katana.rs"]
pub mod syscalls_test_katana;

pub type SyscallResult<T> = Result<T, SyscallExecutionError>;
pub type WriteResponseResult = SyscallResult<()>;
Expand Down Expand Up @@ -564,7 +545,7 @@ pub struct SendMessageToL1Request {
impl SyscallRequest for SendMessageToL1Request {
// The Cairo struct contains: `to_address`, `payload_size`, `payload`.
fn read(vm: &VirtualMachine, ptr: &mut Relocatable) -> SyscallResult<SendMessageToL1Request> {
let to_address = EthAddress::try_from(felt_from_ptr(vm, ptr)?)?;
let to_address = felt_from_ptr(vm, ptr)?;
let payload = L2ToL1Payload(read_felt_array::<SyscallExecutionError>(vm, ptr)?);

Ok(SendMessageToL1Request { message: MessageToL1 { to_address, payload } })
Expand Down Expand Up @@ -709,7 +690,7 @@ pub fn keccak(
if remainder != 0 {
return Err(SyscallExecutionError::SyscallError {
error_data: vec![
Felt::from_hex(INVALID_INPUT_LENGTH_ERROR).map_err(SyscallExecutionError::from)?,
Felt::from_hex(INVALID_INPUT_LENGTH_ERROR).map_err(SyscallExecutionError::from)?
],
});
}
Expand Down
70 changes: 16 additions & 54 deletions crates/blockifier/src/execution/syscalls/syscalls_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,13 @@ use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use num_traits::Pow;
use pretty_assertions::assert_eq;
use rstest::rstest;
use starknet_api::core::{
calculate_contract_address,
ChainId,
ContractAddress,
EthAddress,
PatriciaKey,
};
use starknet_api::core::{calculate_contract_address, ChainId, ContractAddress, PatriciaKey};
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::state::StorageKey;
use starknet_api::transaction::{
AccountDeploymentData,
Calldata,
ContractAddressSalt,
EventContent,
EventData,
EventKey,
Fee,
L2ToL1Payload,
PaymasterData,
Resource,
ResourceBounds,
ResourceBoundsMapping,
Tip,
TransactionHash,
TransactionVersion,
AccountDeploymentData, Calldata, ContractAddressSalt, EventContent, EventData, EventKey, Fee,
L2ToL1Payload, PaymasterData, Resource, ResourceBounds, ResourceBoundsMapping, Tip,
TransactionHash, TransactionVersion,
};
use starknet_api::{calldata, felt};
use starknet_types_core::felt::Felt;
Expand All @@ -41,48 +23,27 @@ use crate::abi::abi_utils::selector_from_name;
use crate::abi::constants;
use crate::context::ChainInfo;
use crate::execution::call_info::{
CallExecution,
CallInfo,
MessageToL1,
OrderedEvent,
OrderedL2ToL1Message,
Retdata,
CallExecution, CallInfo, MessageToL1, OrderedEvent, OrderedL2ToL1Message, Retdata,
};
use crate::execution::common_hints::ExecutionMode;
use crate::execution::entry_point::{CallEntryPoint, CallType};
use crate::execution::errors::EntryPointExecutionError;
use crate::execution::syscalls::hint_processor::{
EmitEventError,
BLOCK_NUMBER_OUT_OF_RANGE_ERROR,
L1_GAS,
L2_GAS,
OUT_OF_GAS_ERROR,
EmitEventError, BLOCK_NUMBER_OUT_OF_RANGE_ERROR, L1_GAS, L2_GAS, OUT_OF_GAS_ERROR,
};
use crate::execution::syscalls::SyscallSelector;
use crate::state::state_api::{State, StateReader};
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{
calldata_for_deploy_test,
create_calldata,
get_syscall_resources,
trivial_external_entry_point_new,
trivial_external_entry_point_with_address,
CairoVersion,
BALANCE,
CHAIN_ID_NAME,
CURRENT_BLOCK_NUMBER,
CURRENT_BLOCK_NUMBER_FOR_VALIDATE,
CURRENT_BLOCK_TIMESTAMP,
CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE,
TEST_SEQUENCER_ADDRESS,
calldata_for_deploy_test, create_calldata, get_syscall_resources,
trivial_external_entry_point_new, trivial_external_entry_point_with_address, CairoVersion,
BALANCE, CHAIN_ID_NAME, CURRENT_BLOCK_NUMBER, CURRENT_BLOCK_NUMBER_FOR_VALIDATE,
CURRENT_BLOCK_TIMESTAMP, CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE, TEST_SEQUENCER_ADDRESS,
};
use crate::transaction::constants::QUERY_VERSION_BASE_BIT;
use crate::transaction::objects::{
CommonAccountFields,
CurrentTransactionInfo,
DeprecatedTransactionInfo,
TransactionInfo,
CommonAccountFields, CurrentTransactionInfo, DeprecatedTransactionInfo, TransactionInfo,
};
use crate::versioned_constants::VersionedConstants;
use crate::{check_entry_point_execution_error_for_custom_hint, nonce, retdata, storage_key};
Expand Down Expand Up @@ -601,9 +562,11 @@ fn test_library_call_assert_fails() {
..trivial_external_entry_point_new(test_contract)
};

assert!(
entry_point_call.execute_directly(&mut state).unwrap_err().to_string().contains("x != y")
);
assert!(entry_point_call
.execute_directly(&mut state)
.unwrap_err()
.to_string()
.contains("x != y"));
}

#[test]
Expand Down Expand Up @@ -844,7 +807,6 @@ fn test_send_message_to_l1() {
..trivial_external_entry_point_new(test_contract)
};

let to_address = EthAddress::try_from(to_address).unwrap();
let message = MessageToL1 { to_address, payload: L2ToL1Payload(payload) };

assert_eq!(
Expand Down
51 changes: 51 additions & 0 deletions crates/blockifier/src/execution/syscalls/syscalls_test_katana.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use cairo_vm::Felt252;
use pretty_assertions::assert_eq;
use starknet_api::felt;
use starknet_api::transaction::{Calldata, L2ToL1Payload};

use crate::abi::abi_utils::selector_from_name;
use crate::context::ChainInfo;
use crate::execution::call_info::{CallExecution, MessageToL1, OrderedL2ToL1Message};
use crate::execution::entry_point::CallEntryPoint;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{trivial_external_entry_point_new, CairoVersion, BALANCE};

#[test]
fn test_send_message_to_l1_with_longer_than_eth_address() {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1);
let chain_info = &ChainInfo::create_for_testing();
let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]);

let to_address = Felt252::MAX;
let payload = vec![felt!(2019_u16), felt!(2020_u16), felt!(2021_u16)];
let calldata = Calldata(
[
vec![
to_address,
// TODO(Ori, 1/2/2024): Write an indicative expect message explaining why the
// convertion works.
felt!(u64::try_from(payload.len()).expect("Failed to convert usize to u64.")),
],
payload.clone(),
]
.concat()
.into(),
);
let entry_point_call = CallEntryPoint {
entry_point_selector: selector_from_name("test_send_message_to_l1"),
calldata,
..trivial_external_entry_point_new(test_contract)
};

let message = MessageToL1 { to_address, payload: L2ToL1Payload(payload) };

assert_eq!(
entry_point_call.execute_directly(&mut state).unwrap().execution,
CallExecution {
l2_to_l1_messages: vec![OrderedL2ToL1Message { order: 0, message }],
gas_consumed: 22990,
..Default::default()
}
);
}
4 changes: 2 additions & 2 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use num_traits::Pow;
use once_cell::sync::Lazy;
use pretty_assertions::assert_eq;
use rstest::{fixture, rstest};
use starknet_api::core::{ChainId, ClassHash, ContractAddress, EthAddress, Nonce, PatriciaKey};
use starknet_api::core::{ChainId, ClassHash, ContractAddress, Nonce, PatriciaKey};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::state::StorageKey;
use starknet_api::transaction::{
Expand Down Expand Up @@ -684,7 +684,7 @@ fn test_invoke_tx_advanced_operations(
let expected_msg = OrderedL2ToL1Message {
order: 0,
message: MessageToL1 {
to_address: EthAddress::try_from(to_address).unwrap(),
to_address,
payload: L2ToL1Payload(vec![felt!(12_u32), felt!(34_u32)]),
},
};
Expand Down
28 changes: 5 additions & 23 deletions crates/committer_cli/src/tests/utils/objects.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
use indexmap::indexmap;
use starknet_api::block_hash::block_hash_calculator::{
TransactionHashingData,
TransactionOutputForHash,
};
use starknet_api::core::{
ClassHash,
CompiledClassHash,
ContractAddress,
EthAddress,
Nonce,
PatriciaKey,
TransactionHashingData, TransactionOutputForHash,
};
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce, PatriciaKey};
use starknet_api::state::{StorageKey, ThinStateDiff};
use starknet_api::transaction::{
Event,
EventContent,
EventData,
EventKey,
Fee,
GasVector,
L2ToL1Payload,
MessageToL1,
RevertedTransactionExecutionStatus,
TransactionExecutionStatus,
TransactionHash,
Event, EventContent, EventData, EventKey, Fee, GasVector, L2ToL1Payload, MessageToL1,
RevertedTransactionExecutionStatus, TransactionExecutionStatus, TransactionHash,
TransactionSignature,
};
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -52,8 +35,7 @@ pub(crate) fn get_transaction_output_for_hash(
gas_consumed: GasVector { l1_gas: 0, l1_data_gas: 64 },
messages_sent: vec![MessageToL1 {
from_address: ContractAddress(PatriciaKey::from(2_u128)),
to_address: EthAddress::try_from(Felt::from_bytes_be_slice(&[1_u8]))
.expect("to_address"),
to_address: Felt::from_bytes_be_slice(&[1_u8]),
payload: L2ToL1Payload(vec![Felt::from_bytes_be_slice(&[0_u8])]),
}],
}
Expand Down
Loading
Loading