@ethereumjs/evm
Version:
JavaScript Ethereum Virtual Machine (EVM) implementation
27 lines • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.precompile02 = precompile02;
const util_1 = require("@ethereumjs/util");
const sha2_js_1 = require("@noble/hashes/sha2.js");
const evm_ts_1 = require("../evm.js");
const index_ts_1 = require("./index.js");
const util_ts_1 = require("./util.js");
function precompile02(opts) {
const pName = (0, index_ts_1.getPrecompileName)('02');
const data = opts.data;
const sha256Function = opts.common.customCrypto.sha256 ?? sha2_js_1.sha256;
let gasUsed = opts.common.param('sha256Gas');
gasUsed += opts.common.param('sha256WordGas') * BigInt(Math.ceil(data.length / 32));
if (!(0, util_ts_1.gasLimitCheck)(opts, gasUsed, pName)) {
return (0, evm_ts_1.OOGResult)(opts.gasLimit);
}
const hash = sha256Function(data);
if (opts._debug !== undefined) {
opts._debug(`${pName} return hash=${(0, util_1.bytesToHex)(hash)}`);
}
return {
executionGasUsed: gasUsed,
returnValue: hash,
};
}
//# sourceMappingURL=02-sha256.js.map