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

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta committed Mar 12, 2024
1 parent b01ecd9 commit 6f4d9af
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/definitions/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
19 changes: 15 additions & 4 deletions src/syscalls/business_logic_syscall_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -656,13 +659,21 @@ impl<'a, S: StateReader, C: ContractClassCache> BusinessLogicSyscallHandler<'a,
let data: Vec<Felt252> = 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));

Expand Down
20 changes: 16 additions & 4 deletions src/syscalls/native_syscall_handler.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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")?;
Expand Down
13 changes: 3 additions & 10 deletions src/syscalls/syscall_handler_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),

}

0 comments on commit 6f4d9af

Please sign in to comment.