Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit Issue8: added limit to identity bytes #20

Merged
merged 1 commit into from
Nov 20, 2024
Merged
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
20 changes: 19 additions & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -276,7 +285,6 @@ pub mod PushComm {
}
}


#[abi(embed_v0)]
impl PushComm of super::IPushComm<ContractState> {
// User
Expand Down Expand Up @@ -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)
Expand Down
Loading