Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/evm/src/precompiles/0b-bls12-g1add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function precompile0b(opts: PrecompileInput): Promise<ExecResult> {
const bls = (opts._EVM as EVM)['_bls']!

// note: the gas used is constant; even if the input is incorrect.
const gasUsed = opts.common.param('bls12381G1AddGas') ?? BigInt(0)
const gasUsed = opts.common.param('bls12381G1AddGas')
if (!gasLimitCheck(opts, gasUsed, pName)) {
return OOGResult(opts.gasLimit)
}
Expand Down
11 changes: 1 addition & 10 deletions packages/evm/src/precompiles/0c-bls12-g1msm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,13 @@ export async function precompile0c(opts: PrecompileInput): Promise<ExecResult> {
// on this eventually to be "floored" pair number should happen before the input length modulo
// validation (same for g2msm)
const numPairs = Math.floor(inputData.length / 160)
const gasUsedPerPair = opts.common.param('bls12381G1MulGas') ?? BigInt(0)
const gasUsedPerPair = opts.common.param('bls12381G1MulGas')
const gasUsed = msmGasUsed(numPairs, gasUsedPerPair, BLS_GAS_DISCOUNT_PAIRS_G1)

if (!gasLimitCheck(opts, gasUsed, pName)) {
return OOGResult(opts.gasLimit)
}

if (inputData.length % 160 !== 0) {
if (opts._debug !== undefined) {
opts._debug(`${pName} failed: Invalid input length length=${inputData.length}`)
}
return EVMErrorResult(
new EVMError(EVMError.errorMessages.BLS_12_381_INVALID_INPUT_LENGTH),
opts.gasLimit,
)
}
if (!moduloLengthCheck(opts, 160, pName)) {
return EVMErrorResult(
new EVMError(EVMError.errorMessages.BLS_12_381_INVALID_INPUT_LENGTH),
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/src/precompiles/0d-bls12-g2add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function precompile0d(opts: PrecompileInput): Promise<ExecResult> {
const bls = (opts._EVM as EVM)['_bls']!

// note: the gas used is constant; even if the input is incorrect.
const gasUsed = opts.common.param('bls12381G2AddGas') ?? BigInt(0)
const gasUsed = opts.common.param('bls12381G2AddGas')
if (!gasLimitCheck(opts, gasUsed, pName)) {
return OOGResult(opts.gasLimit)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/src/precompiles/0e-bls12-g2msm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function precompile0e(opts: PrecompileInput): Promise<ExecResult> {
}

const numPairs = Math.floor(opts.data.length / 288)
const gasUsedPerPair = opts.common.param('bls12381G2MulGas') ?? BigInt(0)
const gasUsedPerPair = opts.common.param('bls12381G2MulGas')
const gasUsed = msmGasUsed(numPairs, gasUsedPerPair, BLS_GAS_DISCOUNT_PAIRS_G2)

if (!gasLimitCheck(opts, gasUsed, pName)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/evm/src/precompiles/0f-bls12-pairing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function precompile0f(opts: PrecompileInput): Promise<ExecResult> {
const pName = getPrecompileName('11')
const bls = (opts._EVM as EVM)['_bls']!

const baseGas = opts.common.param('bls12381PairingBaseGas') ?? BigInt(0)
const baseGas = opts.common.param('bls12381PairingBaseGas')

// TODO: confirm that this is not a thing for the other precompiles
if (opts.data.length === 0) {
Expand All @@ -28,7 +28,7 @@ export async function precompile0f(opts: PrecompileInput): Promise<ExecResult> {
)
}

const gasUsedPerPair = opts.common.param('bls12381PairingPerPairGas') ?? BigInt(0)
const gasUsedPerPair = opts.common.param('bls12381PairingPerPairGas')

// TODO: For this precompile it is the only exception that the length check is placed before the
// gas check. I will keep it there to not side-change the existing implementation, but we should
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/src/precompiles/10-bls12-map-fp-to-g1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function precompile10(opts: PrecompileInput): Promise<ExecResult> {
const bls = (opts._EVM as EVM)['_bls']!

// note: the gas used is constant; even if the input is incorrect.
const gasUsed = opts.common.param('bls12381MapG1Gas') ?? BigInt(0)
const gasUsed = opts.common.param('bls12381MapG1Gas')
if (!gasLimitCheck(opts, gasUsed, pName)) {
return OOGResult(opts.gasLimit)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/src/precompiles/11-bls12-map-fp2-to-g2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function precompile11(opts: PrecompileInput): Promise<ExecResult> {
const bls = (opts._EVM as EVM)['_bls']!

// note: the gas used is constant; even if the input is incorrect.
const gasUsed = opts.common.param('bls12381MapG2Gas') ?? BigInt(0)
const gasUsed = opts.common.param('bls12381MapG2Gas')
if (!gasLimitCheck(opts, gasUsed, pName)) {
return OOGResult(opts.gasLimit)
}
Expand Down
20 changes: 0 additions & 20 deletions packages/evm/src/precompiles/bls12_381/mcl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,6 @@ export class MCLBLS implements EVMBLSInterface {
return BLS12_381_FromG1Point(result)
}

mulG1(input: Uint8Array): Uint8Array {
// convert input to G1 points, add them, and convert the output to a Uint8Array.
const p = BLS12_381_ToG1Point(input.subarray(0, BLS_G1_POINT_BYTE_LENGTH), this._mcl)
const frPoint = BLS12_381_ToFrPoint(input.subarray(BLS_G1_POINT_BYTE_LENGTH, 160), this._mcl)

const result = this._mcl.mul(p, frPoint)

return BLS12_381_FromG1Point(result)
}

addG2(input: Uint8Array): Uint8Array {
// convert input to G1 points, add them, and convert the output to a Uint8Array.
const p1 = BLS12_381_ToG2Point(input.subarray(0, BLS_G2_POINT_BYTE_LENGTH), this._mcl, false)
Expand All @@ -258,16 +248,6 @@ export class MCLBLS implements EVMBLSInterface {
return BLS12_381_FromG2Point(result)
}

mulG2(input: Uint8Array): Uint8Array {
// convert input to G2 point/Fr point, add them, and convert the output to a Uint8Array.
const p = BLS12_381_ToG2Point(input.subarray(0, BLS_G2_POINT_BYTE_LENGTH), this._mcl)
const frPoint = BLS12_381_ToFrPoint(input.subarray(BLS_G2_POINT_BYTE_LENGTH, 288), this._mcl)

const result = this._mcl.mul(p, frPoint)

return BLS12_381_FromG2Point(result)
}

mapFPtoG1(input: Uint8Array): Uint8Array {
// convert input to Fp1 point
const Fp1Point = BLS12_381_ToFpPoint(input.subarray(0, 64), this._mcl)
Expand Down
24 changes: 0 additions & 24 deletions packages/evm/src/precompiles/bls12_381/noble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import type { AffinePoint } from '@noble/curves/abstract/weierstrass.js'
import type { EVMBLSInterface } from '../../types.ts'

// @ts-ignore - @noble/curves v2 is ESM-only, TypeScript's moduleResolution: "node" doesn't properly resolve types for CJS build

Check warning on line 27 in packages/evm/src/precompiles/bls12_381/noble.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
const G1_ZERO = bls12_381.G1.Point.ZERO
// @ts-ignore - @noble/curves v2 is ESM-only, TypeScript's moduleResolution: "node" doesn't properly resolve types for CJS build

Check warning on line 29 in packages/evm/src/precompiles/bls12_381/noble.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
const G2_ZERO = bls12_381.G2.Point.ZERO

function BLS12_381_ToFp2Point(fpXCoordinate: Uint8Array, fpYCoordinate: Uint8Array) {
Expand Down Expand Up @@ -58,7 +58,7 @@
const x = bytesToBigInt(input.subarray(16, BLS_G1_POINT_BYTE_LENGTH / 2))
const y = bytesToBigInt(input.subarray(80, BLS_G1_POINT_BYTE_LENGTH))

// @ts-ignore - @noble/curves v2 is ESM-only, TypeScript's moduleResolution: "node" doesn't properly resolve types for CJS build

Check warning on line 61 in packages/evm/src/precompiles/bls12_381/noble.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
const G1 = bls12_381.G1.Point.fromAffine({
x,
y,
Expand Down Expand Up @@ -102,7 +102,7 @@
const Fp2X = BLS12_381_ToFp2Point(p_x_1, p_x_2)
const Fp2Y = BLS12_381_ToFp2Point(p_y_1, p_y_2)

// @ts-ignore - @noble/curves v2 is ESM-only, TypeScript's moduleResolution: "node" doesn't properly resolve types for CJS build

Check warning on line 105 in packages/evm/src/precompiles/bls12_381/noble.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
const pG2 = bls12_381.G2.Point.fromAffine({
x: Fp2X,
y: Fp2Y,
Expand Down Expand Up @@ -172,18 +172,6 @@
return result
}

mulG1(input: Uint8Array): Uint8Array {
// convert input to G1 points, add them, and convert the output to a Uint8Array.
const p = BLS12_381_ToG1Point(input.subarray(0, BLS_G1_POINT_BYTE_LENGTH))
const scalar = BLS12_381_ToFrPoint(input.subarray(BLS_G1_POINT_BYTE_LENGTH, 160))

if (scalar === BIGINT_0) {
return BLS_G1_INFINITY_POINT_BYTES
}
const result = p.multiplyUnsafe(scalar)
return BLS12_381_FromG1Point(result.toAffine())
}

addG2(input: Uint8Array): Uint8Array {
const p1 = BLS12_381_ToG2Point(input.subarray(0, BLS_G2_POINT_BYTE_LENGTH), false)
const p2 = BLS12_381_ToG2Point(
Expand All @@ -196,22 +184,10 @@
return result
}

mulG2(input: Uint8Array): Uint8Array {
// convert input to G2 point/Fr point, add them, and convert the output to a Uint8Array.
const p = BLS12_381_ToG2Point(input.subarray(0, BLS_G2_POINT_BYTE_LENGTH))
const scalar = BLS12_381_ToFrPoint(input.subarray(BLS_G2_POINT_BYTE_LENGTH, 288))

if (scalar === BIGINT_0) {
return BLS_G2_INFINITY_POINT_BYTES
}
const result = p.multiplyUnsafe(scalar)
return BLS12_381_FromG2Point(result.toAffine())
}

mapFPtoG1(input: Uint8Array): Uint8Array {
// convert input to Fp1 point
const FP = BLS12_381_ToFpPoint(input.subarray(0, 64))
// @ts-ignore - @noble/curves v2 is ESM-only, TypeScript's moduleResolution: "node" doesn't properly resolve types for CJS build

Check warning on line 190 in packages/evm/src/precompiles/bls12_381/noble.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
const result = bls12_381.G1.mapToCurve(FP).toAffine()
const resultBytes = BLS12_381_FromG1Point(result)
return resultBytes
Expand All @@ -220,7 +196,7 @@
mapFP2toG2(input: Uint8Array): Uint8Array {
// convert input to Fp2 point
const Fp2Point = BLS12_381_ToFp2Point(input.subarray(0, 64), input.subarray(64, 128))
// @ts-ignore - @noble/curves v2 is ESM-only, TypeScript's moduleResolution: "node" doesn't properly resolve types for CJS build

Check warning on line 199 in packages/evm/src/precompiles/bls12_381/noble.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
const result = bls12_381.G2.mapToCurve([Fp2Point.c0, Fp2Point.c1]).toAffine()
const resultBytes = BLS12_381_FromG2Point(result)
return resultBytes
Expand Down
2 changes: 0 additions & 2 deletions packages/evm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,7 @@ export interface ExecResult {
export type EVMBLSInterface = {
init?(): void
addG1(input: Uint8Array): Uint8Array
mulG1(input: Uint8Array): Uint8Array
addG2(input: Uint8Array): Uint8Array
mulG2(input: Uint8Array): Uint8Array
mapFPtoG1(input: Uint8Array): Uint8Array
mapFP2toG2(input: Uint8Array): Uint8Array
msmG1(input: Uint8Array): Uint8Array
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ It is also possible to only run the tests from the skip lists:
The following command shows an example of how to get coverage for a set of the official spec test files:

```bash
VITE_CUSTOM_TESTS_PATH=../execution-spec-tests/fusaka-devnet-5/state_tests/osaka/eip7951_p256verify_precompiles VITE_FORK=Osaka npx vitest watch --coverage --coverage.reporter=html --ui --coverage.allowExternal test/tester/state.spec.ts
DEBUG=ethjs,dummy:* VITE_CUSTOM_TESTS_PATH=../execution-spec-tests/fusaka-devnet-5/state_tests/osaka/eip7951_p256verify_precompiles VITE_FORK=Osaka npx vitest watch --coverage --coverage.reporter=html --ui --coverage.allowExternal --coverage.include=evm/src/precompiles/0c-bls12-g1msm.ts [--coverage.include=evm/src/precompiles/index.ts] test/tester/state.spec.ts
```

This can be useful to identify gaps in the coverage of the official spec tests and see where additional tests are needed.

The specific command stays in "watch" mode and opens a specific UI to see coverage also for EVM files (this needs the `coverage.allowExternal` flag to be set).
The specific command stays in "watch" mode and opens a specific UI to see coverage also for EVM files (this needs the `coverage.allowExternal` flag to be set). The `DEBUG` part can be helpful to not have coverage being distorted by non-debug calls artificially lowering the coverage.

### Coverage Reporting

Expand Down
Loading