UNPKG

@tokamak-zk-evm/synthesizer

Version:

Tokamak zk-EVM Synthesizer - Processes Ethereum transactions into wire maps for Tokamak zk-SNARK proof generation

39 lines 1.36 kB
import { bytesToHex, setLengthRight } from "@synthesizer-libs/util"; import { EvmErrorResult, OOGResult } from '../evm.js'; import { gasLimitCheck } from './util.js'; import { getPrecompileName } from './index.js'; export function precompile06(opts) { const pName = getPrecompileName('06'); const gasUsed = opts.common.param('bn254AddGas'); if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit); } // > 128 bytes: chop off extra bytes // < 128 bytes: right-pad with 0-s const input = setLengthRight(opts.data.subarray(0, 128), 128); let returnData; try { returnData = opts._EVM['_bn254'].add(input); } catch (e) { if (opts._debug !== undefined) { opts._debug(`${pName} failed: ${e.message}`); } return EvmErrorResult(e, opts.gasLimit); } // check ecadd success or failure by comparing the output length if (returnData.length !== 64) { if (opts._debug !== undefined) { opts._debug(`${pName} failed: OOG`); } return OOGResult(opts.gasLimit); } if (opts._debug !== undefined) { opts._debug(`${pName} return value=${bytesToHex(returnData)}`); } return { executionGasUsed: gasUsed, returnValue: returnData, }; } //# sourceMappingURL=06-bn254-add.js.map