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

BLS: translate herumi-mcl logic into noble-curves #51

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

andreibancioiu
Copy link
Contributor

@andreibancioiu andreibancioiu commented Sep 20, 2024

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.

@andreibancioiu andreibancioiu self-assigned this Sep 20, 2024
@andreibancioiu andreibancioiu changed the title Research noble crypto (& herumi) BLS BLS: translate herumi-mcl logic into noble-curves Sep 30, 2024
@andreibancioiu andreibancioiu marked this pull request as ready for review September 30, 2024 11:30
@@ -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"
Copy link
Contributor Author

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");
Copy link
Contributor Author

@andreibancioiu andreibancioiu Sep 30, 2024

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.

Copy link
Contributor Author

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:

multiversx/mx-chain-crypto-go#40

it("test using test vectors", async function () {
this.timeout(100000);

const numVectors = 256;
Copy link
Contributor Author

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";
Copy link
Contributor Author

@andreibancioiu andreibancioiu Sep 30, 2024

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.

Comment on lines +48 to +59

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);
Copy link
Contributor Author

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() {
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant