From 1c997ed4f28ac695bd6fa6a4d11ebcc06fe62065 Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Wed, 3 Jul 2024 12:18:14 +0200 Subject: [PATCH] Some clean-ups and docs --- packages/evm/src/precompiles/bls12_381/mcl.ts | 7 +++++ .../evm/src/precompiles/bls12_381/noble.ts | 27 +++++-------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/packages/evm/src/precompiles/bls12_381/mcl.ts b/packages/evm/src/precompiles/bls12_381/mcl.ts index eed8f85391b..e006a0a2637 100644 --- a/packages/evm/src/precompiles/bls12_381/mcl.ts +++ b/packages/evm/src/precompiles/bls12_381/mcl.ts @@ -200,6 +200,13 @@ function BLS12_381_ToFp2Point(fpXCoordinate: Uint8Array, fpYCoordinate: Uint8Arr return fp2 } +/** + * Implementation of the `EVMBLSInterface` using the `mcl-wasm` WASM `mcl` wrapper library, + * see https://github.com/herumi/mcl-wasm. + * + * This can be optionally used to replace the build-in Noble implementation (`NobleBLS`) with + * a more performant WASM variant. See EVM `bls` constructor option on how to use. + */ export class MCLBLS implements EVMBLSInterface { protected readonly _mcl: any diff --git a/packages/evm/src/precompiles/bls12_381/noble.ts b/packages/evm/src/precompiles/bls12_381/noble.ts index 988bb85cdcc..12874f0abd2 100644 --- a/packages/evm/src/precompiles/bls12_381/noble.ts +++ b/packages/evm/src/precompiles/bls12_381/noble.ts @@ -49,18 +49,6 @@ function BLS12_381_ToG1Point(input: Uint8Array) { y, }) - // TODO: validate if these two checks are necessary and - // how to transition to Noble - /*mcl.verifyOrderG1(verifyOrder) - if (verifyOrder && G1.isValidOrder() === false) { - throw new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE) - } - - // Check if these coordinates are actually on the curve. - if (G1.isValid() === false) { - throw new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE) - }*/ - return G1 } @@ -99,15 +87,6 @@ function BLS12_381_ToG2Point(input: Uint8Array) { y: Fp2Y, }) - /*mcl.verifyOrderG2(verifyOrder) - if (verifyOrder && mclPoint.isValidOrder() === false) { - throw new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE) - } - - if (mclPoint.isValid() === false) { - throw new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE) - }*/ - return pG2 } @@ -180,6 +159,12 @@ function BLS12_381_ToFp2Point(fpXCoordinate: Uint8Array, fpYCoordinate: Uint8Arr return FP } +/** + * Implementation of the `EVMBLSInterface` using the `@noble/curves` JS library, + * see https://github.com/paulmillr/noble-curves. + * + * This is the EVM default implementation. + */ export class NobleBLS implements EVMBLSInterface { addG1(input: Uint8Array): Uint8Array { const p1 = BLS12_381_ToG1Point(input.subarray(0, BLS_G1_POINT_BYTE_LENGTH))