diff --git a/native/bls_nif/src/lib.rs b/native/bls_nif/src/lib.rs index b4c53d444..f2966caf8 100644 --- a/native/bls_nif/src/lib.rs +++ b/native/bls_nif/src/lib.rs @@ -16,6 +16,9 @@ fn sign<'env>( private_key: Binary, message: Binary, ) -> Result, String> { + if message.len() != 32 { + return Err(format!("Message must be 32 bytes long")); + } let sk = match SecretKey::deserialize(private_key.as_slice()) { Ok(sk) => sk, Err(e) => return Err(format!("{:?}", e)), @@ -51,6 +54,9 @@ fn aggregate<'env>(env: Env<'env>, signatures: Vec) -> Result(public_key: Binary, message: Binary, signature: Binary) -> Result { + if message.len() != 32 { + return Err(format!("Message must be 32 bytes long")); + } let sig = Signature::deserialize(signature.as_slice()).map_err(|err| format!("{:?}", err))?; let pubkey = PublicKey::deserialize(public_key.as_slice()).map_err(|err| format!("{:?}", err))?; @@ -86,6 +92,9 @@ fn fast_aggregate_verify<'env>( message: Binary, signature: Binary, ) -> Result { + if message.len() != 32 { + return Err(format!("Message must be 32 bytes long")); + } let aggregate_sig = AggregateSignature::deserialize(signature.as_slice()) .map_err(|err| format!("{:?}", err))?; let pubkeys_result = public_keys @@ -104,6 +113,9 @@ fn eth_fast_aggregate_verify<'env>( message: Binary, signature: Binary, ) -> Result { + if message.len() != 32 { + return Err(format!("Message must be 32 bytes long")); + } let aggregate_sig = AggregateSignature::deserialize(signature.as_slice()) .map_err(|err| format!("{:?}", err))?; let pubkeys_result = public_keys