Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
reportMemoryCost(traceInfo: TraceInfo): number {
const structLogs = traceInfo.trace.structLogs;
const MEMORY_OPCODES = [OpCode.MLoad, OpCode.MStore, OpCode.MStore8];
const CALL_DATA_OPCODES = [OpCode.CallDataCopy];
const memoryLogs = _.filter(structLogs, structLog =>
_.includes([...MEMORY_OPCODES, ...CALL_DATA_OPCODES], structLog.op),
);
const memoryLocationsAccessed = _.map(memoryLogs, structLog => {
if (_.includes(CALL_DATA_OPCODES, structLog.op)) {
const memoryOffsetStackOffset = constants.opCodeToParamToStackOffset[structLog.op as any].memoryOffset;
const lengthStackOffset = constants.opCodeToParamToStackOffset[structLog.op as any].length;
const memOffset = parseInt(
structLog.stack[structLog.stack.length - memoryOffsetStackOffset - 1],
HEX_BASE,
);
const length = parseInt(structLog.stack[structLog.stack.length - lengthStackOffset - 1], HEX_BASE);
return memOffset + length;
} else {
const memoryLocationStackOffset = constants.opCodeToParamToStackOffset[structLog.op].offset;
return parseInt(structLog.stack[structLog.stack.length - memoryLocationStackOffset - 1], HEX_BASE);