How to use the ethereum-types.OpCode.SelfDestruct function in ethereum-types

To help you get started, we’ve selected a few ethereum-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / sol-tracing-utils / src / revert_trace.ts View on Github external
const nextStructLog = normalizedStructLogs[i + 1];
            if (nextStructLog.depth !== structLog.depth) {
                addressStack.push(newAddress);
                evmCallStack.push({
                    address: currentAddress,
                    structLog,
                });
            }
        } else if (utils.isEndOpcode(structLog.op) && structLog.op !== OpCode.Revert) {
            // Just like with calls, sometimes returns/stops don't change the execution context (current address).
            const nextStructLog = normalizedStructLogs[i + 1];
            if (_.isUndefined(nextStructLog) || nextStructLog.depth !== structLog.depth) {
                evmCallStack.pop();
                addressStack.pop();
            }
            if (structLog.op === OpCode.SelfDestruct) {
                // After contract execution, we look at all sub-calls to external contracts, and for each one, fetch
                // the bytecode and compute the coverage for the call. If the contract is destroyed with a call
                // to `selfdestruct`, we are unable to fetch it's bytecode and compute coverage.
                // TODO: Refactor this logic to fetch the sub-called contract bytecode before the selfdestruct is called
                // in order to handle this edge-case.
                logUtils.warn(
                    "Detected a selfdestruct. We currently do not support that scenario. We'll just skip the trace part for a destructed contract",
                );
            }
        } else if (structLog.op === OpCode.Revert) {
            evmCallStack.push({
                address: _.last(addressStack) as string,
                structLog,
            });
            return evmCallStack;
        } else if (structLog.op === OpCode.Create) {
github 0xProject / 0x-monorepo / packages / sol-tracing-utils / src / trace.ts View on Github external
// function. We manually check if the call depth had changed to handle that case.
            const nextStructLog = normalizedStructLogs[i + 1];
            if (nextStructLog.depth !== structLog.depth) {
                addressStack.push(newAddress);
                contractAddressToTraces[currentAddress] = (contractAddressToTraces[currentAddress] || []).concat(
                    currentTraceSegment,
                );
                currentTraceSegment = [];
            }
        } else if (utils.isEndOpcode(structLog.op)) {
            const currentAddress = addressStack.pop() as string;
            contractAddressToTraces[currentAddress] = (contractAddressToTraces[currentAddress] || []).concat(
                currentTraceSegment,
            );
            currentTraceSegment = [];
            if (structLog.op === OpCode.SelfDestruct) {
                // After contract execution, we look at all sub-calls to external contracts, and for each one, fetch
                // the bytecode and compute the coverage for the call. If the contract is destroyed with a call
                // to `selfdestruct`, we are unable to fetch it's bytecode and compute coverage.
                // TODO: Refactor this logic to fetch the sub-called contract bytecode before the selfdestruct is called
                // in order to handle this edge-case.
                logUtils.warn(
                    "Detected a selfdestruct. We currently do not support that scenario. We'll just skip the trace part for a destructed contract",
                );
            }
        } else if (structLog.op === OpCode.Create) {
            // TODO: Extract the new contract address from the stack and handle that scenario
            logUtils.warn(
                "Detected a contract created from within another contract. We currently do not support that scenario. We'll just skip that trace",
            );
            return contractAddressToTraces;
        } else {