UNPKG

@ethereumjs/evm

Version:
68 lines 3.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.precompile0c = precompile0c; 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 precompile0c(opts) { const pName = (0, index_ts_2.getPrecompileName)('0d'); const bls = opts._EVM['_bls']; const inputData = opts.data; if (inputData.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); // follow Geth's implementation } // TODO: Double-check respectively confirm that this order is really correct that the gas check // 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 gasUsed = (0, index_ts_1.msmGasUsed)(numPairs, gasUsedPerPair, index_ts_1.BLS_GAS_DISCOUNT_PAIRS_G1); if (!(0, util_ts_1.gasLimitCheck)(opts, gasUsed, pName)) { return (0, evm_ts_1.OOGResult)(opts.gasLimit); } if (inputData.length % 160 !== 0) { if (opts._debug !== undefined) { opts._debug(`${pName} failed: Invalid input length length=${inputData.length}`); } return (0, evm_ts_1.EVMErrorResult)(new errors_ts_1.EVMError(errors_ts_1.EVMError.errorMessages.BLS_12_381_INVALID_INPUT_LENGTH), opts.gasLimit); } if (!(0, util_ts_1.moduloLengthCheck)(opts, 160, 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); } // prepare pairing list and check for mandatory zero bytes const zeroByteRanges = [ [0, 16], [64, 80], ]; for (let k = 0; k < numPairs; k++) { // zero bytes check const pairStart = 160 * 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.msmG1(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=0c-bls12-g1msm.js.map