Commit graph

42 commits

Author SHA1 Message Date
Daniel Liu
cfca45a7eb
refactor(all): rework EVM constructor #30745 (#2065) 2026-02-17 14:35:18 +05:30
Daniel Liu
d7a42cb038
refactor(core): clean up EVM environmental structure #31061 (#1985) 2026-02-10 16:40:54 +05:30
Daniel Liu
d74c23cca1
perf(core): use uint256 in state #28598 (#1977) 2026-02-05 13:59:23 +05:30
Daniel Liu
4c098ddf1f
core/vm: fold EVMInterpreter into EVM #32352 (#1838) 2025-12-04 10:31:40 +05:30
Daniel Liu
af69d382ff
eth/tracers: various fixes #30540 (#1491)
Breaking changes:

- The ChainConfig was exposed to tracers via VMContext passed in
`OnTxStart`. This is unnecessary specially looking through the lens of
live tracers as chain config remains the same throughout the lifetime of
the program. It was there so that native API-invoked tracers could
access it. So instead we moved it to the constructor of API tracers.

Non-breaking:

- Change the default config of the tracers to be `{}` instead of nil.
This way an extra nil check can be avoided.

Refactoring:

- Rename `supply` struct to `supplyTracer`.
- Un-export some hook definitions.

Co-authored-by: Sina M <1591639+s1na@users.noreply.github.com>
2025-09-17 09:04:38 +08:00
Daniel Liu
2b906f22f1
eth/tracers/js: avoid compiling js bigint when not needed #30640 (#1497)
While looking at some mem profiles from `evm` runs, I noticed that
`goja` compilation of the bigint library was present. The bigint library
compilation happens in a package `init`, whenever the package
`eth/tracers/js` is loaded. This PR changes it to load lazily when
needed.

It becomes slightly faster with this change, and slightly less alloc:y.

Non-scientific benchmark with 100 executions:
```
time for i in {1..100}; do ./evm --code 6040 run; done;
 ```

current `master`:

```
real    0m6.634s
user    0m5.213s
sys     0m2.277s
```
Without compiling bigint
```
real    0m5.802s
user    0m4.191s
sys     0m1.965s
```

Co-authored-by: Martin HS <martin@swende.se>
2025-09-17 08:17:18 +08:00
Daniel Liu
f5e76ea6df
eth/tracers: avoid panic in state test runner #30332 (#1485)
Make tracers more robust by handling `nil` receipt as input.
Also pass in a receipt with gas used in the state test runner.
Closes https://github.com/ethereum/go-ethereum/issues/30117.

---------

Co-authored-by: Martin HS <martin@swende.se>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
2025-09-13 10:50:10 +08:00
Daniel Liu
1597be6879
eth/tracers/js: add coinbase addr to ctx #30231 (#1484)
Add coinbase address to javascript tracer context.

This PR adds the `coinbase` address to `jsTracer.ctx`, allowing access
to the coinbase address (fee receipient) in custom JavaScript tracers.

Example usage:

```javascript
result: function(ctx) {
  return toAddress(ctx.coinbase);
}
```

This change enables custom tracers to access coinbase address,
previously unavailable, enhancing their capabilities to match built-in
tracers.

Co-authored-by: Dylan Vassallo <dylan.vassallo@hotmail.com>
2025-09-13 10:49:17 +08:00
Daniel Liu
b896f4dce1
eth/tracers: use slices.Contains #29461 (#1463)
Co-authored-by: Aaron Chen <aaronchen.lisp@gmail.com>
2025-09-13 10:18:06 +08:00
Daniel Liu
bb458d0eed
eth/tracers/js: consistent name for method receivers #29375 (#1461)
Co-authored-by: Brandon Liu <lzqcn2000@126.com>
2025-09-13 10:16:43 +08:00
Daniel Liu
6bd8df6b8f
eth/tracers: fix mismatched names in comments #29348 (#1458) 2025-09-13 10:07:28 +08:00
wit765
12eab8e785
all: rename ChainId to ChainID #16853 (#1456)
Co-authored-by: wit <wit765765346@gmail>
2025-09-09 22:54:34 +08:00
Daniel Liu
ad9003c41e
eth/tracers: live chain tracing with hooks #29189 (#1352)
Here we add a Go API for running tracing plugins within the main block import process.

As an advanced user of geth, you can now create a Go file in eth/tracers/live/, and within
that file register your custom tracer implementation. Then recompile geth and select your tracer
on the command line. Hooks defined in the tracer will run whenever a block is processed.

The hook system is defined in package core/tracing. It uses a struct with callbacks, instead of
requiring an interface, for several reasons:

- We plan to keep this API stable long-term. The core/tracing hook API does not depend on
  on deep geth internals.
- There are a lot of hooks, and tracers will only need some of them. Using a struct allows you
   to implement only the hooks you want to actually use.

All existing tracers in eth/tracers/native have been rewritten to use the new hook system.

This change breaks compatibility with the vm.EVMLogger interface that we used to have.
If you are a user of vm.EVMLogger, please migrate to core/tracing, and sorry for breaking
your stuff. But we just couldn't have both the old and new tracing APIs coexist in the EVM.

---------

Co-authored-by: Sina M <1591639+s1na@users.noreply.github.com>
Co-authored-by: Matthieu Vachon <matthieu.o.vachon@gmail.com>
Co-authored-by: Delweng <delweng@gmail.com>
Co-authored-by: Martin HS <martin@swende.se>
2025-09-09 17:30:56 +08:00
Daniel Liu
693b248d0d
eth/tracers: fix typos in comments #28881 (#1346) 2025-09-09 16:16:26 +08:00
Daniel Liu
fe337141c1
eth/tracers/js: fix type inconsistencies #28488 (#1343)
This change fixes two type-inconsistencies in the JS tracer:

- In most places we return byte arrays as a `Uint8Array` to the tracer. However it seems we missed doing the conversion for `ctx` fields which are passed to the tracer during `result`. They are passed as simple arrays. I think Uint8Arrays are more suitable and we should change this inconsistency. Note: this will be a breaking-change. But I believe the effect is small. If we look at our tracers we see that these fields (`ctx.from`, `ctx.to`, etc.) are used in 2 ways. Passed to `toHex` which takes both array or buffer. Or the length was measured which is the same for both types.
- The `slice` taking in `int, int` params versus `memory.slice` taking `int64, int64` params. I suggest changing `slice` types to `int64`. This should have no effect almost in any case.

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
2025-09-09 15:52:57 +08:00
Daniel Liu
242ea9e0e9
eth/tracers/js: use t.toBig on ctx.GasPrice for js tracing #27903 (#1341)
This change fixes a bug in js tracer, where `ctx.GasPrice.toString(16)` returns a number string in base `10`.

Co-authored-by: Joe Netti <joe@netti.dev>
2025-09-09 15:40:17 +08:00
Daniel Liu
525a84eae4
eth/tracers: refactor exporting js buffer #27472 (#1336) 2025-09-09 15:05:47 +08:00
Daniel Liu
a5eab7eddb
eth/tracers: replace noarg fmt.Errorf with errors.New #27330 (#1335) 2025-09-09 14:59:01 +08:00
Daniel Liu
9fd13e5e4a
eth/tracers: report correct gasLimit in call tracers #27029 (#1325)
This includes a semantic change to the `callTracer` as well as `flatCallTracer`.
The value of field `gas` in the **first** call frame will change as follows:

- It previously contained gas available after initial deductions (i.e. tx costs)
- It will now contain the full tx gasLimit value

Signed-off-by: jsvisa <delweng@gmail.com>
Co-authored-by: Delweng <delweng@gmail.com>
2025-09-09 11:56:50 +08:00
Daniel Liu
98e9dc6c95
eth/tracers/native: prevent panic for LOG edge-cases #26848 (#1324)
This PR fixes OOM panic in the callTracer as well as panicing on
opcode validation errors (e.g. stack underflow) in callTracer and
prestateTracer.

Co-authored-by: jwasinger <j-wasinger@hotmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
2025-09-09 11:40:55 +08:00
Daniel Liu
0061de6b0a
eth/tracers: use non-threaded tracechain #24283 (#1315)
This makes non-JS tracers execute all block txs on a single goroutine.
In the previous implementation, we used to prepare every tx pre-state
on one goroutine, and then run the transactions again with tracing enabled.
Native tracers are usually faster, so it is faster overall to use their output as
the pre-state for tracing the next transaction.

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
2025-09-09 10:25:37 +08:00
Daniel Liu
7d4d81f586
eth/tracers, core/vm: remove time from trace output and tracing interface #26291 (#1311)
This removes the 'time' field from logs, as well as from the tracer interface. This change makes the trace output deterministic.  If a tracer needs the time they can measure it themselves. No need for evm to do this.

Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
2025-09-09 09:26:10 +08:00
Daniel Liu
06f50c7226
eth/tracers: fix gasUsed for native and JS tracers #26048 (#1305)
* eth/tracers: fix gasUsed in call tracer

* fix js tracers gasUsed

* fix legacy prestate tracer

* fix restGas in test

* drop intrinsicGas field from js tracers

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
2025-09-09 07:57:17 +08:00
Daniel Liu
25caabb77a
eth/tracers: simplify test framework #25973 (#1304)
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
2025-09-09 07:46:56 +08:00
Daniel Liu
9d8bec712d
eth/tracers: remove revertReasonTracer, add revert reason to callTracer #25508 (#1298)
* eth/tracers: add revertReason to callTracer

* update callframe gen json

* add revertal to calltrace test

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
2025-09-09 06:43:32 +08:00
Daniel Liu
b72c76eb30
eth/tracers: pad memory slice on OOB case #25213 (#1295)
* eth/tracers: pad memory slice on oob case

* eth/tracers/js: fix testfailure due to err msg capitalization

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
2025-09-09 06:38:10 +08:00
Daniel Liu
3b80bd0347
eth/tracers/js: improve integer types in log object #25668 (#1293)
All fields related to gas must be represented as uint64. Depth is
internally tracked as int, so it makes sense to also store it as int.

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-09-08 23:42:04 +08:00
Daniel Liu
a935810d4c
eth/tracers/js: fill in refund field #25661 (#1292) 2025-09-08 23:40:07 +08:00
Daniel Liu
67efb14ff3
eth/tracers: add onlyTopCall option to callTracer #25430 (#1291) 2025-09-08 23:38:19 +08:00
Daniel Liu
241ad1d635
eth/tracers: optimize goja buffer conversion #25156 (#1287)
This changes the []byte <-> Uint8Array conversion to use an
ArrayBuffer, avoiding inefficient copying of the slice data in Goja.

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-09-08 21:24:58 +08:00
Daniel Liu
1b561493fb
eth/tracers: fix typo and linter #25020 #24783 #25551 (#1286) 2025-09-08 21:15:42 +08:00
Daniel Liu
88d703180c
eth/tracers/js: drop duktape engine #24934 (#1283) 2025-09-08 21:11:27 +08:00
Daniel Liu
b27c8d23b2
eth/tracers/js: add memory.length method #24887 (#1284) 2025-09-08 21:08:16 +08:00
Daniel Liu
5226fa2cbf
eth/tracers/js: goja tracer #23773 (#1282) 2025-09-08 20:59:29 +08:00
Daniel Liu
ba2d72e8d8
eth/tracers: migrate go-bindata to embed #24744 (#1279) 2025-09-08 20:57:23 +08:00
Daniel Liu
0bc25c35b4
core,eth: implement tx-level hooks for tracers #24510 (#1277)
* core,eth: add empty tx logger hooks

* core,eth: add initial and remaining gas to tx hooks

* store tx gasLimit in js tracer

* use gasLimit to compute intrinsic cost for js tracer

* re-use rules in transitiondb

* rm logs

* rm logs

* Mv some fields from Start to TxStart

* simplify sender lookup in prestate tracer

* mv env to TxStart

* Revert "mv env to TxStart"

This reverts commit 656939634b9aff19f55a1cd167345faf8b1ec310.

* Revert "simplify sender lookup in prestate tracer"

This reverts commit ab65bce48007cab99e68232e7aac2fe008338d50.

* Revert "Mv some fields from Start to TxStart"

This reverts commit aa50d3d9b2559addc80df966111ef5fb5d0c1b6b.

* fix intrinsic gas for prestate tracer

* add comments

* refactor

* fix test case

* simplify consumedGas calc in prestate tracer

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
2025-09-08 17:53:21 +08:00
Daniel Liu
4f738d2191
eth/tracers: clean-up tracer collection #24320 (#1274) 2025-09-08 17:47:33 +08:00
Daniel Liu
0c293e5c34
eth/tracers: native prestate tracer #24268 (#1273) 2025-09-08 17:45:28 +08:00
Daniel Liu
060642e619
eth/tracers/js: add support for REVERT/SELFDESTRUCT in evmdis_tracer #24016 (#1271)
* eth/tracers: Add support for REVERT in evmdis_tracer

* evm/tracers: Fix evmdis_tracer to use SELFDESTRUCT instead of SUICIDE

* eth/tracers: Regenerate tracer library

Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
2025-09-08 17:28:59 +08:00
Daniel Liu
7d433a454a
eth/tracers: make native 4byte default, remove js version #23916 (#1268)
Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
2025-08-31 16:33:25 +08:00
Daniel Liu
1d1a88db5f
eth/tracers: add golang 4byte tracer #23882 (#1267)
* native 4byte tracer

* Update eth/tracers/native/4byte.go



* Update eth/tracers/native/4byte.go



* goimports

* eth/tracers: make 4byte tracer not care about create

Co-authored-by: Ward Bradt <wardbradt5@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
2025-08-31 16:05:54 +08:00
Daniel Liu
031ea75eca
eth/tracers: package restructuring #23857 (#1266) 2025-08-29 05:26:36 +08:00