diff --git a/src/definitions/constants.rs b/src/definitions/constants.rs index c42258737..4effad495 100644 --- a/src/definitions/constants.rs +++ b/src/definitions/constants.rs @@ -113,6 +113,6 @@ lazy_static! { } // Event Limits -pub(crate) const EVENT_MAX_DATA_LENGTH : usize = 300; -pub(crate) const EVENT_MAX_KEYS_LENGTH: usize = 50; +pub(crate) const EVENT_MAX_DATA_LENGTH: usize = 300; +pub(crate) const EVENT_MAX_KEYS_LENGTH: usize = 50; pub(crate) const MAX_N_EMITTED_EVENTS: u64 = 1000; diff --git a/src/syscalls/business_logic_syscall_handler.rs b/src/syscalls/business_logic_syscall_handler.rs index 7aadaf327..1c5a46245 100644 --- a/src/syscalls/business_logic_syscall_handler.rs +++ b/src/syscalls/business_logic_syscall_handler.rs @@ -15,7 +15,10 @@ use crate::{ core::errors::state_errors::StateError, definitions::{ block_context::BlockContext, - constants::{BLOCK_HASH_CONTRACT_ADDRESS, CONSTRUCTOR_ENTRY_POINT_SELECTOR, EVENT_MAX_DATA_LENGTH, EVENT_MAX_KEYS_LENGTH, MAX_N_EMITTED_EVENTS}, + constants::{ + BLOCK_HASH_CONTRACT_ADDRESS, CONSTRUCTOR_ENTRY_POINT_SELECTOR, EVENT_MAX_DATA_LENGTH, + EVENT_MAX_KEYS_LENGTH, MAX_N_EMITTED_EVENTS, + }, }, execution::{ execution_entry_point::{ExecutionEntryPoint, ExecutionResult}, @@ -656,13 +659,21 @@ impl<'a, S: StateReader, C: ContractClassCache> BusinessLogicSyscallHandler<'a, let data: Vec = get_felt_range(vm, request.data_start, request.data_end)?; // Check event limits if order >= MAX_N_EMITTED_EVENTS { - return Err(SyscallHandlerError::MaxNumberOfEmittedEventsExceeded(MAX_N_EMITTED_EVENTS)) + return Err(SyscallHandlerError::MaxNumberOfEmittedEventsExceeded( + MAX_N_EMITTED_EVENTS, + )); } if keys.len() > EVENT_MAX_KEYS_LENGTH { - return Err(SyscallHandlerError::EventMaxKeysLengthExceeded(keys.len(), EVENT_MAX_KEYS_LENGTH)) + return Err(SyscallHandlerError::EventMaxKeysLengthExceeded( + keys.len(), + EVENT_MAX_KEYS_LENGTH, + )); } if data.len() > EVENT_MAX_DATA_LENGTH { - return Err(SyscallHandlerError::EventMaxKeysLengthExceeded(data.len(), EVENT_MAX_DATA_LENGTH)) + return Err(SyscallHandlerError::EventMaxKeysLengthExceeded( + data.len(), + EVENT_MAX_DATA_LENGTH, + )); } self.events.push(OrderedEvent::new(order, keys, data)); diff --git a/src/syscalls/native_syscall_handler.rs b/src/syscalls/native_syscall_handler.rs index d2fa4b8a4..badeea73a 100644 --- a/src/syscalls/native_syscall_handler.rs +++ b/src/syscalls/native_syscall_handler.rs @@ -1,6 +1,12 @@ use crate::{ core::errors::state_errors::StateError, - definitions::{block_context::BlockContext, constants::{CONSTRUCTOR_ENTRY_POINT_SELECTOR, EVENT_MAX_DATA_LENGTH, EVENT_MAX_KEYS_LENGTH, MAX_N_EMITTED_EVENTS}}, + definitions::{ + block_context::BlockContext, + constants::{ + CONSTRUCTOR_ENTRY_POINT_SELECTOR, EVENT_MAX_DATA_LENGTH, EVENT_MAX_KEYS_LENGTH, + MAX_N_EMITTED_EVENTS, + }, + }, execution::{ execution_entry_point::{ExecutionEntryPoint, ExecutionResult}, CallInfo, CallResult, CallType, OrderedEvent, OrderedL2ToL1Message, @@ -393,13 +399,19 @@ impl<'a, 'cache, S: StateReader, C: ContractClassCache> StarkNetSyscallHandler tracing::debug!("Called `emit_event(KEYS: {keys:?}, DATA: {data:?})` from Cairo Native"); // Check event limits if order >= MAX_N_EMITTED_EVENTS { - return Err(vec![Felt252::from_bytes_be_slice("Max number of emitted events reached".as_bytes())]) + return Err(vec![Felt252::from_bytes_be_slice( + "Max number of emitted events reached".as_bytes(), + )]); } if keys.len() > EVENT_MAX_KEYS_LENGTH { - return Err(vec![Felt252::from_bytes_be_slice("Event max keys length exceeded".as_bytes())]) + return Err(vec![Felt252::from_bytes_be_slice( + "Event max keys length exceeded".as_bytes(), + )]); } if data.len() > EVENT_MAX_DATA_LENGTH { - return Err(vec![Felt252::from_bytes_be_slice("Event data keys length exceeded".as_bytes())]) + return Err(vec![Felt252::from_bytes_be_slice( + "Event data keys length exceeded".as_bytes(), + )]); } self.handle_syscall_request(gas, "emit_event")?; diff --git a/src/syscalls/syscall_handler_errors.rs b/src/syscalls/syscall_handler_errors.rs index 7d5a6aaac..7c64f25da 100644 --- a/src/syscalls/syscall_handler_errors.rs +++ b/src/syscalls/syscall_handler_errors.rs @@ -73,17 +73,10 @@ pub enum SyscallHandlerError { UnsupportedAddressDomain(String), #[error("{0:?}")] CustomError(String), - #[error( - "Event exceeded the maximum keys length, keys length: {0}, max keys length: {1}." - )] + #[error("Event exceeded the maximum keys length, keys length: {0}, max keys length: {1}.")] EventMaxKeysLengthExceeded(usize, usize), - #[error( - "Event exceeded the maximum data length, data length: {0}, max data length: {1}." - )] + #[error("Event exceeded the maximum data length, data length: {0}, max data length: {1}.")] EventMaxDataLengthExceeded(usize, usize), - #[error( - "Maximum number of events reached: {0}, can't emit another event." - )] + #[error("Maximum number of events reached: {0}, can't emit another event.")] MaxNumberOfEmittedEventsExceeded(u64), - }