Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit b9679d4

Browse files
fix: strict check for given messages count and originally revealed (#175)
1 parent 83803fc commit b9679d4

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

__tests__/bbsSignature/verifyProof.bbsSignature.spec.ts

+25
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,31 @@ describe("bbsSignature", () => {
301301
expect(result.verified).toBeTruthy();
302302
});
303303

304+
it("should not verify with more given messages than revealed", async () => {
305+
const messages = [
306+
stringToBytes("8NhsJO/MKxO74A=="),
307+
stringToBytes("0noLBcl29ASJ2w=="),
308+
stringToBytes("eMPpY348vqGDNA=="),
309+
];
310+
const blsPublicKey = base64Decode(
311+
"qJgttTOthlZHltz+c0PE07hx3worb/cy7QY5iwRegQ9BfwvGahdqCO9Q9xuOnF5nD/Tq6t8zm9z26EAFCiaEJnL5b50D1cHDgNxBUPEEae+4bUb3JRsHaxBdZWDOo3pb"
312+
);
313+
const proof = base64Decode(
314+
"AAMBjl1W6j/1y/M3V4OIluw3BSTvgKCYRh+2SSeNNfDSZzKqNJAlQMGfHvBzpFQN55MZscHwEmMM6yWK2dqKGVhecvkwUvOIogpMFTbf3ikMor375ddSB3MAuHvgmlZKdLz7iwbxoCrf4+zfDvYeeLF6QR1uMdUa7v50ix2ZeSllsmOk5NxrEVMZXJ/+SDfASgTZAAAAdJeaUx4qwv5W72EKCDSBIYfxwlj28IGx0TnDm0E1y10n3hE0SIKYzgqqE81SPV9jfwAAAAIdssV4x73UeqxXmgQJSMO4XKDiiyxprlrpyz+1tINi7QbUABSCe4T1pdYOS0miYLDwzy2/zS2uuJ12yfqj6S1hl0U/uNbr03t8xypruPQhYreQGanMpFCnZquOJ9CYTGSPwMl1Hlva5hW0Jcrwugn1AAAABDLHtpcxsutFpn2EiPTYZMEeNnVr2x5AggpCAuLfd0+JBKEEwHKANSeajnWKBZ0YkZ/MpXkpU3ThRYWijpb6EsE4QJzkzSzKt5ZQCXsRkFLg/gWZIAUzKEjk3G2ELrFHlR9AedW1eANiHF/4ZuQPAtlRYg+mxeiEp87/xoLdq+OA"
315+
);
316+
317+
const revealedMessages = messages.slice(0, 2);
318+
319+
const request: BbsVerifyProofRequest = {
320+
proof,
321+
publicKey: blsPublicKey,
322+
messages: revealedMessages,
323+
nonce: stringToBytes("I03DvFXcpVdOPuOiyXgcBf4voAA="),
324+
};
325+
const result = await blsVerifyProof(request);
326+
expect(result.verified).toBeFalsy();
327+
});
328+
304329
it("should not verify with malformed proof", async () => {
305330
const messages = [
306331
stringToBytes("Message1"),

native/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,11 @@ fn extract_verify_proof_context(cx: &mut FunctionContext, is_bls: bool) -> Resul
860860
// let revealed_indices = obj_field_to_vec!(cx, js_obj, "revealed");
861861
let message_bytes = obj_field_to_vec!(cx, js_obj, "messages");
862862

863+
if message_bytes.len() != revealed.len() {
864+
panic!("Given messages count ({}) is different from revealed messages count ({}) for this proof",
865+
message_bytes.len(), revealed.len());
866+
}
867+
863868
let mut messages = Vec::new();
864869
for i in 0..message_bytes.len() {
865870
let message = obj_field_to_field_elem!(cx, message_bytes[i]);

0 commit comments

Comments
 (0)