@ethereumjs/evm
Version:
JavaScript Ethereum Virtual Machine (EVM) implementation
42 lines • 1.6 kB
JavaScript
import { bytesToHex } from '@ethereumjs/util';
import { EVMError } from "../errors.js";
import { EVMErrorResult, OOGResult } from "../evm.js";
import { getPrecompileName } from "./index.js";
import { gasLimitCheck, moduloLengthCheck } from "./util.js";
export function precompile08(opts) {
const pName = getPrecompileName('08');
if (!moduloLengthCheck(opts, 192, pName)) {
return EVMErrorResult(new EVMError(EVMError.errorMessages.INVALID_INPUT_LENGTH), opts.gasLimit);
}
const inputDataSize = BigInt(Math.floor(opts.data.length / 192));
const gasUsed = opts.common.param('bn254PairingGas') + inputDataSize * opts.common.param('bn254PairingWordGas');
if (!gasLimitCheck(opts, gasUsed, pName)) {
return OOGResult(opts.gasLimit);
}
let returnData;
try {
returnData = opts._EVM['_bn254'].pairing(opts.data);
}
catch (e) {
if (opts._debug !== undefined) {
opts._debug(`${pName} failed: ${e.message}`);
}
return EVMErrorResult(e, opts.gasLimit);
}
// check ecpairing success or failure by comparing the output length
if (returnData.length !== 32) {
if (opts._debug !== undefined) {
opts._debug(`${pName} failed: OOG`);
}
// TODO: should this really return OOG?
return OOGResult(opts.gasLimit);
}
if (opts._debug !== undefined) {
opts._debug(`${pName} return value=${bytesToHex(returnData)}`);
}
return {
executionGasUsed: gasUsed,
returnValue: returnData,
};
}
//# sourceMappingURL=08-bn254-pairing.js.map