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

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
"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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants