-
Notifications
You must be signed in to change notification settings - Fork 20.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eth/tracers: re-write of 4byte tracer using enter/exit #23622
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2017 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 <http://www.gnu.org/licenses/>. | ||
|
||
// 4byteTracer 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: "4byteTracer"}) | ||
// { | ||
// 0x27dc297e-128: 1, | ||
// 0x38cc4831-0: 2, | ||
// 0x524f3889-96: 1, | ||
// 0xadf59f99-288: 1, | ||
// 0xc281d19e-0: 1 | ||
// } | ||
{ | ||
// ids aggregates the 4byte ids found. | ||
ids : {}, | ||
|
||
// callType returns 'false' for non-calls, or the peek-index for the first param | ||
// after 'value', i.e. meminstart. | ||
callType: function(opstr){ | ||
switch(opstr){ | ||
case "CALL": case "CALLCODE": | ||
// gas, addr, val, memin, meminsz, memout, memoutsz | ||
return 3; // stack ptr to memin | ||
|
||
case "DELEGATECALL": case "STATICCALL": | ||
// gas, addr, memin, meminsz, memout, memoutsz | ||
return 2; // stack ptr to memin | ||
} | ||
return false; | ||
}, | ||
|
||
// store save the given indentifier and datasize. | ||
store: function(id, size){ | ||
var key = "" + toHex(id) + "-" + size; | ||
this.ids[key] = this.ids[key] + 1 || 1; | ||
}, | ||
|
||
// step is invoked for every opcode that the VM executes. | ||
step: function(log, db) { | ||
// Skip any opcodes that are not internal calls | ||
var ct = this.callType(log.op.toString()); | ||
if (!ct) { | ||
return; | ||
} | ||
// Skip any pre-compile invocations, those are just fancy opcodes | ||
if (isPrecompiled(toAddress(log.stack.peek(1).toString(16)))) { | ||
return; | ||
} | ||
// Gather internal call details | ||
var inSz = log.stack.peek(ct + 1).valueOf(); | ||
if (inSz >= 4) { | ||
var inOff = log.stack.peek(ct).valueOf(); | ||
this.store(log.memory.slice(inOff, inOff + 4), inSz-4); | ||
} | ||
}, | ||
|
||
// fault is invoked when the actual execution of an opcode fails. | ||
fault: function(log, db) { }, | ||
|
||
// result is invoked when all the opcodes have been iterated over and returns | ||
// the final result of the tracing. | ||
result: function(ctx) { | ||
// Save the outer calldata also | ||
if (ctx.input.length >= 4) { | ||
this.store(slice(ctx.input, 0, 4), ctx.input.length-4) | ||
} | ||
return this.ids; | ||
}, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we even enter on precompiles?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so