From 7a7b9a5b13f670ea2a1c341943e56acfabdc7a5d Mon Sep 17 00:00:00 2001 From: Nilesh Gupta Date: Thu, 21 Nov 2024 00:23:45 +0530 Subject: [PATCH] refactor: added limit to identity bytes --- src/lib.cairo | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lib.cairo b/src/lib.cairo index 1f73c2f..b1e9793 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -261,6 +261,15 @@ pub mod PushComm { recipient: ContractAddress, identity: ByteArray ) -> bool { + // Define the maximum allowed bytes based on felts limit + let MAX_IDENTITY_BYTES_LIMIT: usize = 9145; // equivalent to 295 felts + + // Check that the identity length is within the limit + let identity_length = identity.len(); + if identity_length > MAX_IDENTITY_BYTES_LIMIT { + return false; + } + let success = self._check_notif_req(channel); if success { self @@ -276,7 +285,6 @@ pub mod PushComm { } } - #[abi(embed_v0)] impl PushComm of super::IPushComm { // User @@ -312,6 +320,16 @@ pub mod PushComm { ); let modified_notif_settings = format!("@{}+@{}", notif_id, notif_settings); + + // Define the maximum allowed bytes based on felts limit + let MAX_IDENTITY_BYTES_LIMIT: usize = 9145; // equivalent to 295 felts + + // Check that the notif_settings length is within the limit + let modified_notif_settings_length = modified_notif_settings.len(); + assert!( + modified_notif_settings_length <= MAX_IDENTITY_BYTES_LIMIT, "notif_settings exceeds limit" + ); + self .user_to_channel_notifs .entry(caller_address)