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

Bug: Some invalid signatures cause .verify to throw instead of returning false #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 28 additions & 1 deletion test/signer.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assert } from "chai";
import { arrayify, formatBytes32String, keccak256 } from "ethers/lib/utils";
import { aggregate, BlsSignerFactory } from "../src/signer";
import { solG1, solG2 } from "../src/mcl";
import { aggregate, BlsSignerFactory, BlsVerifier } from "../src/signer";

describe("BLS Signer", async () => {
// Domain is a data that signer and verifier must agree on
Expand Down Expand Up @@ -44,4 +45,30 @@ describe("BLS Signer", async () => {
signers[0].verifyMultiple(aggSignature, pubkeys, messages)
);
});

it("rejects invalid signature", async function() {
const verifier = new BlsVerifier(arrayify(keccak256("0xfeedbee5")));

// Starting from a correctly signed example
const signature: solG1 = ["0x159647ae964ea7a386767ab1e41aa47652265bf031ab9d05b70bf5ad1a770a3c","0x0d46b38b1f72d7df1f88786272f0b3fea1c79e1c8515a165fe19939e031ced9e"];
const pubkey: solG2 = ["0x2836b6b13bd5ace9680634043f09fec8732b6e43939f7e4d2f76c03db0afce15","0x18496f68063e0be219b95a1d086279772a3bca0005aa1cb39eabde35d2d8d5f4","0x0ae7d6473913e4865cdeba81f88d3511acb461175f4e9ac7e8fe5e48bbc55c0f","0x075a3c3c825d516ed0b6014246e869d50f24be3affcac6f1814ee69429cd045d"];
const message = "0x0000000000000000000000000000000000000000000000000000000000066eeb000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000008cd755f93e56c90e3d5803c036771cfcc12b7c537717ec640ce190aa48cd0019aad18112e6c16befa603de675c3e86a11228aab6";

assert.isTrue(verifier.verify(
signature,
pubkey,
message,
));

// Change first hex digit of signature from 1 to 0 (to make it invalid)
const badSignature = signature.slice() as solG1;
badSignature[0] = `0x0${signature[0].slice(3)}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@voltrevo mcl-wasm will throw the err _wrapInput with malformed hex values, or values that are out of the supported range. See:

I ran into this same issue and used an openssl generated hex to resolve, see https://github.com/jzaki/bls-wallet/pull/92/files#r787376021 . I am unfortunately not cryptographically experienced enough to provide a more robust explanation.

Two ways I can think of that we can address:

  • Add more validation logic to values passed into this lib to throw more meaningful errors.
  • Add validation logic in consuming code (such as in bls-wallet-clients) to handle it a layer up.

Thoughts?


// This should just return false, but it throws :(
assert.isFalse(verifier.verify(
badSignature,
pubkey,
message,
));
});
});