UNPKG

@ethereumjs/evm

Version:
47 lines 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.precompile11 = precompile11; 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 precompile11(opts) { const pName = (0, index_ts_2.getPrecompileName)('13'); const bls = opts._EVM['_bls']; // note: the gas used is constant; even if the input is incorrect. const gasUsed = opts.common.param('bls12381MapG2Gas') ?? BigInt(0); if (!(0, util_ts_1.gasLimitCheck)(opts, gasUsed, pName)) { return (0, evm_ts_1.OOGResult)(opts.gasLimit); } if (!(0, util_ts_1.equalityLengthCheck)(opts, 128, 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); } // check if some parts of input are zero bytes. const zeroByteRanges = [ [0, 16], [64, 80], ]; if (!(0, index_ts_1.leading16ZeroBytesCheck)(opts, zeroByteRanges, pName)) { 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.mapFP2toG2(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=11-bls12-map-fp2-to-g2.js.map