Skip to content

Commit

Permalink
Some clean-ups and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerd77 committed Jul 3, 2024
1 parent 47ee270 commit 1c997ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
7 changes: 7 additions & 0 deletions packages/evm/src/precompiles/bls12_381/mcl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 6 additions & 21 deletions packages/evm/src/precompiles/bls12_381/noble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 1c997ed

Please sign in to comment.