UNPKG

@ethereumjs/evm

Version:
66 lines 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.precompile0f = precompile0f; const util_1 = require("@ethereumjs/util"); const errors_ts_1 = require("../errors.js"); const evm_ts_1 = require("../evm.js"); const index_ts_1 = require("./bls12_381/index.js"); const index_ts_2 = require("./index.js"); const util_ts_1 = require("./util.js"); async function precompile0f(opts) { const pName = (0, index_ts_2.getPrecompileName)('11'); const bls = opts._EVM['_bls']; const baseGas = opts.common.param('bls12381PairingBaseGas'); // TODO: confirm that this is not a thing for the other precompiles if (opts.data.length === 0) { if (opts._debug !== undefined) { opts._debug(`${pName} failed: Empty input`); } return (0, evm_ts_1.EVMErrorResult)(new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.BLS_12_381_INPUT_EMPTY), opts.gasLimit); } 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 // check (respectively Jochem can maybe have a word) if this is something intended or not if (!(0, util_ts_1.moduloLengthCheck)(opts, 384, pName)) { return (0, evm_ts_1.EVMErrorResult)(new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.BLS_12_381_INVALID_INPUT_LENGTH), opts.gasLimit); } const gasUsed = baseGas + gasUsedPerPair * BigInt(Math.floor(opts.data.length / 384)); if (!(0, util_ts_1.gasLimitCheck)(opts, gasUsed, pName)) { return (0, evm_ts_1.OOGResult)(opts.gasLimit); } // check for mandatory zero bytes const zeroByteRanges = [ [0, 16], [64, 80], [128, 144], [192, 208], [256, 272], [320, 336], ]; for (let k = 0; k < opts.data.length / 384; k++) { // zero bytes check const pairStart = 384 * k; if (!(0, index_ts_1.leading16ZeroBytesCheck)(opts, zeroByteRanges, pName, pairStart)) { return (0, evm_ts_1.EVMErrorResult)(new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.BLS_12_381_POINT_NOT_ON_CURVE), opts.gasLimit); } } let returnValue; try { returnValue = bls.pairingCheck(opts.data); } catch (e) { if (opts._debug !== undefined) { opts._debug(`${pName} failed: ${e.message}`); } return (0, evm_ts_1.EVMErrorResult)(e, opts.gasLimit); } if (opts._debug !== undefined) { opts._debug(`${pName} return value=${(0, util_1.bytesToHex)(returnValue)}`); } return { executionGasUsed: gasUsed, returnValue, }; } //# sourceMappingURL=0f-bls12-pairing.js.map