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

[sdk] Add a length restriction on poseidon hash input #33363

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions sdk/program/src/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use thiserror::Error;

/// BN254 base field bytes.
pub const BN254_FIELD_BYTES: usize = 32;

/// Length of Poseidon hash result.
pub const HASH_BYTES: usize = 32;

Expand Down Expand Up @@ -233,6 +236,10 @@ pub fn hashv(
}
}

if vals.iter().any(|val| val.len() > BN254_FIELD_BYTES) {
return Err(PoseidonSyscallError::InputLargerThanModulus);
}

let mut hasher =
Poseidon::<Fr>::new_circom(vals.len()).map_err(PoseidonSyscallError::from)?;
let res = match endianness {
Expand Down