Skip to content

Commit

Permalink
eth/tracers: native prestate tracer (ethereum#24268)
Browse files Browse the repository at this point in the history
* eth/tracers: add initial native prestate tracer

* fix balance hex

* handle prestate for tx from and to

* drop created contract from prestate

* fix sender balance

* use switch instead

Co-authored-by: Martin Holst Swende <martin@swende.se>

* minor fix

* lookup create2 account

* mv code around a bit

* check stackLen for create2

* fix transfer tx for js prestate tracer

* fix create2 addr

* track extcodehash in js prestate tracer

Co-authored-by: Martin Holst Swende <martin@swende.se>
  • Loading branch information
s1na and holiman authored Jan 31, 2022
1 parent 0c1bd22 commit cac09a3
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 6 deletions.
6 changes: 3 additions & 3 deletions eth/tracers/js/internal/tracers/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion eth/tracers/js/internal/tracers/prestate_tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
// result is invoked when all the opcodes have been iterated over and returns
// the final result of the tracing.
result: function(ctx, db) {
if (this.prestate === null) {
this.prestate = {};
// If tx is transfer-only, the recipient account
// hasn't been populated.
this.lookupAccount(ctx.to, db);
}

// At this point, we need to deduct the 'value' from the
// outer transaction, and move it back to the origin
this.lookupAccount(ctx.from, db);
Expand Down Expand Up @@ -79,7 +86,7 @@
}
// Whenever new state is accessed, add it to the prestate
switch (log.op.toString()) {
case "EXTCODECOPY": case "EXTCODESIZE": case "BALANCE":
case "EXTCODECOPY": case "EXTCODESIZE": case "EXTCODEHASH": case "BALANCE":
this.lookupAccount(toAddress(log.stack.peek(0).toString(16)), db);
break;
case "CREATE":
Expand Down
3 changes: 1 addition & 2 deletions eth/tracers/native/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ type callTracer struct {
func newCallTracer() tracers.Tracer {
// First callframe contains tx context info
// and is populated on start and end.
t := &callTracer{callstack: make([]callFrame, 1)}
return t
return &callTracer{callstack: make([]callFrame, 1)}
}

// CaptureStart implements the EVMLogger interface to initialize the tracing operation.
Expand Down
Loading

0 comments on commit cac09a3

Please sign in to comment.