diff --git a/packages/common/test/data/paramsTest.ts b/packages/common/test/data/paramsTest.ts index 367c2e3c78..a319fc46af 100644 --- a/packages/common/test/data/paramsTest.ts +++ b/packages/common/test/data/paramsTest.ts @@ -13,7 +13,7 @@ export const paramsTest: ParamsDict = { */ 609: { // gasPrices - ecAddGas: 500, // Gas costs for curve addition precompile + bn254AddGas: 500, // Gas costs for curve addition precompile // pow minerReward: '3000000000000000000', // the amount a miner get rewarded for mining a block }, @@ -38,13 +38,13 @@ export const paramsTest: ParamsDict = { */ 1679: { // gasPrices - ecAddGas: 150, // Gas costs for curve addition precompile + bn254AddGas: 150, // Gas costs for curve addition precompile }, /** * BLS12-381 precompiles */ 2537: { // gasPrices - Bls12381G1AddGas: 500, // Gas cost of a single BLS12-381 G1 addition precompile-call + bls12381G1AddGas: 500, // Gas cost of a single BLS12-381 G1 addition precompile-call }, } diff --git a/packages/common/test/params.spec.ts b/packages/common/test/params.spec.ts index 5d2e086877..626954fdb7 100644 --- a/packages/common/test/params.spec.ts +++ b/packages/common/test/params.spec.ts @@ -8,26 +8,26 @@ describe('[Common]: Parameter instantiation / params option / Updates', () => { it('Param option', () => { const c = new Common({ chain: Mainnet, params: paramsTest }) let msg = 'Should also work with parameters passed with params option' - assert.equal(c.param('ecAddGas'), BigInt(150), msg) + assert.equal(c.param('bn254AddGas'), BigInt(150), msg) const params = { 1679: { - ecAddGas: 250, + bn254AddGas: 250, }, } c.updateParams(params) msg = 'Should update parameter on updateParams() and properly rebuild cache' - assert.equal(c.param('ecAddGas'), BigInt(250), msg) + assert.equal(c.param('bn254AddGas'), BigInt(250), msg) c.resetParams(params) msg = 'Should reset all parameters on resetParams() and properly rebuild cache' - assert.equal(c.param('ecAddGas'), BigInt(250), msg) + assert.equal(c.param('bn254AddGas'), BigInt(250), msg) assert.throws(() => { - c.param('ecMulGas'), BigInt(250) + c.param('bn254MulGas'), BigInt(250) }) msg = 'Should not side-manipulate the original params file during updating internally' - assert.equal(paramsTest['1679']['ecAddGas'], 150) + assert.equal(paramsTest['1679']['bn254AddGas'], 150) }) }) @@ -35,15 +35,15 @@ describe('[Common]: Parameter access for param(), paramByHardfork()', () => { it('Basic usage', () => { const c = new Common({ chain: Mainnet, params: paramsTest, eips: [2537] }) let msg = 'Should return correct value when HF directly provided' - assert.equal(c.paramByHardfork('ecAddGas', 'byzantium'), BigInt(500), msg) + assert.equal(c.paramByHardfork('bn254AddGas', 'byzantium'), BigInt(500), msg) msg = 'Should return correct value for HF set in class' c.setHardfork(Hardfork.Byzantium) - assert.equal(c.param('ecAddGas'), BigInt(500), msg) + assert.equal(c.param('bn254AddGas'), BigInt(500), msg) c.setHardfork(Hardfork.Istanbul) - assert.equal(c.param('ecAddGas'), BigInt(150), msg) + assert.equal(c.param('bn254AddGas'), BigInt(150), msg) c.setHardfork(Hardfork.MuirGlacier) - assert.equal(c.param('ecAddGas'), BigInt(150), msg) + assert.equal(c.param('bn254AddGas'), BigInt(150), msg) assert.throws(() => { c.paramByHardfork('notExistingValue', 'byzantium') @@ -55,7 +55,7 @@ describe('[Common]: Parameter access for param(), paramByHardfork()', () => { // To run please manually add an "ecAdd" entry with value 12345 to EIP2537 config // and uncomment the test msg = 'EIP config should take precedence over HF config' - assert.equal(c.param('ecAddGas'), 12345, msg) + assert.equal(c.param('bn254AddGas'), 12345, msg) */ }) @@ -64,7 +64,7 @@ describe('[Common]: Parameter access for param(), paramByHardfork()', () => { c.setHardfork(Hardfork.Byzantium) assert.equal( - c.param('ecAddGas'), + c.param('bn254AddGas'), BigInt(500), 'Should return correct value for HF set in class', ) @@ -123,12 +123,12 @@ describe('[Common]: Parameter access for param(), paramByHardfork()', () => { const UNSUPPORTED_EIP = 1000000 const f = function () { - c.paramByEIP('Bls12381G1AddGas', UNSUPPORTED_EIP) + c.paramByEIP('bls12381G1AddGas', UNSUPPORTED_EIP) } let msg = 'Should throw for using paramByEIP() with an unsupported EIP' assert.throws(f, /not supported$/, undefined, msg) - msg = 'Should return Bls12381G1AddGas gas price for EIP2537' - assert.equal(c.paramByEIP('Bls12381G1AddGas', 2537), BigInt(500), msg) + msg = 'Should return bls12381G1AddGas gas price for EIP2537' + assert.equal(c.paramByEIP('bls12381G1AddGas', 2537), BigInt(500), msg) }) }) diff --git a/packages/evm/src/params.ts b/packages/evm/src/params.ts index 1182a3d183..397e746e20 100644 --- a/packages/evm/src/params.ts +++ b/packages/evm/src/params.ts @@ -137,10 +137,10 @@ export const paramsEVM: ParamsDict = { 609: { // gasPrices modexpGquaddivisorGas: 20, // Gquaddivisor from modexp precompile for gas calculation - ecAddGas: 500, // Gas costs for curve addition precompile - ecMulGas: 40000, // Gas costs for curve multiplication precompile - ecPairingGas: 100000, // Base gas costs for curve pairing precompile - ecPairingWordGas: 80000, // Gas costs regarding curve pairing precompile input length + bn254AddGas: 500, // Gas costs for curve addition precompile + bn254MulGas: 40000, // Gas costs for curve multiplication precompile + bn254PairingGas: 100000, // Base gas costs for curve pairing precompile + bn254PairingWordGas: 80000, // Gas costs regarding curve pairing precompile input length revertGas: 0, // Base fee of the REVERT opcode staticcallGas: 700, // Base fee of the STATICCALL opcode returndatasizeGas: 2, // Base fee of the RETURNDATASIZE opcode @@ -183,10 +183,10 @@ export const paramsEVM: ParamsDict = { 1679: { // gasPrices blake2RoundGas: 1, // Gas cost per round for the Blake2 F precompile - ecAddGas: 150, // Gas costs for curve addition precompile - ecMulGas: 6000, // Gas costs for curve multiplication precompile - ecPairingGas: 45000, // Base gas costs for curve pairing precompile - ecPairingWordGas: 34000, // Gas costs regarding curve pairing precompile input length + bn254AddGas: 150, // Gas costs for curve addition precompile + bn254MulGas: 6000, // Gas costs for curve multiplication precompile + bn254PairingGas: 45000, // Base gas costs for curve pairing precompile + bn254PairingWordGas: 34000, // Gas costs regarding curve pairing precompile input length sstoreSentryEIP2200Gas: 2300, // Minimum gas required to be present for an SSTORE call, not consumed sstoreNoopEIP2200Gas: 800, // Once per SSTORE operation if the value doesn't change sstoreDirtyEIP2200Gas: 800, // Once per SSTORE operation if a dirty value is changed @@ -234,14 +234,14 @@ export const paramsEVM: ParamsDict = { */ 2537: { // gasPrices - Bls12381G1AddGas: 500, // Gas cost of a single BLS12-381 G1 addition precompile-call - Bls12381G1MulGas: 12000, // Gas cost of a single BLS12-381 G1 multiplication precompile-call - Bls12381G2AddGas: 800, // Gas cost of a single BLS12-381 G2 addition precompile-call - Bls12381G2MulGas: 45000, // Gas cost of a single BLS12-381 G2 multiplication precompile-call - Bls12381PairingBaseGas: 65000, // Base gas cost of BLS12-381 pairing check - Bls12381PairingPerPairGas: 43000, // Per-pair gas cost of BLS12-381 pairing check - Bls12381MapG1Gas: 5500, // Gas cost of BLS12-381 map field element to G1 - Bls12381MapG2Gas: 75000, // Gas cost of BLS12-381 map field element to G2 + bls12381G1AddGas: 500, // Gas cost of a single BLS12-381 G1 addition precompile-call + bls12381G1MulGas: 12000, // Gas cost of a single BLS12-381 G1 multiplication precompile-call + bls12381G2AddGas: 800, // Gas cost of a single BLS12-381 G2 addition precompile-call + bls12381G2MulGas: 45000, // Gas cost of a single BLS12-381 G2 multiplication precompile-call + bls12381PairingBaseGas: 65000, // Base gas cost of BLS12-381 pairing check + bls12381PairingPerPairGas: 43000, // Per-pair gas cost of BLS12-381 pairing check + bls12381MapG1Gas: 5500, // Gas cost of BLS12-381 map field element to G1 + bls12381MapG2Gas: 75000, // Gas cost of BLS12-381 map field element to G2 }, /** . * Gas cost increases for state access opcodes diff --git a/packages/evm/src/precompiles/01-ecrecover.ts b/packages/evm/src/precompiles/01-ecrecover.ts index 79bad3c941..e5ad0ad41c 100644 --- a/packages/evm/src/precompiles/01-ecrecover.ts +++ b/packages/evm/src/precompiles/01-ecrecover.ts @@ -13,13 +13,16 @@ import { OOGResult } from '../evm.js' import { gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export function precompile01(opts: PrecompileInput): ExecResult { + const pName = getPrecompileName('01') const ecrecoverFunction = opts.common.customCrypto.ecrecover ?? ecrecover const gasUsed = opts.common.param('ecRecoverGas') - if (!gasLimitCheck(opts, gasUsed, 'ECRECOVER (0x01)')) { + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } @@ -34,7 +37,7 @@ export function precompile01(opts: PrecompileInput): ExecResult { // However, this should throw, only 27 and 28 is allowed as input if (vBigInt !== BIGINT_27 && vBigInt !== BIGINT_28) { if (opts._debug !== undefined) { - opts._debug(`ECRECOVER (0x01) failed: v neither 27 nor 28`) + opts._debug(`${pName} failed: v neither 27 nor 28`) } return { executionGasUsed: gasUsed, @@ -49,7 +52,7 @@ export function precompile01(opts: PrecompileInput): ExecResult { try { if (opts._debug !== undefined) { opts._debug( - `ECRECOVER (0x01): PK recovery with msgHash=${bytesToHex(msgHash)} v=${bytesToHex( + `${pName}: PK recovery with msgHash=${bytesToHex(msgHash)} v=${bytesToHex( v, )} r=${bytesToHex(r)}s=${bytesToHex(s)}}`, ) @@ -57,7 +60,7 @@ export function precompile01(opts: PrecompileInput): ExecResult { publicKey = ecrecoverFunction(msgHash, bytesToBigInt(v), r, s) } catch (e: any) { if (opts._debug !== undefined) { - opts._debug(`ECRECOVER (0x01) failed: PK recovery failed`) + opts._debug(`${pName} failed: PK recovery failed`) } return { executionGasUsed: gasUsed, @@ -66,7 +69,7 @@ export function precompile01(opts: PrecompileInput): ExecResult { } const address = setLengthLeft(publicToAddress(publicKey), 32) if (opts._debug !== undefined) { - opts._debug(`ECRECOVER (0x01) return address=${bytesToHex(address)}`) + opts._debug(`${pName} return address=${bytesToHex(address)}`) } return { executionGasUsed: gasUsed, diff --git a/packages/evm/src/precompiles/02-sha256.ts b/packages/evm/src/precompiles/02-sha256.ts index ebfa2c9ebc..8aebe5fe0e 100644 --- a/packages/evm/src/precompiles/02-sha256.ts +++ b/packages/evm/src/precompiles/02-sha256.ts @@ -5,22 +5,25 @@ import { OOGResult } from '../evm.js' import { gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export function precompile02(opts: PrecompileInput): ExecResult { + const pName = getPrecompileName('02') const data = opts.data const sha256Function = opts.common.customCrypto.sha256 ?? sha256 let gasUsed = opts.common.param('sha256Gas') gasUsed += opts.common.param('sha256WordGas') * BigInt(Math.ceil(data.length / 32)) - if (!gasLimitCheck(opts, gasUsed, 'KECCAK256 (0x02)')) { + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } const hash = sha256Function(data) if (opts._debug !== undefined) { - opts._debug(`KECCAK256 (0x02) return hash=${bytesToHex(hash)}`) + opts._debug(`${pName} return hash=${bytesToHex(hash)}`) } return { diff --git a/packages/evm/src/precompiles/03-ripemd160.ts b/packages/evm/src/precompiles/03-ripemd160.ts index e4e7233751..784ae18ab5 100644 --- a/packages/evm/src/precompiles/03-ripemd160.ts +++ b/packages/evm/src/precompiles/03-ripemd160.ts @@ -5,22 +5,25 @@ import { OOGResult } from '../evm.js' import { gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export function precompile03(opts: PrecompileInput): ExecResult { + const pName = getPrecompileName('03') const data = opts.data let gasUsed = opts.common.param('ripemd160Gas') gasUsed += opts.common.param('ripemd160WordGas') * BigInt(Math.ceil(data.length / 32)) - if (!gasLimitCheck(opts, gasUsed, 'RIPEMD160 (0x03)')) { + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } const hash = setLengthLeft(ripemd160(data), 32) if (opts._debug !== undefined) { - opts._debug(`RIPEMD160 (0x03) return hash=${bytesToHex(hash)}`) + opts._debug(`${pName} return hash=${bytesToHex(hash)}`) } return { diff --git a/packages/evm/src/precompiles/04-identity.ts b/packages/evm/src/precompiles/04-identity.ts index d2a5f70057..b44fc55469 100644 --- a/packages/evm/src/precompiles/04-identity.ts +++ b/packages/evm/src/precompiles/04-identity.ts @@ -4,20 +4,23 @@ import { OOGResult } from '../evm.js' import { gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export function precompile04(opts: PrecompileInput): ExecResult { + const pName = getPrecompileName('04') const data = opts.data let gasUsed = opts.common.param('identityGas') gasUsed += opts.common.param('identityWordGas') * BigInt(Math.ceil(data.length / 32)) - if (!gasLimitCheck(opts, gasUsed, 'IDENTITY (0x04)')) { + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`IDENTITY (0x04) return data=${short(opts.data)}`) + opts._debug(`${pName} return data=${short(opts.data)}`) } return { diff --git a/packages/evm/src/precompiles/05-modexp.ts b/packages/evm/src/precompiles/05-modexp.ts index a1f24b7413..38b185669d 100644 --- a/packages/evm/src/precompiles/05-modexp.ts +++ b/packages/evm/src/precompiles/05-modexp.ts @@ -18,6 +18,8 @@ import { OOGResult } from '../evm.js' import { gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' @@ -104,6 +106,7 @@ export function expMod(a: bigint, power: bigint, modulo: bigint) { } export function precompile05(opts: PrecompileInput): ExecResult { + const pName = getPrecompileName('05') const data = opts.data.length < 96 ? setLengthRight(opts.data, 96) : opts.data let adjustedELen = getAdjustedExponentLength(data) @@ -137,7 +140,7 @@ export function precompile05(opts: PrecompileInput): ExecResult { gasUsed = BIGINT_200 } } - if (!gasLimitCheck(opts, gasUsed, 'MODEXP (0x05)')) { + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } @@ -150,14 +153,14 @@ export function precompile05(opts: PrecompileInput): ExecResult { if (bLen > maxSize || eLen > maxSize || mLen > maxSize) { if (opts._debug !== undefined) { - opts._debug(`MODEXP (0x05) failed: OOG`) + opts._debug(`${pName} failed: OOG`) } return OOGResult(opts.gasLimit) } if (mEnd > maxInt) { if (opts._debug !== undefined) { - opts._debug(`MODEXP (0x05) failed: OOG`) + opts._debug(`${pName} failed: OOG`) } return OOGResult(opts.gasLimit) } @@ -180,7 +183,7 @@ export function precompile05(opts: PrecompileInput): ExecResult { const res = setLengthLeft(R, Number(mLen)) if (opts._debug !== undefined) { - opts._debug(`MODEXP (0x05) return value=${bytesToHex(res)}`) + opts._debug(`${pName} return value=${bytesToHex(res)}`) } return { diff --git a/packages/evm/src/precompiles/06-ecadd.ts b/packages/evm/src/precompiles/06-bn254-add.ts similarity index 75% rename from packages/evm/src/precompiles/06-ecadd.ts rename to packages/evm/src/precompiles/06-bn254-add.ts index b86e9eafb8..23c8163bf1 100644 --- a/packages/evm/src/precompiles/06-ecadd.ts +++ b/packages/evm/src/precompiles/06-bn254-add.ts @@ -4,13 +4,16 @@ import { EvmErrorResult, OOGResult } from '../evm.js' import { gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { EVM } from '../evm.js' import type { ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export function precompile06(opts: PrecompileInput): ExecResult { - const gasUsed = opts.common.param('ecAddGas') - if (!gasLimitCheck(opts, gasUsed, 'ECADD (0x06)')) { + const pName = getPrecompileName('06') + const gasUsed = opts.common.param('bn254AddGas') + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } @@ -23,7 +26,7 @@ export function precompile06(opts: PrecompileInput): ExecResult { returnData = (opts._EVM as EVM)['_bn254'].add(input) } catch (e: any) { if (opts._debug !== undefined) { - opts._debug(`ECADD (0x06) failed: ${e.message}`) + opts._debug(`${pName} failed: ${e.message}`) } return EvmErrorResult(e, opts.gasLimit) } @@ -31,13 +34,13 @@ export function precompile06(opts: PrecompileInput): ExecResult { // check ecadd success or failure by comparing the output length if (returnData.length !== 64) { if (opts._debug !== undefined) { - opts._debug(`ECADD (0x06) failed: OOG`) + opts._debug(`${pName} failed: OOG`) } return OOGResult(opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`ECADD (0x06) return value=${bytesToHex(returnData)}`) + opts._debug(`${pName} return value=${bytesToHex(returnData)}`) } return { diff --git a/packages/evm/src/precompiles/07-ecmul.ts b/packages/evm/src/precompiles/07-bn254-mul.ts similarity index 75% rename from packages/evm/src/precompiles/07-ecmul.ts rename to packages/evm/src/precompiles/07-bn254-mul.ts index 34319642ed..28be204aef 100644 --- a/packages/evm/src/precompiles/07-ecmul.ts +++ b/packages/evm/src/precompiles/07-bn254-mul.ts @@ -4,13 +4,16 @@ import { EvmErrorResult, OOGResult } from '../evm.js' import { gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { EVM } from '../evm.js' import type { ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export function precompile07(opts: PrecompileInput): ExecResult { - const gasUsed = opts.common.param('ecMulGas') - if (!gasLimitCheck(opts, gasUsed, 'ECMUL (0x07)')) { + const pName = getPrecompileName('07') + const gasUsed = opts.common.param('bn254MulGas') + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } @@ -23,7 +26,7 @@ export function precompile07(opts: PrecompileInput): ExecResult { returnData = (opts._EVM as EVM)['_bn254'].mul(input) } catch (e: any) { if (opts._debug !== undefined) { - opts._debug(`ECMUL (0x07) failed: ${e.message}`) + opts._debug(`${pName} failed: ${e.message}`) } return EvmErrorResult(e, opts.gasLimit) } @@ -31,14 +34,14 @@ export function precompile07(opts: PrecompileInput): ExecResult { // check ecmul success or failure by comparing the output length if (returnData.length !== 64) { if (opts._debug !== undefined) { - opts._debug(`ECMUL (0x07) failed: OOG`) + opts._debug(`${pName} failed: OOG`) } // TODO: should this really return OOG? return OOGResult(opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`ECMUL (0x07) return value=${bytesToHex(returnData)}`) + opts._debug(`${pName} return value=${bytesToHex(returnData)}`) } return { diff --git a/packages/evm/src/precompiles/08-ecpairing.ts b/packages/evm/src/precompiles/08-bn254-pairing.ts similarity index 72% rename from packages/evm/src/precompiles/08-ecpairing.ts rename to packages/evm/src/precompiles/08-bn254-pairing.ts index 0dcdc25561..2d1e67ed3a 100644 --- a/packages/evm/src/precompiles/08-ecpairing.ts +++ b/packages/evm/src/precompiles/08-bn254-pairing.ts @@ -5,20 +5,23 @@ import { ERROR, EvmError } from '../exceptions.js' import { gasLimitCheck, moduloLengthCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { EVM } from '../evm.js' import type { ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export function precompile08(opts: PrecompileInput): ExecResult { - if (!moduloLengthCheck(opts, 192, 'ECPAIRING (0x08)')) { + const pName = getPrecompileName('08') + if (!moduloLengthCheck(opts, 192, pName)) { return EvmErrorResult(new EvmError(ERROR.INVALID_INPUT_LENGTH), opts.gasLimit) } const inputDataSize = BigInt(Math.floor(opts.data.length / 192)) const gasUsed = - opts.common.param('ecPairingGas') + inputDataSize * opts.common.param('ecPairingWordGas') + opts.common.param('bn254PairingGas') + inputDataSize * opts.common.param('bn254PairingWordGas') - if (!gasLimitCheck(opts, gasUsed, 'ECPAIRING (0x08)')) { + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } @@ -27,7 +30,7 @@ export function precompile08(opts: PrecompileInput): ExecResult { returnData = (opts._EVM as EVM)['_bn254'].pairing(opts.data) } catch (e: any) { if (opts._debug !== undefined) { - opts._debug(`ECPAIRING (0x08) failed: ${e.message}`) + opts._debug(`${pName} failed: ${e.message}`) } return EvmErrorResult(e, opts.gasLimit) } @@ -35,14 +38,14 @@ export function precompile08(opts: PrecompileInput): ExecResult { // check ecpairing success or failure by comparing the output length if (returnData.length !== 32) { if (opts._debug !== undefined) { - opts._debug(`ECPAIRING (0x08) failed: OOG`) + opts._debug(`${pName} failed: OOG`) } // TODO: should this really return OOG? return OOGResult(opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`ECPAIRING (0x08) return value=${bytesToHex(returnData)}`) + opts._debug(`${pName} return value=${bytesToHex(returnData)}`) } return { diff --git a/packages/evm/src/precompiles/09-blake2f.ts b/packages/evm/src/precompiles/09-blake2f.ts index a45fbd9a77..8a5943389f 100644 --- a/packages/evm/src/precompiles/09-blake2f.ts +++ b/packages/evm/src/precompiles/09-blake2f.ts @@ -5,6 +5,8 @@ import { ERROR, EvmError } from '../exceptions.js' import { gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' @@ -160,10 +162,11 @@ export function F(h: Uint32Array, m: Uint32Array, t: Uint32Array, f: boolean, ro } export function precompile09(opts: PrecompileInput): ExecResult { + const pName = getPrecompileName('09') const data = opts.data if (data.length !== 213) { if (opts._debug !== undefined) { - opts._debug(`BLAKE2F (0x09) failed: OUT_OF_RANGE dataLength=${data.length}`) + opts._debug(`${pName} failed: OUT_OF_RANGE dataLength=${data.length}`) } return { returnValue: new Uint8Array(0), @@ -174,7 +177,7 @@ export function precompile09(opts: PrecompileInput): ExecResult { const lastByte = data.subarray(212, 213)[0] if (lastByte !== 1 && lastByte !== 0) { if (opts._debug !== undefined) { - opts._debug(`BLAKE2F (0x09) failed: OUT_OF_RANGE lastByte=${lastByte}`) + opts._debug(`${pName} failed: OUT_OF_RANGE lastByte=${lastByte}`) } return { returnValue: new Uint8Array(0), @@ -192,7 +195,7 @@ export function precompile09(opts: PrecompileInput): ExecResult { let gasUsed = opts.common.param('blake2RoundGas') gasUsed *= BigInt(rounds) - if (!gasLimitCheck(opts, gasUsed, 'BLAKE2F (0x09)')) { + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } @@ -220,7 +223,7 @@ export function precompile09(opts: PrecompileInput): ExecResult { } if (opts._debug !== undefined) { - opts._debug(`BLAKE2F (0x09) return hash=${bytesToHex(output)}`) + opts._debug(`${pName} return hash=${bytesToHex(output)}`) } return { diff --git a/packages/evm/src/precompiles/0a-kzg-point-evaluation.ts b/packages/evm/src/precompiles/0a-kzg-point-evaluation.ts index ceda3f7bcb..b2320b555b 100644 --- a/packages/evm/src/precompiles/0a-kzg-point-evaluation.ts +++ b/packages/evm/src/precompiles/0a-kzg-point-evaluation.ts @@ -11,6 +11,8 @@ import { ERROR, EvmError } from '../exceptions.js' import { gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' @@ -21,11 +23,12 @@ export const BLS_MODULUS = BigInt( const modulusBuffer = setLengthLeft(bigIntToBytes(BLS_MODULUS), 32) export async function precompile0a(opts: PrecompileInput): Promise { + const pName = getPrecompileName('0a') if (opts.common.customCrypto?.kzg === undefined) { throw new Error('kzg not initialized') } const gasUsed = opts.common.param('kzgPointEvaluationPrecompileGas') - if (!gasLimitCheck(opts, gasUsed, 'KZG_POINT_EVALUATION (0x14)')) { + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } @@ -43,14 +46,14 @@ export async function precompile0a(opts: PrecompileInput): Promise { if (bytesToHex(computeVersionedHash(commitment, version)) !== bytesToHex(versionedHash)) { if (opts._debug !== undefined) { - opts._debug(`KZG_POINT_EVALUATION (0x14) failed: INVALID_COMMITMENT`) + opts._debug(`${pName} failed: INVALID_COMMITMENT`) } return EvmErrorResult(new EvmError(ERROR.INVALID_COMMITMENT), opts.gasLimit) } if (opts._debug !== undefined) { opts._debug( - `KZG_POINT_EVALUATION (0x14): proof verification with commitment=${bytesToHex( + `${pName}: proof verification with commitment=${bytesToHex( commitment, )} z=${bytesToHex(z)} y=${bytesToHex(y)} kzgProof=${bytesToHex(kzgProof)}`, ) @@ -63,12 +66,12 @@ export async function precompile0a(opts: PrecompileInput): Promise { } catch (err: any) { if (err.message.includes('C_KZG_BADARGS') === true) { if (opts._debug !== undefined) { - opts._debug(`KZG_POINT_EVALUATION (0x14) failed: INVALID_INPUTS`) + opts._debug(`${pName} failed: INVALID_INPUTS`) } return EvmErrorResult(new EvmError(ERROR.INVALID_INPUTS), opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`KZG_POINT_EVALUATION (0x14) failed: Unknown error - ${err.message}`) + opts._debug(`${pName} failed: Unknown error - ${err.message}`) } return EvmErrorResult(new EvmError(ERROR.REVERT), opts.gasLimit) } @@ -78,7 +81,7 @@ export async function precompile0a(opts: PrecompileInput): Promise { if (opts._debug !== undefined) { opts._debug( - `KZG_POINT_EVALUATION (0x14) return fieldElements=${bytesToHex( + `${pName} return fieldElements=${bytesToHex( fieldElementsBuffer, )} modulus=${bytesToHex(modulusBuffer)}`, ) diff --git a/packages/evm/src/precompiles/0b-bls12-g1add.ts b/packages/evm/src/precompiles/0b-bls12-g1add.ts index a585b86eac..9fd91e3b4b 100644 --- a/packages/evm/src/precompiles/0b-bls12-g1add.ts +++ b/packages/evm/src/precompiles/0b-bls12-g1add.ts @@ -6,19 +6,22 @@ import { ERROR, EvmError } from '../exceptions.js' import { leading16ZeroBytesCheck } from './bls12_381/index.js' import { equalityLengthCheck, gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export async function precompile0b(opts: PrecompileInput): Promise { + const pName = getPrecompileName('0b') const bls = (opts._EVM)._bls! as EVMBLSInterface // note: the gas used is constant; even if the input is incorrect. - const gasUsed = opts.common.paramByEIP('Bls12381G1AddGas', 2537) ?? BigInt(0) - if (!gasLimitCheck(opts, gasUsed, 'BLS12G1ADD (0x0b)')) { + const gasUsed = opts.common.paramByEIP('bls12381G1AddGas', 2537) ?? BigInt(0) + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } - if (!equalityLengthCheck(opts, 256, 'BLS12G1ADD (0x0b)')) { + if (!equalityLengthCheck(opts, 256, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INVALID_INPUT_LENGTH), opts.gasLimit) } @@ -29,7 +32,7 @@ export async function precompile0b(opts: PrecompileInput): Promise { [128, 144], [192, 208], ] - if (!leading16ZeroBytesCheck(opts, zeroByteRanges, 'BLS12G1ADD (0x0b)')) { + if (!leading16ZeroBytesCheck(opts, zeroByteRanges, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE), opts.gasLimit) } @@ -38,13 +41,13 @@ export async function precompile0b(opts: PrecompileInput): Promise { returnValue = bls.addG1(opts.data) } catch (e: any) { if (opts._debug !== undefined) { - opts._debug(`BLS12G1ADD (0x0b) failed: ${e.message}`) + opts._debug(`${pName} failed: ${e.message}`) } return EvmErrorResult(e, opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`BLS12G1ADD (0x0b) return value=${bytesToHex(returnValue)}`) + opts._debug(`${pName} return value=${bytesToHex(returnValue)}`) } return { diff --git a/packages/evm/src/precompiles/0c-bls12-g1mul.ts b/packages/evm/src/precompiles/0c-bls12-g1mul.ts index 891aa7c3eb..aedb566405 100644 --- a/packages/evm/src/precompiles/0c-bls12-g1mul.ts +++ b/packages/evm/src/precompiles/0c-bls12-g1mul.ts @@ -6,19 +6,22 @@ import { ERROR, EvmError } from '../exceptions.js' import { leading16ZeroBytesCheck } from './bls12_381/index.js' import { equalityLengthCheck, gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export async function precompile0c(opts: PrecompileInput): Promise { + const pName = getPrecompileName('0c') const bls = (opts._EVM)._bls! as EVMBLSInterface // note: the gas used is constant; even if the input is incorrect. - const gasUsed = opts.common.paramByEIP('Bls12381G1MulGas', 2537) ?? BigInt(0) - if (!gasLimitCheck(opts, gasUsed, 'BLS12G1MUL (0x0c)')) { + const gasUsed = opts.common.paramByEIP('bls12381G1MulGas', 2537) ?? BigInt(0) + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } - if (!equalityLengthCheck(opts, 160, 'BLS12G1MUL (0x0c)')) { + if (!equalityLengthCheck(opts, 160, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INVALID_INPUT_LENGTH), opts.gasLimit) } @@ -27,7 +30,7 @@ export async function precompile0c(opts: PrecompileInput): Promise { [0, 16], [64, 80], ] - if (!leading16ZeroBytesCheck(opts, zeroByteRanges, 'BLS12G1MUL (0x0c)')) { + if (!leading16ZeroBytesCheck(opts, zeroByteRanges, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE), opts.gasLimit) } @@ -36,13 +39,13 @@ export async function precompile0c(opts: PrecompileInput): Promise { returnValue = bls.mulG1(opts.data) } catch (e: any) { if (opts._debug !== undefined) { - opts._debug(`BLS12G1MUL (0x0c) failed: ${e.message}`) + opts._debug(`${pName} failed: ${e.message}`) } return EvmErrorResult(e, opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`BLS12G1MUL (0x0c) return value=${bytesToHex(returnValue)}`) + opts._debug(`${pName} return value=${bytesToHex(returnValue)}`) } return { diff --git a/packages/evm/src/precompiles/0d-bls12-g1msm.ts b/packages/evm/src/precompiles/0d-bls12-g1msm.ts index 0ff151754c..ac67b5be48 100644 --- a/packages/evm/src/precompiles/0d-bls12-g1msm.ts +++ b/packages/evm/src/precompiles/0d-bls12-g1msm.ts @@ -6,17 +6,20 @@ import { ERROR, EvmError } from '../exceptions.js' import { leading16ZeroBytesCheck, msmGasUsed } from './bls12_381/index.js' import { gasLimitCheck, moduloLengthCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export async function precompile0d(opts: PrecompileInput): Promise { + const pName = getPrecompileName('0d') const bls = (opts._EVM)._bls! as EVMBLSInterface const inputData = opts.data if (inputData.length === 0) { if (opts._debug !== undefined) { - opts._debug(`BLS12G1MSM (0x0d) failed: Empty input`) + opts._debug(`${pName} failed: Empty input`) } return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INPUT_EMPTY), opts.gasLimit) // follow Geth's implementation } @@ -25,20 +28,20 @@ export async function precompile0d(opts: PrecompileInput): Promise { // 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.paramByEIP('Bls12381G1MulGas', 2537) ?? BigInt(0) + const gasUsedPerPair = opts.common.paramByEIP('bls12381G1MulGas', 2537) ?? BigInt(0) const gasUsed = msmGasUsed(numPairs, gasUsedPerPair) - if (!gasLimitCheck(opts, gasUsed, 'BLS12G1MSM (0x0d)')) { + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } if (inputData.length % 160 !== 0) { if (opts._debug !== undefined) { - opts._debug(`BLS12G1MSM (0x0d) failed: Invalid input length length=${inputData.length}`) + opts._debug(`${pName} failed: Invalid input length length=${inputData.length}`) } return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INVALID_INPUT_LENGTH), opts.gasLimit) } - if (!moduloLengthCheck(opts, 160, 'BLS12G1MSM (0x0d)')) { + if (!moduloLengthCheck(opts, 160, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INVALID_INPUT_LENGTH), opts.gasLimit) } @@ -51,7 +54,7 @@ export async function precompile0d(opts: PrecompileInput): Promise { for (let k = 0; k < numPairs; k++) { // zero bytes check const pairStart = 160 * k - if (!leading16ZeroBytesCheck(opts, zeroByteRanges, 'BLS12G1MSM (0x0d)', pairStart)) { + if (!leading16ZeroBytesCheck(opts, zeroByteRanges, pName, pairStart)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE), opts.gasLimit) } } @@ -61,13 +64,13 @@ export async function precompile0d(opts: PrecompileInput): Promise { returnValue = bls.msmG1(opts.data) } catch (e: any) { if (opts._debug !== undefined) { - opts._debug(`BLS12G1MSM (0x0d) failed: ${e.message}`) + opts._debug(`${pName} failed: ${e.message}`) } return EvmErrorResult(e, opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`BLS12G1MSM (0x0d) return value=${bytesToHex(returnValue)}`) + opts._debug(`${pName} return value=${bytesToHex(returnValue)}`) } return { diff --git a/packages/evm/src/precompiles/0e-bls12-g2add.ts b/packages/evm/src/precompiles/0e-bls12-g2add.ts index e9a6082917..d1bc0e4807 100644 --- a/packages/evm/src/precompiles/0e-bls12-g2add.ts +++ b/packages/evm/src/precompiles/0e-bls12-g2add.ts @@ -6,19 +6,22 @@ import { ERROR, EvmError } from '../exceptions.js' import { leading16ZeroBytesCheck } from './bls12_381/index.js' import { equalityLengthCheck, gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export async function precompile0e(opts: PrecompileInput): Promise { + const pName = getPrecompileName('0e') const bls = (opts._EVM)._bls! as EVMBLSInterface // note: the gas used is constant; even if the input is incorrect. - const gasUsed = opts.common.paramByEIP('Bls12381G2AddGas', 2537) ?? BigInt(0) - if (!gasLimitCheck(opts, gasUsed, 'BLS12G2ADD (0x0e)')) { + const gasUsed = opts.common.paramByEIP('bls12381G2AddGas', 2537) ?? BigInt(0) + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } - if (!equalityLengthCheck(opts, 512, 'BLS12G2ADD (0x0e)')) { + if (!equalityLengthCheck(opts, 512, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INVALID_INPUT_LENGTH), opts.gasLimit) } @@ -33,7 +36,7 @@ export async function precompile0e(opts: PrecompileInput): Promise { [384, 400], [448, 464], ] - if (!leading16ZeroBytesCheck(opts, zeroByteRanges, 'BLS12G2ADD (0x0e)')) { + if (!leading16ZeroBytesCheck(opts, zeroByteRanges, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE), opts.gasLimit) } @@ -47,7 +50,7 @@ export async function precompile0e(opts: PrecompileInput): Promise { } if (opts._debug !== undefined) { - opts._debug(`BLS12G2ADD (0x0e) return value=${bytesToHex(returnValue)}`) + opts._debug(`${pName} return value=${bytesToHex(returnValue)}`) } return { diff --git a/packages/evm/src/precompiles/0f-bls12-g2mul.ts b/packages/evm/src/precompiles/0f-bls12-g2mul.ts index 4b8ed8c581..3e6e16d6eb 100644 --- a/packages/evm/src/precompiles/0f-bls12-g2mul.ts +++ b/packages/evm/src/precompiles/0f-bls12-g2mul.ts @@ -6,19 +6,22 @@ import { ERROR, EvmError } from '../exceptions.js' import { leading16ZeroBytesCheck } from './bls12_381/index.js' import { equalityLengthCheck, gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export async function precompile0f(opts: PrecompileInput): Promise { + const pName = getPrecompileName('0f') const bls = (opts._EVM)._bls! as EVMBLSInterface // note: the gas used is constant; even if the input is incorrect. - const gasUsed = opts.common.paramByEIP('Bls12381G2MulGas', 2537) ?? BigInt(0) - if (!gasLimitCheck(opts, gasUsed, 'BLS12G2MUL (0x0f)')) { + const gasUsed = opts.common.paramByEIP('bls12381G2MulGas', 2537) ?? BigInt(0) + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } - if (!equalityLengthCheck(opts, 288, 'BLS12G2MUL (0x0f)')) { + if (!equalityLengthCheck(opts, 288, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INVALID_INPUT_LENGTH), opts.gasLimit) } @@ -29,7 +32,7 @@ export async function precompile0f(opts: PrecompileInput): Promise { [128, 144], [192, 208], ] - if (!leading16ZeroBytesCheck(opts, zeroByteRanges, 'BLS12G2MUL (0x0f)')) { + if (!leading16ZeroBytesCheck(opts, zeroByteRanges, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE), opts.gasLimit) } @@ -40,13 +43,13 @@ export async function precompile0f(opts: PrecompileInput): Promise { returnValue = bls.mulG2(opts.data) } catch (e: any) { if (opts._debug !== undefined) { - opts._debug(`BLS12G2MUL (0x0f) failed: ${e.message}`) + opts._debug(`${pName} failed: ${e.message}`) } return EvmErrorResult(e, opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`BLS12G2MUL (0x0f) return value=${bytesToHex(returnValue)}`) + opts._debug(`${pName} return value=${bytesToHex(returnValue)}`) } return { diff --git a/packages/evm/src/precompiles/10-bls12-g2msm.ts b/packages/evm/src/precompiles/10-bls12-g2msm.ts index d6bb66e208..b327e3ca6f 100644 --- a/packages/evm/src/precompiles/10-bls12-g2msm.ts +++ b/packages/evm/src/precompiles/10-bls12-g2msm.ts @@ -6,28 +6,31 @@ import { ERROR, EvmError } from '../exceptions.js' import { leading16ZeroBytesCheck, msmGasUsed } from './bls12_381/index.js' import { gasLimitCheck, moduloLengthCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export async function precompile10(opts: PrecompileInput): Promise { + const pName = getPrecompileName('10') const bls = (opts._EVM)._bls! as EVMBLSInterface if (opts.data.length === 0) { if (opts._debug !== undefined) { - opts._debug(`BLS12G2MSM (0x10) failed: Empty input`) + opts._debug(`${pName} failed: Empty input`) } return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INPUT_EMPTY), opts.gasLimit) // follow Geth's implementation } const numPairs = Math.floor(opts.data.length / 288) - const gasUsedPerPair = opts.common.paramByEIP('Bls12381G2MulGas', 2537) ?? BigInt(0) + const gasUsedPerPair = opts.common.paramByEIP('bls12381G2MulGas', 2537) ?? BigInt(0) const gasUsed = msmGasUsed(numPairs, gasUsedPerPair) - if (!gasLimitCheck(opts, gasUsed, 'BLS12G2MSM (0x10)')) { + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } - if (!moduloLengthCheck(opts, 288, 'BLS12G2MSM (0x10)')) { + if (!moduloLengthCheck(opts, 288, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INVALID_INPUT_LENGTH), opts.gasLimit) } @@ -42,7 +45,7 @@ export async function precompile10(opts: PrecompileInput): Promise { for (let k = 0; k < numPairs; k++) { // zero bytes check const pairStart = 288 * k - if (!leading16ZeroBytesCheck(opts, zeroByteRanges, 'BLS12G2MSM (0x10)', pairStart)) { + if (!leading16ZeroBytesCheck(opts, zeroByteRanges, pName, pairStart)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE), opts.gasLimit) } } @@ -52,13 +55,13 @@ export async function precompile10(opts: PrecompileInput): Promise { returnValue = bls.msmG2(opts.data) } catch (e: any) { if (opts._debug !== undefined) { - opts._debug(`BLS12G2MSM (0x10) failed: ${e.message}`) + opts._debug(`${pName} failed: ${e.message}`) } return EvmErrorResult(e, opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`BLS12G2MSM (0x10) return value=${bytesToHex(returnValue)}`) + opts._debug(`${pName} return value=${bytesToHex(returnValue)}`) } return { diff --git a/packages/evm/src/precompiles/11-bls12-pairing.ts b/packages/evm/src/precompiles/11-bls12-pairing.ts index 6c5ad4c107..fa8a03ecc9 100644 --- a/packages/evm/src/precompiles/11-bls12-pairing.ts +++ b/packages/evm/src/precompiles/11-bls12-pairing.ts @@ -6,33 +6,36 @@ import { ERROR, EvmError } from '../exceptions.js' import { leading16ZeroBytesCheck } from './bls12_381/index.js' import { gasLimitCheck, moduloLengthCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export async function precompile11(opts: PrecompileInput): Promise { + const pName = getPrecompileName('11') const bls = (opts._EVM)._bls! as EVMBLSInterface - const baseGas = opts.common.paramByEIP('Bls12381PairingBaseGas', 2537) ?? BigInt(0) + const baseGas = opts.common.paramByEIP('bls12381PairingBaseGas', 2537) ?? BigInt(0) // TODO: confirm that this is not a thing for the other precompiles if (opts.data.length === 0) { if (opts._debug !== undefined) { - opts._debug(`BLS12PAIRING (0x11) failed: Empty input`) + opts._debug(`${pName} failed: Empty input`) } return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INPUT_EMPTY), opts.gasLimit) } - const gasUsedPerPair = opts.common.paramByEIP('Bls12381PairingPerPairGas', 2537) ?? BigInt(0) + const gasUsedPerPair = opts.common.paramByEIP('bls12381PairingPerPairGas', 2537) ?? BigInt(0) // 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 // check (respectively Jochem can maybe have a word) if this is something intended or not - if (!moduloLengthCheck(opts, 384, 'BLS12PAIRING (0x11)')) { + if (!moduloLengthCheck(opts, 384, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INVALID_INPUT_LENGTH), opts.gasLimit) } const gasUsed = baseGas + gasUsedPerPair * BigInt(Math.floor(opts.data.length / 384)) - if (!gasLimitCheck(opts, gasUsed, 'BLS12PAIRING (0x11)')) { + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } @@ -48,7 +51,7 @@ export async function precompile11(opts: PrecompileInput): Promise { for (let k = 0; k < opts.data.length / 384; k++) { // zero bytes check const pairStart = 384 * k - if (!leading16ZeroBytesCheck(opts, zeroByteRanges, 'BLS12PAIRING (0x11)', pairStart)) { + if (!leading16ZeroBytesCheck(opts, zeroByteRanges, pName, pairStart)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE), opts.gasLimit) } } @@ -58,13 +61,13 @@ export async function precompile11(opts: PrecompileInput): Promise { returnValue = bls.pairingCheck(opts.data) } catch (e: any) { if (opts._debug !== undefined) { - opts._debug(`BLS12PAIRING (0x11) failed: ${e.message}`) + opts._debug(`${pName} failed: ${e.message}`) } return EvmErrorResult(e, opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`BLS12PAIRING (0x11) return value=${bytesToHex(returnValue)}`) + opts._debug(`${pName} return value=${bytesToHex(returnValue)}`) } return { diff --git a/packages/evm/src/precompiles/12-bls12-map-fp-to-g1.ts b/packages/evm/src/precompiles/12-bls12-map-fp-to-g1.ts index c5f00aa7c3..93381090db 100644 --- a/packages/evm/src/precompiles/12-bls12-map-fp-to-g1.ts +++ b/packages/evm/src/precompiles/12-bls12-map-fp-to-g1.ts @@ -6,25 +6,28 @@ import { ERROR, EvmError } from '../exceptions.js' import { leading16ZeroBytesCheck } from './bls12_381/index.js' import { equalityLengthCheck, gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export async function precompile12(opts: PrecompileInput): Promise { + const pName = getPrecompileName('12') const bls = (opts._EVM)._bls! as EVMBLSInterface // note: the gas used is constant; even if the input is incorrect. - const gasUsed = opts.common.paramByEIP('Bls12381MapG1Gas', 2537) ?? BigInt(0) - if (!gasLimitCheck(opts, gasUsed, 'BLS12MAPFPTOG1 (0x12)')) { + const gasUsed = opts.common.paramByEIP('bls12381MapG1Gas', 2537) ?? BigInt(0) + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } - if (!equalityLengthCheck(opts, 64, 'BLS12MAPFPTOG1 (0x12)')) { + if (!equalityLengthCheck(opts, 64, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INVALID_INPUT_LENGTH), opts.gasLimit) } // check if some parts of input are zero bytes. const zeroByteRanges = [[0, 16]] - if (!leading16ZeroBytesCheck(opts, zeroByteRanges, 'BLS12MAPFPTOG1 (0x12)')) { + if (!leading16ZeroBytesCheck(opts, zeroByteRanges, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE), opts.gasLimit) } @@ -33,13 +36,13 @@ export async function precompile12(opts: PrecompileInput): Promise { returnValue = bls.mapFPtoG1(opts.data) } catch (e: any) { if (opts._debug !== undefined) { - opts._debug(`BLS12MAPFPTOG1 (0x12) failed: ${e.message}`) + opts._debug(`${pName} failed: ${e.message}`) } return EvmErrorResult(e, opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`BLS12MAPFPTOG1 (0x12) return value=${bytesToHex(returnValue)}`) + opts._debug(`${pName} return value=${bytesToHex(returnValue)}`) } return { diff --git a/packages/evm/src/precompiles/13-bls12-map-fp2-to-g2.ts b/packages/evm/src/precompiles/13-bls12-map-fp2-to-g2.ts index e9936e70da..ff4a60f3c4 100644 --- a/packages/evm/src/precompiles/13-bls12-map-fp2-to-g2.ts +++ b/packages/evm/src/precompiles/13-bls12-map-fp2-to-g2.ts @@ -6,19 +6,22 @@ import { ERROR, EvmError } from '../exceptions.js' import { leading16ZeroBytesCheck } from './bls12_381/index.js' import { equalityLengthCheck, gasLimitCheck } from './util.js' +import { getPrecompileName } from './index.js' + import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' export async function precompile13(opts: PrecompileInput): Promise { + const pName = getPrecompileName('13') const bls = (opts._EVM)._bls! as EVMBLSInterface // note: the gas used is constant; even if the input is incorrect. - const gasUsed = opts.common.paramByEIP('Bls12381MapG2Gas', 2537) ?? BigInt(0) - if (!gasLimitCheck(opts, gasUsed, 'BLS12MAPFP2TOG2 (0x13)')) { + const gasUsed = opts.common.paramByEIP('bls12381MapG2Gas', 2537) ?? BigInt(0) + if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) } - if (!equalityLengthCheck(opts, 128, 'BLS12MAPFP2TOG2 (0x13)')) { + if (!equalityLengthCheck(opts, 128, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_INVALID_INPUT_LENGTH), opts.gasLimit) } @@ -27,7 +30,7 @@ export async function precompile13(opts: PrecompileInput): Promise { [0, 16], [64, 80], ] - if (!leading16ZeroBytesCheck(opts, zeroByteRanges, 'BLS12MAPFP2TOG2 (0x13)')) { + if (!leading16ZeroBytesCheck(opts, zeroByteRanges, pName)) { return EvmErrorResult(new EvmError(ERROR.BLS_12_381_POINT_NOT_ON_CURVE), opts.gasLimit) } @@ -36,13 +39,13 @@ export async function precompile13(opts: PrecompileInput): Promise { returnValue = bls.mapFP2toG2(opts.data) } catch (e: any) { if (opts._debug !== undefined) { - opts._debug(`BLS12MAPFP2TOG2 (0x13) failed: ${e.message}`) + opts._debug(`${pName} failed: ${e.message}`) } return EvmErrorResult(e, opts.gasLimit) } if (opts._debug !== undefined) { - opts._debug(`BLS12MAPFP2TOG2 (0x13) return value=${bytesToHex(returnValue)}`) + opts._debug(`${pName} return value=${bytesToHex(returnValue)}`) } return { diff --git a/packages/evm/src/precompiles/bls12_381/constants.ts b/packages/evm/src/precompiles/bls12_381/constants.ts index 0ce107c5f3..a869e7cb5b 100644 --- a/packages/evm/src/precompiles/bls12_381/constants.ts +++ b/packages/evm/src/precompiles/bls12_381/constants.ts @@ -14,7 +14,7 @@ export const BLS_G2_INFINITY_POINT_BYTES = new Uint8Array(BLS_G2_POINT_BYTE_LENG export const BLS_ZERO_BUFFER = new Uint8Array(32) export const BLS_ONE_BUFFER = concatBytes(new Uint8Array(31), hexToBytes('0x01')) -// gas discount pairs taken from EIP-2537 `Bls12381MultiExpGasDiscount` parameter +// gas discount pairs taken from EIP-2537 `bls12381MultiExpGasDiscount` parameter export const BLS_GAS_DISCOUNT_PAIRS = [ [1, 1200], [2, 888], diff --git a/packages/evm/src/precompiles/index.ts b/packages/evm/src/precompiles/index.ts index 5efa2ba93e..03fef4f1c9 100644 --- a/packages/evm/src/precompiles/index.ts +++ b/packages/evm/src/precompiles/index.ts @@ -6,9 +6,9 @@ import { precompile02 } from './02-sha256.js' import { precompile03 } from './03-ripemd160.js' import { precompile04 } from './04-identity.js' import { precompile05 } from './05-modexp.js' -import { precompile06 } from './06-ecadd.js' -import { precompile07 } from './07-ecmul.js' -import { precompile08 } from './08-ecpairing.js' +import { precompile06 } from './06-bn254-add.js' +import { precompile07 } from './07-bn254-mul.js' +import { precompile08 } from './08-bn254-pairing.js' import { precompile09 } from './09-blake2f.js' import { precompile0a } from './0a-kzg-point-evaluation.js' import { precompile0b } from './0b-bls12-g1add.js' @@ -93,7 +93,7 @@ const precompileEntries: PrecompileEntry[] = [ param: Hardfork.Chainstart, }, precompile: precompile04, - name: 'Identity (0x04)', + name: 'IDENTITY (0x04)', }, { address: BYTES_19 + '05', @@ -111,7 +111,7 @@ const precompileEntries: PrecompileEntry[] = [ param: Hardfork.Byzantium, }, precompile: precompile06, - name: 'ECADD (0x06)', + name: 'BN254_ADD (0x06)', }, { address: BYTES_19 + '07', @@ -120,7 +120,7 @@ const precompileEntries: PrecompileEntry[] = [ param: Hardfork.Byzantium, }, precompile: precompile07, - name: 'ECMUL (0x07)', + name: 'BN254_MUL (0x07)', }, { address: BYTES_19 + '08', @@ -129,7 +129,7 @@ const precompileEntries: PrecompileEntry[] = [ param: Hardfork.Byzantium, }, precompile: precompile08, - name: 'ECPAIR (0x08)', + name: 'BN254_PAIRING (0x08)', }, { address: BYTES_19 + '09', @@ -147,7 +147,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 4844, }, precompile: precompile0a, - name: 'KZG (0x0a)', + name: 'KZG_POINT_EVALUATION (0x0a)', }, { address: BYTES_19 + '0b', @@ -156,7 +156,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile0b, - name: 'BLS12_G1ADD', + name: 'BLS12_G1ADD (0x0b)', }, { address: BYTES_19 + '0c', @@ -165,7 +165,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile0c, - name: 'BLS12_G1MUL', + name: 'BLS12_G1MUL (0x0c)', }, { address: BYTES_19 + '0d', @@ -174,7 +174,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile0d, - name: 'BLS12_G1MSM', + name: 'BLS12_G1MSM (0x0d)', }, { address: BYTES_19 + '0e', @@ -183,7 +183,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile0e, - name: 'BLS12_G2ADD', + name: 'BLS12_G2ADD (0x0e)', }, { address: BYTES_19 + '0f', @@ -192,7 +192,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile0f, - name: 'BLS12_G2MUL', + name: 'BLS12_G2MUL (0x0f)', }, { address: BYTES_19 + '10', @@ -201,7 +201,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile10, - name: 'BLS12_G2MSM', + name: 'BLS12_G2MSM (0x10)', }, { address: BYTES_19 + '11', @@ -210,7 +210,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile11, - name: 'BLS12_PAIRING', + name: 'BLS12_PAIRING (0x11)', }, { address: BYTES_19 + '12', @@ -219,7 +219,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile12, - name: 'BLS12_MAP_FP_TO_G1', + name: 'BLS12_MAP_FP_TO_G1 (0x12)', }, { address: BYTES_19 + '13', @@ -228,7 +228,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile13, - name: 'BLS12_MAP_FP2_TO_G2', + name: 'BLS12_MAP_FP2_TO_G2 (0x13)', }, ] @@ -296,11 +296,15 @@ function getActivePrecompiles( } function getPrecompileName(addressUnprefixedStr: string) { + if (addressUnprefixedStr.length < 40) { + addressUnprefixedStr = addressUnprefixedStr.padStart(40, '0') + } for (const entry of precompileEntries) { if (entry.address === addressUnprefixedStr) { return entry.name } } + return '' } export { diff --git a/packages/evm/src/types.ts b/packages/evm/src/types.ts index b4281c52a8..2051deb34d 100644 --- a/packages/evm/src/types.ts +++ b/packages/evm/src/types.ts @@ -251,7 +251,7 @@ export interface EVMOpts { * * ```ts * const params = JSON.parse(JSON.stringify(paramsEVM)) - * params['1679']['ecAddGas'] = 100 // 150 + * params['1679']['bn254AddGas'] = 100 // 150 * ``` */ params?: ParamsDict diff --git a/packages/evm/test/evm.spec.ts b/packages/evm/test/evm.spec.ts index 30197834dc..1287b78bb7 100644 --- a/packages/evm/test/evm.spec.ts +++ b/packages/evm/test/evm.spec.ts @@ -14,11 +14,15 @@ describe('initialization', () => { it('EVM parameter customization', async () => { let evm = await createEVM() - assert.equal(evm.common.param('ecAddGas'), BigInt(150), 'should use default EVM parameters') + assert.equal(evm.common.param('bn254AddGas'), BigInt(150), 'should use default EVM parameters') const params = JSON.parse(JSON.stringify(paramsEVM)) - params['1679']['ecAddGas'] = 100 // 150 + params['1679']['bn254AddGas'] = 100 // 150 evm = await createEVM({ params }) - assert.equal(evm.common.param('ecAddGas'), BigInt(100), 'should use custom parameters provided') + assert.equal( + evm.common.param('bn254AddGas'), + BigInt(100), + 'should use custom parameters provided', + ) }) }) diff --git a/packages/evm/test/precompiles/06-ecadd.spec.ts b/packages/evm/test/precompiles/06-ecadd.spec.ts index fad052a08a..7d0ebeddde 100644 --- a/packages/evm/test/precompiles/06-ecadd.spec.ts +++ b/packages/evm/test/precompiles/06-ecadd.spec.ts @@ -3,16 +3,16 @@ import { assert, describe, it } from 'vitest' import { createEVM, getActivePrecompiles } from '../../src/index.js' -describe('Precompiles: ECADD', () => { - it('ECADD', async () => { +describe('Precompiles: BN254ADD', () => { + it('BN254ADD', async () => { const common = new Common({ chain: Mainnet, hardfork: Hardfork.Petersburg }) const evm = await createEVM({ common, }) const addressStr = '0000000000000000000000000000000000000006' - const ECADD = getActivePrecompiles(common).get(addressStr)! + const BN254ADD = getActivePrecompiles(common).get(addressStr)! - const result = await ECADD({ + const result = await BN254ADD({ data: new Uint8Array(0), gasLimit: BigInt(0xffff), common, diff --git a/packages/evm/test/precompiles/07-ecmul.spec.ts b/packages/evm/test/precompiles/07-ecmul.spec.ts index ed9ac1e9a9..8d547102e0 100644 --- a/packages/evm/test/precompiles/07-ecmul.spec.ts +++ b/packages/evm/test/precompiles/07-ecmul.spec.ts @@ -3,15 +3,15 @@ import { assert, describe, it } from 'vitest' import { createEVM, getActivePrecompiles } from '../../src/index.js' -describe('Precompiles: ECMUL', () => { - it('ECMUL', async () => { +describe('Precompiles: BN254MUL', () => { + it('BN254MUL', async () => { const common = new Common({ chain: Mainnet, hardfork: Hardfork.Petersburg }) const evm = await createEVM({ common, }) - const ECMUL = getActivePrecompiles(common).get('0000000000000000000000000000000000000007')! + const BN254MUL = getActivePrecompiles(common).get('0000000000000000000000000000000000000007')! - const result = await ECMUL({ + const result = await BN254MUL({ data: new Uint8Array(0), gasLimit: BigInt(0xffff), common, diff --git a/packages/evm/test/precompiles/08-ecpairing.spec.ts b/packages/evm/test/precompiles/08-ecpairing.spec.ts index 9888b52395..82149cce5a 100644 --- a/packages/evm/test/precompiles/08-ecpairing.spec.ts +++ b/packages/evm/test/precompiles/08-ecpairing.spec.ts @@ -4,15 +4,15 @@ import { assert, describe, it } from 'vitest' import { createEVM, getActivePrecompiles } from '../../src/index.js' -describe('Precompiles: ECPAIRING', () => { - it('ECPAIRING', async () => { +describe('Precompiles: BN254PAIRING', () => { + it('BN254PAIRING', async () => { const common = new Common({ chain: Mainnet, hardfork: Hardfork.Petersburg }) const evm = await createEVM({ common, }) const addressStr = '0000000000000000000000000000000000000008' - const ECPAIRING = getActivePrecompiles(common).get(addressStr)! - const result = await ECPAIRING({ + const BN254PAIRING = getActivePrecompiles(common).get(addressStr)! + const result = await BN254PAIRING({ data: hexToBytes( '0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa000000000000000000000000000000000000000000000000000000000000000130644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd45198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa', ), diff --git a/packages/evm/test/precompiles/hardfork.spec.ts b/packages/evm/test/precompiles/hardfork.spec.ts index da5495b8f8..0044ed5e7a 100644 --- a/packages/evm/test/precompiles/hardfork.spec.ts +++ b/packages/evm/test/precompiles/hardfork.spec.ts @@ -5,19 +5,19 @@ import { assert, describe, it } from 'vitest' import { createEVM, getActivePrecompiles } from '../../src/index.js' describe('Precompiles: hardfork availability', () => { - it('Test ECPAIRING availability', async () => { + it('Test BN254PAIRING availability', async () => { const ECPAIR_AddressStr = '0000000000000000000000000000000000000008' const ECPAIR_Address = new Address(hexToBytes(`0x${ECPAIR_AddressStr}`)) // ECPAIR was introduced in Byzantium; check if available from Byzantium. const commonByzantium = new Common({ chain: Mainnet, hardfork: Hardfork.Byzantium }) - let ECPAIRING = getActivePrecompiles(commonByzantium).get(ECPAIR_AddressStr) + let BN254PAIRING = getActivePrecompiles(commonByzantium).get(ECPAIR_AddressStr) - if (!ECPAIRING) { - assert.fail('ECPAIRING is not available in petersburg while it should be available') + if (!BN254PAIRING) { + assert.fail('BN254PAIRING is not available in petersburg while it should be available') } else { - assert.ok(true, 'ECPAIRING available in petersburg') + assert.ok(true, 'BN254PAIRING available in petersburg') } let evm = await createEVM({ @@ -34,11 +34,11 @@ describe('Precompiles: hardfork availability', () => { // Check if ECPAIR is available in future hard forks. const commonPetersburg = new Common({ chain: Mainnet, hardfork: Hardfork.Petersburg }) - ECPAIRING = getActivePrecompiles(commonPetersburg).get(ECPAIR_AddressStr)! - if (ECPAIRING === undefined) { - assert.fail('ECPAIRING is not available in petersburg while it should be available') + BN254PAIRING = getActivePrecompiles(commonPetersburg).get(ECPAIR_AddressStr)! + if (BN254PAIRING === undefined) { + assert.fail('BN254PAIRING is not available in petersburg while it should be available') } else { - assert.ok(true, 'ECPAIRING available in petersburg') + assert.ok(true, 'BN254PAIRING available in petersburg') } evm = await createEVM({ @@ -55,12 +55,12 @@ describe('Precompiles: hardfork availability', () => { // Check if ECPAIR is not available in Homestead. const commonHomestead = new Common({ chain: Mainnet, hardfork: Hardfork.Homestead }) - ECPAIRING = getActivePrecompiles(commonHomestead).get(ECPAIR_AddressStr)! + BN254PAIRING = getActivePrecompiles(commonHomestead).get(ECPAIR_AddressStr)! - if (ECPAIRING !== undefined) { - assert.fail('ECPAIRING is available in homestead while it should not be available') + if (BN254PAIRING !== undefined) { + assert.fail('BN254PAIRING is available in homestead while it should not be available') } else { - assert.ok(true, 'ECPAIRING not available in homestead') + assert.ok(true, 'BN254PAIRING not available in homestead') } evm = await createEVM({ diff --git a/packages/vm/test/api/index.spec.ts b/packages/vm/test/api/index.spec.ts index 80cf4120eb..bf94c5ad79 100644 --- a/packages/vm/test/api/index.spec.ts +++ b/packages/vm/test/api/index.spec.ts @@ -183,7 +183,7 @@ describe('VM -> common (chain, HFs, EIPs)', () => { let common = createCustomCommon({ chainId: 3 }, Mainnet) common.setHardfork(Hardfork.Byzantium) let vm = await createVM({ common }) - assert.equal(vm.common.param('ecAddGas'), BigInt(500)) + assert.equal(vm.common.param('bn254AddGas'), BigInt(500)) try { common = new Common({ chain: Mainnet, hardfork: 'extraCheese' }) diff --git a/packages/vm/test/api/istanbul/eip-1108.spec.ts b/packages/vm/test/api/istanbul/eip-1108.spec.ts index da6852fa31..6edeeef53b 100644 --- a/packages/vm/test/api/istanbul/eip-1108.spec.ts +++ b/packages/vm/test/api/istanbul/eip-1108.spec.ts @@ -13,11 +13,11 @@ describe('Istanbul: EIP-1108 tests', () => { beforeAll(async () => { vm = await createVM({ common }) }) - it('ECADD', async () => { + it('BN254ADD', async () => { const address = '0000000000000000000000000000000000000006' - const ECADD = getActivePrecompiles(common).get(address)! + const BN254ADD = getActivePrecompiles(common).get(address)! - const result = await ECADD({ + const result = await BN254ADD({ data: new Uint8Array(0), gasLimit: BigInt(0xffff), common, @@ -27,11 +27,11 @@ describe('Istanbul: EIP-1108 tests', () => { assert.deepEqual(result.executionGasUsed, BigInt(150), 'should use istanbul gas costs') }) - it('ECMUL', async () => { + it('BN254MUL', async () => { const address = '0000000000000000000000000000000000000007' - const ECMUL = getActivePrecompiles(common).get(address)! + const BN254MUL = getActivePrecompiles(common).get(address)! - const result = await ECMUL({ + const result = await BN254MUL({ data: new Uint8Array(0), gasLimit: BigInt(0xffff), common, @@ -41,11 +41,11 @@ describe('Istanbul: EIP-1108 tests', () => { assert.deepEqual(result.executionGasUsed, BigInt(6000), 'should use istanbul gas costs') }) - it('ECPAIRING', async () => { + it('BN254PAIRING', async () => { const address = '0000000000000000000000000000000000000008' - const ECPAIRING = getActivePrecompiles(common).get(address)! + const BN254PAIRING = getActivePrecompiles(common).get(address)! - const result = await ECPAIRING({ + const result = await BN254PAIRING({ data: hexToBytes( '0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa000000000000000000000000000000000000000000000000000000000000000130644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd45198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa', ),