@ethereumjs/evm
Version:
JavaScript Ethereum Virtual Machine (EVM) implementation
24 lines • 905 B
JavaScript
import { bytesToHex } from '@ethereumjs/util';
import { sha256 } from '@noble/hashes/sha2.js';
import { OOGResult } from "../evm.js";
import { getPrecompileName } from "./index.js";
import { gasLimitCheck } from "./util.js";
export function precompile02(opts) {
const pName = getPrecompileName('02');
const data = opts.data;
const sha256Function = opts.common.customCrypto.sha256 ?? sha256;
let gasUsed = opts.common.param('sha256Gas');
gasUsed += opts.common.param('sha256WordGas') * BigInt(Math.ceil(data.length / 32));
if (!gasLimitCheck(opts, gasUsed, pName)) {
return OOGResult(opts.gasLimit);
}
const hash = sha256Function(data);
if (opts._debug !== undefined) {
opts._debug(`${pName} return hash=${bytesToHex(hash)}`);
}
return {
executionGasUsed: gasUsed,
returnValue: hash,
};
}
//# sourceMappingURL=02-sha256.js.map