-
Notifications
You must be signed in to change notification settings - Fork 2
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
BLS: translate herumi-mcl logic into noble-curves #51
base: main
Are you sure you want to change the base?
Conversation
@@ -47,6 +47,7 @@ | |||
"mocha": "9.2.2", | |||
"ts-node": "9.1.1", | |||
"tslint": "6.1.3", | |||
"typescript": "4.1.2" | |||
"typescript": "5.6.2", | |||
"@noble/curves": "1.6.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only as "dev-dependency" for now (no change of production code).
|
||
const numVectors = 256; | ||
const testdataPath = path.resolve(__dirname, "testdata"); | ||
const filePath = path.resolve(testdataPath, "blsVectors.json"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSON file containing the test vectors will be moved to "mx-chain-crypto-go" at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few of the "inline" test vectors (explicit, in tests code, not in the JSON file) were took from:
src/blsCompatibility.spec.ts
Outdated
it("test using test vectors", async function () { | ||
this.timeout(100000); | ||
|
||
const numVectors = 256; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use all test vectors (test takes some time, ~50 seconds).
@@ -0,0 +1,1026 @@ | |||
import { FpLegendre, isNegativeLE } from "@noble/curves/abstract/modular"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the translation within a test file, to be refactored & moved to production logic when appropriate.
|
||
assert.equal(toHex(actualPublicKey.bytes), publicKey); | ||
assertG2PointsAreEqual(actualPublicKey.point, publicKeyAsPoint); | ||
assertG2PointsAreEqual(publicKeyAsPoint, bytesToG2ProjectivePoint(fromHex(publicKey))); | ||
|
||
assert.equal(toHex(actualMessageMapped.bytes), messageMapped); | ||
assertG1PointsAreEqual(actualMessageMapped.point, messageMappedAsPoint); | ||
|
||
assert.equal(toHex(actualSignature.bytes), signature); | ||
assertG1PointsAreEqual(actualSignature.point, signatureAsPoint); | ||
|
||
assert.isTrue(verified); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve the precision of the tests, we also check the points coordinates.
}); | ||
}); | ||
|
||
function setupG2GeneratorPointsLikeHerumi() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Necessary, since we use a custom generator for BLS public keys.
See #30.
Here, we did a translation of BLS-related components of Herumi (MCL) into Noble Curves components. We did this as a test - no production code was touched.