github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/state/runtime/instrumentation/js/internal/tracers/4byte_tracer_legacy.js (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 // 4byteTracer searches for 4byte-identifiers, and collects them for post-processing. 18 // It collects the methods identifiers along with the size of the supplied data, so 19 // a reversed signature can be matched against the size of the data. 20 // 21 // Example: 22 // > debug.traceTransaction( "0x214e597e35da083692f5386141e69f47e973b2c56e7a8073b1ea08fd7571e9de", {tracer: "4byteTracer"}) 23 // { 24 // 0x27dc297e-128: 1, 25 // 0x38cc4831-0: 2, 26 // 0x524f3889-96: 1, 27 // 0xadf59f99-288: 1, 28 // 0xc281d19e-0: 1 29 // } 30 { 31 // ids aggregates the 4byte ids found. 32 ids : {}, 33 34 // callType returns 'false' for non-calls, or the peek-index for the first param 35 // after 'value', i.e. meminstart. 36 callType: function(opstr){ 37 switch(opstr){ 38 case "CALL": case "CALLCODE": 39 // gas, addr, val, memin, meminsz, memout, memoutsz 40 return 3; // stack ptr to memin 41 42 case "DELEGATECALL": case "STATICCALL": 43 // gas, addr, memin, meminsz, memout, memoutsz 44 return 2; // stack ptr to memin 45 } 46 return false; 47 }, 48 49 // store save the given indentifier and datasize. 50 store: function(id, size){ 51 var key = "" + toHex(id) + "-" + size; 52 this.ids[key] = this.ids[key] + 1 || 1; 53 }, 54 55 // step is invoked for every opcode that the VM executes. 56 step: function(log, db) { 57 // Skip any opcodes that are not internal calls 58 var ct = this.callType(log.op.toString()); 59 if (!ct) { 60 return; 61 } 62 // Skip any pre-compile invocations, those are just fancy opcodes 63 if (isPrecompiled(toAddress(log.stack.peek(1).toString(16)))) { 64 return; 65 } 66 // Gather internal call details 67 var inSz = log.stack.peek(ct + 1).valueOf(); 68 if (inSz >= 4) { 69 var inOff = log.stack.peek(ct).valueOf(); 70 this.store(log.memory.slice(inOff, inOff + 4), inSz-4); 71 } 72 }, 73 74 // fault is invoked when the actual execution of an opcode fails. 75 fault: function(log, db) { }, 76 77 // result is invoked when all the opcodes have been iterated over and returns 78 // the final result of the tracing. 79 result: function(ctx) { 80 // Save the outer calldata also 81 if (ctx.input.length >= 4) { 82 this.store(slice(ctx.input, 0, 4), ctx.input.length-4) 83 } 84 return this.ids; 85 }, 86 }