Skip to content

Commit

Permalink
fix: strict check for given messages count and originally revealed (#175
Browse files Browse the repository at this point in the history
)
  • Loading branch information
anton-iskryzhytskyi authored Nov 28, 2021
1 parent 83803fc commit b9679d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions __tests__/bbsSignature/verifyProof.bbsSignature.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,31 @@ describe("bbsSignature", () => {
expect(result.verified).toBeTruthy();
});

it("should not verify with more given messages than revealed", async () => {
const messages = [
stringToBytes("8NhsJO/MKxO74A=="),
stringToBytes("0noLBcl29ASJ2w=="),
stringToBytes("eMPpY348vqGDNA=="),
];
const blsPublicKey = base64Decode(
"qJgttTOthlZHltz+c0PE07hx3worb/cy7QY5iwRegQ9BfwvGahdqCO9Q9xuOnF5nD/Tq6t8zm9z26EAFCiaEJnL5b50D1cHDgNxBUPEEae+4bUb3JRsHaxBdZWDOo3pb"
);
const proof = base64Decode(
"AAMBjl1W6j/1y/M3V4OIluw3BSTvgKCYRh+2SSeNNfDSZzKqNJAlQMGfHvBzpFQN55MZscHwEmMM6yWK2dqKGVhecvkwUvOIogpMFTbf3ikMor375ddSB3MAuHvgmlZKdLz7iwbxoCrf4+zfDvYeeLF6QR1uMdUa7v50ix2ZeSllsmOk5NxrEVMZXJ/+SDfASgTZAAAAdJeaUx4qwv5W72EKCDSBIYfxwlj28IGx0TnDm0E1y10n3hE0SIKYzgqqE81SPV9jfwAAAAIdssV4x73UeqxXmgQJSMO4XKDiiyxprlrpyz+1tINi7QbUABSCe4T1pdYOS0miYLDwzy2/zS2uuJ12yfqj6S1hl0U/uNbr03t8xypruPQhYreQGanMpFCnZquOJ9CYTGSPwMl1Hlva5hW0Jcrwugn1AAAABDLHtpcxsutFpn2EiPTYZMEeNnVr2x5AggpCAuLfd0+JBKEEwHKANSeajnWKBZ0YkZ/MpXkpU3ThRYWijpb6EsE4QJzkzSzKt5ZQCXsRkFLg/gWZIAUzKEjk3G2ELrFHlR9AedW1eANiHF/4ZuQPAtlRYg+mxeiEp87/xoLdq+OA"
);

const revealedMessages = messages.slice(0, 2);

const request: BbsVerifyProofRequest = {
proof,
publicKey: blsPublicKey,
messages: revealedMessages,
nonce: stringToBytes("I03DvFXcpVdOPuOiyXgcBf4voAA="),
};
const result = await blsVerifyProof(request);
expect(result.verified).toBeFalsy();
});

it("should not verify with malformed proof", async () => {
const messages = [
stringToBytes("Message1"),
Expand Down
5 changes: 5 additions & 0 deletions native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,11 @@ fn extract_verify_proof_context(cx: &mut FunctionContext, is_bls: bool) -> Resul
// let revealed_indices = obj_field_to_vec!(cx, js_obj, "revealed");
let message_bytes = obj_field_to_vec!(cx, js_obj, "messages");

if message_bytes.len() != revealed.len() {
panic!("Given messages count ({}) is different from revealed messages count ({}) for this proof",
message_bytes.len(), revealed.len());
}

let mut messages = Vec::new();
for i in 0..message_bytes.len() {
let message = obj_field_to_field_elem!(cx, message_bytes[i]);
Expand Down

0 comments on commit b9679d4

Please sign in to comment.