UNPKG

@ethereumjs/evm

Version:
63 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.moduloLengthCheck = exports.equalityLengthCheck = exports.gasLimitCheck = void 0; const util_1 = require("@ethereumjs/util"); /** * Checks that the gas used remain under the gas limit. * * @param opts - Precompile input wrapper * @param gasUsed - Amount of gas consumed by the precompile * @param pName - Human readable precompile name for logging * @returns `true` if the gas usage is within the provided limit */ const gasLimitCheck = (opts, gasUsed, pName) => { if (opts._debug !== undefined) { opts._debug(`Run ${pName} precompile data=${(0, util_1.short)(opts.data)} length=${opts.data.length} gasLimit=${opts.gasLimit} gasUsed=${gasUsed}`); } if (opts.gasLimit < gasUsed) { if (opts._debug !== undefined) { opts._debug(`${pName} failed: OOG`); } return false; } return true; }; exports.gasLimitCheck = gasLimitCheck; /** * Checks that the length of the provided data is equal to `length`. * * @param opts - Precompile input wrapper * @param length - Required data length in bytes * @param pName - Human readable precompile name for logging * @returns `true` if the provided data matches the required length */ const equalityLengthCheck = (opts, length, pName) => { if (opts.data.length !== length) { if (opts._debug !== undefined) { opts._debug(`${pName} failed: Invalid input length length=${opts.data.length} (expected: ${length})`); } return false; } return true; }; exports.equalityLengthCheck = equalityLengthCheck; /** * Checks that the total length of the provided data input can be subdivided into k equal parts * with `length` (without leaving some remainder bytes). * * @param opts - Precompile input wrapper * @param length - Required chunk size * @param pName - Human readable precompile name for logging * @returns `true` if the length is divisible by the chunk size */ const moduloLengthCheck = (opts, length, pName) => { if (opts.data.length % length !== 0) { if (opts._debug !== undefined) { opts._debug(`${pName} failed: Invalid input length length=${opts.data.length} (expected: ${length}*k bytes)`); } return false; } return true; }; exports.moduloLengthCheck = moduloLengthCheck; //# sourceMappingURL=util.js.map