diff --git a/eth/tracers/js/internal/tracers/4byte_tracer.js b/eth/tracers/js/internal/tracers/4byte_tracer.js index 9ec3209f8b184..07dde6c321192 100644 --- a/eth/tracers/js/internal/tracers/4byte_tracer.js +++ b/eth/tracers/js/internal/tracers/4byte_tracer.js @@ -37,11 +37,16 @@ this.ids[key] = this.ids[key] + 1 || 1; }, - enter: function(frame) { + enter: function(frame, log) { // Skip any pre-compile invocations, those are just fancy opcodes if (isPrecompiled(frame.getTo())) { return; } + var type = frame.getType() + if (type !== "CALL" && type !== "STATICCALL" && + type !== "DELEGATECALL" && type !== "CALLCODE"){ + return; + } var input = frame.getInput() if (input.length >= 4) { this.store(slice(input, 0, 4), input.length - 4); diff --git a/eth/tracers/js/internal/tracers/assets.go b/eth/tracers/js/internal/tracers/assets.go index 37e3702400e1b..9e9cf55b5fa60 100644 --- a/eth/tracers/js/internal/tracers/assets.go +++ b/eth/tracers/js/internal/tracers/assets.go @@ -1,6 +1,6 @@ // Code generated by go-bindata. DO NOT EDIT. // sources: -// 4byte_tracer.js (2.224kB) +// 4byte_tracer.js (2.375kB) // 4byte_tracer_legacy.js (2.933kB) // bigram_tracer.js (1.712kB) // call_tracer_js.js (3.497kB) @@ -79,7 +79,7 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } -var __4byte_tracerJs = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x55\x5b\x6f\x22\x39\x13\x7d\x86\x5f\x71\xc4\x13\x68\x9a\x4b\x73\x09\x97\xf9\x32\x12\xdf\x28\x99\x41\xca\x66\x22\x42\x34\x8a\x56\xfb\x60\xda\xd5\xdd\xde\x18\xbb\x65\xbb\xb9\x6c\x26\xff\x7d\x65\x37\xe4\x36\xbb\xda\x79\x02\xec\xaa\x73\xaa\x4e\x1d\x17\xdd\x2e\x3e\xeb\xe2\x60\x44\x96\x3b\xf4\x7b\xf1\x18\xab\x9c\x90\xe9\x36\xb9\x9c\x0c\x95\x1b\xcc\x4b\x97\x6b\x63\xeb\xdd\x2e\x56\xb9\xb0\x48\x85\x24\x08\x8b\x82\x19\x07\x9d\xc2\xbd\x8b\x97\x62\x6d\x98\x39\x74\xea\xdd\x6e\x95\xf3\x8f\xd7\x1e\x21\x35\x44\xb0\x3a\x75\x3b\x66\x68\x86\x83\x2e\x91\x30\x05\x43\x5c\x58\x67\xc4\xba\x74\x04\xe1\xc0\x14\xef\x6a\x83\x8d\xe6\x22\x3d\x78\x48\xe1\x50\x2a\x4e\x26\x50\x3b\x32\x1b\x7b\xaa\xe3\xcb\xf5\x1d\xae\xc8\x5a\x32\xf8\x42\x8a\x0c\x93\xb8\x29\xd7\x52\x24\xb8\x12\x09\x29\x4b\x60\x16\x85\x3f\xb1\x39\x71\xac\x03\x9c\x4f\xbc\xf4\xa5\xdc\x1e\x4b\xc1\xa5\x2e\x15\x67\x4e\x68\x15\x81\x84\xaf\x1c\x5b\x32\x56\x68\x85\xc1\x89\xea\x08\x18\x41\x1b\x0f\xd2\x64\xce\x37\x60\xa0\x0b\x9f\xd7\x02\x53\x07\x48\xe6\x5e\x52\x7f\x41\x90\x97\xbe\x39\x84\x0a\x34\xb9\x2e\x08\x2e\x67\xce\x77\xbd\x13\x52\x62\x4d\x28\x2d\xa5\xa5\x8c\x3c\xda\xba\x74\xf8\xbe\x58\x7d\xfd\x76\xb7\xc2\xfc\xfa\x1e\xdf\xe7\xcb\xe5\xfc\x7a\x75\xff\x11\x3b\xe1\x72\x5d\x3a\xd0\x96\x2a\x28\xb1\x29\xa4\x20\x8e\x1d\x33\x86\x29\x77\x80\x4e\x3d\xc2\x6f\x17\xcb\xcf\x5f\xe7\xd7\xab\xf9\xff\x17\x57\x8b\xd5\x3d\xb4\xc1\xe5\x62\x75\x7d\x71\x7b\x8b\xcb\x6f\x4b\xcc\x71\x33\x5f\xae\x16\x9f\xef\xae\xe6\x4b\xdc\xdc\x2d\x6f\xbe\xdd\x5e\x74\x70\x4b\xbe\x2a\xf2\xf9\xff\xad\x79\x1a\xa6\x67\x08\x9c\x1c\x13\xd2\x9e\x94\xb8\xd7\x25\x6c\xae\x4b\xc9\x91\xb3\x2d\xc1\x50\x42\x62\x4b\x1c\x0c\x89\x2e\x0e\xbf\x3c\x54\x8f\xc5\xa4\x56\x59\xe8\xf9\x5f\x0d\x89\x45\x0a\xa5\x5d\x04\x4b\x84\xff\xe5\xce\x15\xb3\x6e\x77\xb7\xdb\x75\x32\x55\x76\xb4\xc9\xba\xb2\x82\xb3\xdd\x4f\x9d\xba\xc7\x1c\xae\x0f\x8e\x56\x86\x25\x64\x60\x89\x99\x24\x27\x1b\x9a\x09\x17\x6d\xc1\x49\x39\x91\x0a\x32\x36\xf2\x26\x45\xa2\xa5\xa4\xc4\x59\x5f\xc1\x26\x04\x16\xda\xba\x76\x61\x74\x42\xd6\x0a\x95\xf9\xc6\xb1\x70\x6f\x02\xb1\x21\x97\x6b\x6e\xf1\x0a\xee\x7d\x37\x56\xfc\x45\x27\x35\x6c\x59\x54\x63\xe4\xcc\xb1\x08\x56\x87\xee\x61\xc8\xdb\x8c\x38\xac\xc8\x14\x73\xa5\xa1\xf0\x96\xd6\x84\x0d\x73\x89\x37\x3b\xcb\x98\x50\xd6\xfd\x04\xe8\x71\x4e\x13\xb9\xd8\xb3\x4d\x21\x69\xe6\xbf\x03\x9f\xc0\x69\x5d\x66\x1d\xe7\x25\x58\x19\xa6\x2c\x4b\xbc\xb9\x9b\x68\xf4\xf6\xfd\x78\x48\xa3\xe9\x98\x06\x23\xce\x7a\x93\xc1\xd9\xb4\x9f\x8e\x06\x93\xb3\x78\x18\xd3\xd9\x34\x1d\x8e\x69\x3a\x1e\xac\xfb\xc9\xe8\x8c\xc6\x6c\xd2\x1b\x0f\xd6\x31\xb1\xde\x24\xe5\xe3\xd1\x38\xa6\x29\xa7\x46\x84\xc7\x00\x6c\x66\x68\xbc\x52\xba\xf1\xd4\xaa\xd8\x1f\xab\x0f\xa0\xb7\xef\x8f\x79\xd2\x9f\x8e\xa9\x1d\xf7\x27\x33\xc4\xd1\xcb\xcd\x60\x92\x24\xc3\xc9\x20\x6e\xf7\x66\xe8\xbf\x3a\x1f\xf5\x87\xe9\x60\x32\x99\xb6\xa7\x67\x6f\x13\x18\x4f\x47\xd3\x74\x3a\x6d\xf7\x27\xef\xa0\x92\xfe\x24\xe6\xf1\x94\x3c\x54\x5c\x1d\x3f\xd5\x1f\xeb\x35\xbf\x70\xb8\x05\xcb\x32\x43\x19\x73\x54\x4d\x2d\x54\x1c\x2e\x52\xbf\x2c\x3a\xf5\x9a\xff\x3e\xc3\xe3\x53\x54\x0f\x39\xd6\x79\xc7\x5b\xef\xeb\x60\x48\xe1\x9f\xa1\x50\xcf\x43\x0e\x8e\xf1\xda\xfb\x59\x74\xea\xb5\x10\x3f\x43\x5a\xaa\x4a\x63\xc1\xa3\x30\xa6\xd6\x63\xbd\x56\xdb\x32\x83\x07\x3a\xe0\x1c\x8d\x06\x3e\xc0\xe9\xaf\xb4\x6f\x0a\xde\xc2\x07\x34\xda\xfe\xc4\x47\x7e\xac\xd7\x6a\x2e\x17\xb6\x23\xb8\xfd\xfd\x81\x0e\x7f\xe0\x1c\x6f\x7f\x7f\x40\x8c\x1f\x3f\x10\x7f\xac\xd7\x42\x99\xa4\x9c\x97\xff\x99\x33\x35\x6c\x43\x2d\x78\xc6\x6e\x17\xb7\x0f\xa2\x08\x6b\xac\x30\xd4\x4e\xf4\xa6\x08\x8b\x5f\x6d\x75\x12\x56\xa3\x8d\xe0\x72\xed\x57\xaa\x21\xfc\x59\x5a\x87\x94\xa9\xe4\x00\x5d\x24\x9a\x93\xad\xd7\x6a\x22\x45\x53\xd8\x1b\x43\xc7\x64\x5e\x11\x74\x32\x72\x2b\xdd\x6c\xb5\x2a\xa6\x9a\x21\x57\x1a\xe5\xab\x7f\x3a\xb6\x2a\x54\x51\x3a\x9c\xe3\x39\x7c\xe1\x0f\x9a\xad\x13\xa6\xff\xd5\x91\xa4\x32\x97\xe3\xd3\x39\x86\x47\xa0\xd0\x6c\xd0\xb1\x69\xfd\x5b\xae\x02\x23\xf4\x22\x0c\x5b\x11\xde\xa4\xb5\x31\x6c\x1d\x29\x2b\x29\xf6\xc2\xbd\x57\x62\x49\xb6\x94\xae\xf5\x32\xd3\x94\x95\xd2\xf9\x45\xed\x55\x78\xf0\xab\x34\x3f\xee\x56\x96\xb8\x92\x49\xd0\x9e\x92\xd2\x03\xf8\xc7\xc5\xd4\x51\x0b\xa4\xd5\xd6\xab\x85\xfc\x57\x2c\x52\x67\x11\xf8\xfa\x15\x83\x09\x94\x3f\x51\x30\x29\x03\xcd\x51\xdb\x6a\x5d\xae\xc9\x3b\xca\x91\x61\xfe\xff\x42\x6f\x8f\x9e\xaa\xe4\xb4\x01\xce\xe7\xa4\x42\x31\x79\x02\x3e\xbe\x79\xff\xf0\xc2\x3e\xaa\x55\xe7\xaf\x6a\x4a\xdc\xfe\xc5\x01\x27\xf7\xea\xd2\xff\x91\x25\x4c\x4a\xef\x58\x30\x69\xf5\x71\x16\x89\xdb\x77\x7e\x79\x1e\xcf\xc1\xcf\x33\x79\x9f\xde\x1e\xb6\x8e\x3e\xa8\xda\x78\x36\x70\x65\xd9\xa7\xfa\xdf\x01\x00\x00\xff\xff\xf6\xa8\xa1\xb9\xb0\x08\x00\x00") +var __4byte_tracerJs = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x55\x5b\x4f\xdb\x48\x14\x7e\x4e\x7e\xc5\xb7\x79\xa8\x88\xea\xdc\x03\xb9\x74\xa9\x94\xa5\xa1\x8d\xc4\x02\x0a\x46\x15\x5a\xed\xc3\xc4\x73\x6c\xcf\xe2\xcc\x58\x33\x63\x48\x96\xf2\xdf\x57\x33\x76\x48\xa0\xad\xb6\x4f\x84\x73\xf9\xce\xe5\x3b\xf3\xb9\xd3\xc1\x99\xca\xb7\x5a\x24\xa9\x45\xbf\xdb\x1b\x21\x4c\x09\x89\x6a\x91\x4d\x49\x53\xb1\xc6\xac\xb0\xa9\xd2\xa6\xde\xe9\x20\x4c\x85\x41\x2c\x32\x82\x30\xc8\x99\xb6\x50\x31\xec\x9b\xf8\x4c\xac\x34\xd3\xdb\x76\xbd\xd3\x29\x73\x7e\xe8\x76\x08\xb1\x26\x82\x51\xb1\x7d\x64\x9a\xa6\xd8\xaa\x02\x11\x93\xd0\xc4\x85\xb1\x5a\xac\x0a\x4b\x10\x16\x4c\xf2\x8e\xd2\x58\x2b\x2e\xe2\xad\x83\x14\x16\x85\xe4\xa4\x7d\x69\x4b\x7a\x6d\x76\x7d\x7c\xbe\xbc\xc5\x05\x19\x43\x1a\x9f\x49\x92\x66\x19\xae\x8b\x55\x26\x22\x5c\x88\x88\xa4\x21\x30\x83\xdc\x59\x4c\x4a\x1c\x2b\x0f\xe7\x12\xcf\x5d\x2b\x37\x55\x2b\x38\x57\x85\xe4\xcc\x0a\x25\x03\x90\x70\x9d\xe3\x81\xb4\x11\x4a\x62\xb0\x2b\x55\x01\x06\x50\xda\x81\x1c\x31\xeb\x06\xd0\x50\xb9\xcb\x6b\x82\xc9\x2d\x32\x66\xf7\xa9\xbf\xb0\x90\xfd\xdc\x1c\x42\xfa\x32\xa9\xca\x09\x36\x65\xd6\x4d\xfd\x28\xb2\x0c\x2b\x42\x61\x28\x2e\xb2\xc0\xa1\xad\x0a\x8b\xaf\x8b\xf0\xcb\xd5\x6d\x88\xd9\xe5\x1d\xbe\xce\x96\xcb\xd9\x65\x78\xf7\x01\x8f\xc2\xa6\xaa\xb0\xa0\x07\x2a\xa1\xc4\x3a\xcf\x04\x71\x3c\x32\xad\x99\xb4\x5b\xa8\xd8\x21\xfc\x39\x5f\x9e\x7d\x99\x5d\x86\xb3\x3f\x16\x17\x8b\xf0\x0e\x4a\xe3\x7c\x11\x5e\xce\x6f\x6e\x70\x7e\xb5\xc4\x0c\xd7\xb3\x65\xb8\x38\xbb\xbd\x98\x2d\x71\x7d\xbb\xbc\xbe\xba\x99\xb7\x71\x43\xae\x2b\x72\xf9\xff\xbf\xf3\xd8\xb3\xa7\x09\x9c\x2c\x13\x99\xd9\x6d\xe2\x4e\x15\x30\xa9\x2a\x32\x8e\x94\x3d\x10\x34\x45\x24\x1e\x88\x83\x21\x52\xf9\xf6\x97\x49\x75\x58\x2c\x53\x32\xf1\x33\xff\xf4\x20\xb1\x88\x21\x95\x0d\x60\x88\xf0\x7b\x6a\x6d\x3e\xed\x74\x1e\x1f\x1f\xdb\x89\x2c\xda\x4a\x27\x9d\xac\x84\x33\x9d\x8f\xed\xba\xc3\x1c\xae\xb6\x96\x42\xcd\x22\xd2\x30\xc4\x74\x94\x92\xf1\xc3\x78\x47\x4b\x70\x92\x56\xc4\x82\xb4\x09\xdc\x91\x22\x52\x59\x46\x91\x35\xae\x83\xb5\x0f\xcc\x95\xb1\xad\x5c\xab\x88\x8c\x11\x32\x71\x83\x63\x61\x5f\x05\x62\x4d\x36\x55\xdc\xe0\x00\xee\xed\x34\x46\xfc\x4b\xbb\x6d\x98\x22\x2f\x69\xe4\xcc\xb2\x00\x46\xf9\xe9\xa1\xc9\x9d\x19\x71\x18\x91\x48\x66\x0b\x4d\xfe\x2d\xad\x08\x6b\x66\x23\x77\xec\x2c\x61\x42\x1a\xfb\x1d\xa0\xc3\xd9\x31\x32\xdf\xb0\x75\x9e\xd1\xd4\xfd\x06\x3e\x82\xd3\xaa\x48\xda\xd6\xad\x20\xd4\x4c\x1a\x16\xb9\xe3\x3e\x42\xa3\xbb\xe9\xf7\x86\x74\x3c\x19\xd1\xe0\x98\xb3\xee\x78\x70\x32\xe9\xc7\xc7\x83\xf1\x49\x6f\xd8\xa3\x93\x49\x3c\x1c\xd1\x64\x34\x58\xf5\xa3\xe3\x13\x1a\xb1\x71\x77\x34\x58\xf5\x88\x75\xc7\x31\x1f\x1d\x8f\x7a\x34\xe1\xd4\x08\xf0\xe4\x81\xf5\x14\x8d\x83\x4d\x37\x9e\x9b\x65\xf5\xa7\xf2\x0f\xd0\xdd\xf4\x47\x3c\xea\x4f\x46\xd4\xea\xf5\xc7\x53\xf4\x82\xbd\x67\x30\x8e\xa2\xe1\x78\xd0\x6b\x75\xa7\xe8\x1f\xd8\x8f\xfb\xc3\x78\x30\x1e\x4f\x5a\x93\x93\xd7\x09\x8c\xc7\xc7\x93\x78\x32\x69\xf5\xc7\x6f\xa0\xa2\xfe\xb8\xc7\x7b\x13\x72\x50\xbd\xd2\xfc\x5c\x7f\xaa\xd7\x9c\xe0\x70\x03\x96\x24\x9a\x12\x66\xa9\x64\xcd\x77\xec\x1d\xb1\x13\x8b\x76\xbd\xe6\x7e\x4f\xf1\xf4\x1c\xd4\x7d\x8e\xb1\xee\xe2\x8d\xbb\x6b\x7f\x90\xc2\x3d\x43\x21\x5f\x48\xf6\x17\xe3\x76\xef\xb8\x68\xd7\x6b\x3e\x7e\x8a\xb8\x90\xe5\x8e\x05\x0f\x3c\x4d\xcd\xa7\x7a\xad\xf6\xc0\x34\xee\x69\x8b\x53\x34\x1a\x78\x0f\xab\xbe\xd0\xe6\x48\xf0\x26\xde\xa3\xd1\x72\x16\x17\xf9\xa1\x5e\xab\xd9\x54\x98\xb6\xe0\xe6\xaf\x7b\xda\xfe\x8d\x53\xbc\xfe\xff\x3d\x7a\xf8\xf6\x0d\xbd\x0f\xf5\x9a\x6f\x93\xa4\x75\xeb\x7f\xa9\x19\x6b\xb6\xa6\x00\x99\x4a\x9a\x70\x65\x3b\x1d\xdc\xdc\x8b\xdc\x6b\x59\xae\xa9\x15\xa9\x75\xee\xd5\x5f\x3e\xa8\xc8\xeb\xa3\x09\x60\x53\xe5\x74\x55\x13\xfe\x29\x8c\x45\xcc\x64\xb4\x85\xca\x23\xc5\xc9\xd4\x6b\x35\x11\xe3\x48\x98\x6b\x4d\x55\x32\x2f\xab\xb4\x13\xb2\xa1\x3a\x6a\x36\xcb\x4a\x35\x4d\xb6\xd0\xd2\x8d\xf0\x5c\xcd\x6b\xb7\x39\xe1\x14\xfb\xe8\x6d\x4e\x47\xcd\x0a\xd1\x3b\x7f\x3b\x3d\x45\xe3\x6c\x76\x71\xd1\xc0\xbb\x77\xd8\x9b\x6e\xc2\x59\xb8\x38\xdb\x39\x1c\xfa\xde\xf7\x69\x7e\x31\xff\x3c\x0b\xe7\x3f\x48\x73\xa6\xb3\xab\x4f\xf3\x46\xf3\x27\x1d\x09\x99\x17\xf6\xb0\xa5\x85\x33\xbc\xf4\xe4\xdd\xed\x8c\x64\x62\x53\x7c\x3c\xc5\xb0\x1a\xcd\x73\xe0\xe9\x3d\x32\x4e\x62\xca\xc0\x00\xdd\x00\xc3\x66\x80\x57\x69\x2d\x0c\x9b\x55\xc9\x92\xa1\x8d\xb0\x6f\x09\x5a\x92\x29\x32\xdb\xdc\x9f\x5a\xcc\x8a\xcc\xba\xef\x87\xe3\xe5\xde\x29\x7c\x5a\x49\x3e\x8b\x6c\xc1\x32\xd0\x86\xa2\xc2\x01\xb8\x37\xcf\x64\xc5\x0e\xe2\x52\x8c\x6b\x3e\xff\xa0\x4a\xa6\x92\x00\x7c\x75\x50\x41\xfb\x92\xdf\x95\x60\x59\xe6\xcb\x54\x6c\x97\x2a\xbe\x22\x77\xe8\x96\x34\x73\x9f\x31\xf5\x50\x9d\x7a\xb9\x4e\xe3\xe1\x5c\x4e\x2c\x24\xcb\x76\xc0\x95\x14\x39\x3d\xf0\x32\x59\x2b\xed\x07\x3d\x45\x76\xb3\xbf\xc9\xdd\xa3\x52\x85\xfb\xbe\x46\x2c\xcb\xdc\x43\x02\xcb\x8c\xaa\xb8\x88\xec\xa6\xfd\xcb\x7c\xbc\x04\xbf\x70\xf2\x36\xbd\x35\x6c\x56\x77\x50\x8e\xf1\xf2\xae\xca\x97\xf4\x5c\xff\x2f\x00\x00\xff\xff\x6e\x82\xd6\x8b\x47\x09\x00\x00") func _4byte_tracerJsBytes() ([]byte, error) { return bindataRead( @@ -95,7 +95,7 @@ func _4byte_tracerJs() (*asset, error) { } info := bindataFileInfo{name: "4byte_tracer.js", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x6b, 0xa8, 0x46, 0xa2, 0x3a, 0x2b, 0xaa, 0xb9, 0xb9, 0xba, 0xe2, 0x22, 0x10, 0xe, 0xe7, 0x4c, 0x24, 0xfc, 0x4c, 0x85, 0xeb, 0x96, 0x48, 0xe8, 0x7f, 0xc8, 0xe0, 0xd0, 0xd, 0x26, 0xa1, 0xb2}} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xdb, 0xff, 0x9f, 0xb0, 0x9e, 0x1a, 0xd7, 0xd3, 0xcb, 0xf6, 0x6e, 0xf5, 0xf7, 0xbc, 0xe7, 0xbc, 0xd6, 0x7c, 0x37, 0x16, 0xd7, 0x4f, 0x85, 0xb3, 0x1f, 0xfd, 0x66, 0x3e, 0x91, 0xed, 0x86, 0x27}} return a, nil } diff --git a/eth/tracers/native/4byte.go b/eth/tracers/native/4byte.go new file mode 100644 index 0000000000000..082a60355d2fd --- /dev/null +++ b/eth/tracers/native/4byte.go @@ -0,0 +1,148 @@ +// Copyright 2021 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package native + +import ( + "encoding/json" + "math/big" + "strconv" + "sync/atomic" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/eth/tracers" +) + +func init() { + register("4byte", newFourByteTracer) +} + +// fourByteTracer searches for 4byte-identifiers, and collects them for post-processing. +// It collects the methods identifiers along with the size of the supplied data, so +// a reversed signature can be matched against the size of the data. +// +// Example: +// > debug.traceTransaction( "0x214e597e35da083692f5386141e69f47e973b2c56e7a8073b1ea08fd7571e9de", {tracer: "4byte"}) +// { +// 0x27dc297e-128: 1, +// 0x38cc4831-0: 2, +// 0x524f3889-96: 1, +// 0xadf59f99-288: 1, +// 0xc281d19e-0: 1 +// } +type fourByteTracer struct { + env *vm.EVM + ids map[string]int // ids aggregates the 4byte ids found + interrupt uint32 // Atomic flag to signal execution interruption + reason error // Textual reason for the interruption + activePrecompiles []common.Address // Updated on CaptureStart based on given rules +} + +// newFourByteTracer returns a native go tracer which collects +// 4 byte-identifiers of a tx, and implements vm.EVMLogger. +func newFourByteTracer() tracers.Tracer { + t := &fourByteTracer{ + ids: make(map[string]int), + } + return t +} + +// isPrecompiled returns whether the addr is a precompile. Logic borrowed from newJsTracer in eth/tracers/js/tracer.go +func (t *fourByteTracer) isPrecompiled(addr common.Address) bool { + for _, p := range t.activePrecompiles { + if p == addr { + return true + } + } + return false +} + +// store saves the given identifier and datasize. +func (t *fourByteTracer) store(id []byte, size int) { + key := bytesToHex(id) + "-" + strconv.Itoa(size) + t.ids[key] += 1 +} + +// CaptureStart implements the EVMLogger interface to initialize the tracing operation. +func (t *fourByteTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) { + t.env = env + + // Update list of precompiles based on current block + rules := env.ChainConfig().Rules(env.Context.BlockNumber) + t.activePrecompiles = vm.ActivePrecompiles(rules) + + // Save the outer calldata also + if len(input) >= 4 { + t.store(input[0:4], len(input)-4) + } +} + +// CaptureState implements the EVMLogger interface to trace a single step of VM execution. +func (t *fourByteTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) { +} + +// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct). +func (t *fourByteTracer) CaptureEnter(op vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) { + // Skip if tracing was interrupted + if atomic.LoadUint32(&t.interrupt) > 0 { + t.env.Cancel() + return + } + if len(input) < 4 { + return + } + // primarily we want to avoid CREATE/CREATE2/SELFDESTRUCT + if op != vm.DELEGATECALL && op != vm.STATICCALL && + op != vm.CALL && op != vm.CALLCODE { + return + } + // Skip any pre-compile invocations, those are just fancy opcodes + if t.isPrecompiled(to) { + return + } + t.store(input[0:4], len(input)-4) +} + +// CaptureExit is called when EVM exits a scope, even if the scope didn't +// execute any code. +func (t *fourByteTracer) CaptureExit(output []byte, gasUsed uint64, err error) { +} + +// CaptureFault implements the EVMLogger interface to trace an execution fault. +func (t *fourByteTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error) { +} + +// CaptureEnd is called after the call finishes to finalize the tracing. +func (t *fourByteTracer) CaptureEnd(output []byte, gasUsed uint64, _ time.Duration, err error) { +} + +// GetResult returns the json-encoded nested list of call traces, and any +// error arising from the encoding or forceful termination (via `Stop`). +func (t *fourByteTracer) GetResult() (json.RawMessage, error) { + res, err := json.Marshal(t.ids) + if err != nil { + return nil, err + } + return res, t.reason +} + +// Stop terminates execution of the tracer at the first opportune moment. +func (t *fourByteTracer) Stop(err error) { + t.reason = err + atomic.StoreUint32(&t.interrupt, 1) +}