Commit Graph

555 Commits

Author SHA1 Message Date
Marius van der Wijden 6fe254e378 all: fix merging issues 2025-02-04 10:20:10 +01:00
Marius van der Wijden dbb4ef5d9f
Merge branch 'master' into eof-opcodes 2025-02-04 10:01:36 +01:00
jwasinger 55a18616b1
core/vm: simplify tracer hook invocation in interpreter loop (#31074)
Removes duplicate code in the interpreter loop.
2025-02-03 18:44:26 +01:00
Sina M a50cac5bbe
core/vm: EXTCODE* return delegation designator for 7702 (#31089)
Implements https://github.com/ethereum/EIPs/pull/9248
2025-01-30 09:08:42 -07:00
Guillaume Ballet 52766bedb9
core/{.,state,vm},miner,eth/tracers,tests: implement 7709 with a syscall flag (#31036)
Same as #31015 but requires the contract to exist. Not compatible with
any verkle testnet up to now.

This adds a `isSytemCall` flag so that it is possible to detect when a
system call is executed, so that the code execution and other locations
are not added to the witness.

---------

Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-01-29 14:31:25 +01:00
Christina 9516e0f6b6
chore: fix various comments (#31082) 2025-01-28 16:56:23 +01:00
Sina M 3003a13440
core/vm: implement EIP-2537 spec updates (#30978)
Reference:

- Remove MUL precompiles: https://github.com/ethereum/EIPs/pull/8945
- Pricing change for pairing operation:
https://github.com/ethereum/EIPs/pull/9098
- Pricing change for add, mapping and mul operations:
https://github.com/ethereum/EIPs/pull/9097
- Pricing change for MSM operations:
https://github.com/ethereum/EIPs/pull/9116

---------

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
2025-01-24 15:38:17 +01:00
Martin HS 2bf4a8ff73
cmd/evm: refactor handling output-files for `t8n` (#30854)
As part of trying to make the inputs and outputs of the evm subcommands
more streamlined and aligned, this PR modifies how `evm t8n` manages
output-files.

Previously, we do a kind of wonky thing where between each transaction,
we invoke a `getTracer` closure. In that closure, we create a new
output-file, a tracer, and then make the tracer stream output to the
file. We also fiddle a bit to ensure that the file becomes properly
closed.

It is a kind of hacky solution we have in place. This PR changes it, so
that from the execution-pipeline point of view, we have just a regular
tracer. No fiddling with re-setting it or closing files.

That particular tracer, however, is a bit special: it takes care of
creating new files per transaction (in the tx-start-hook) and closing
(on tx-end-hook). Also instantiating the right type of underlying
tracer, which can be a json-logger or a custom tracer.

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2025-01-21 15:35:03 +08:00
georgehao 1843f27766
all: fix some typos in comments and names (#31023) 2025-01-14 14:16:15 +01:00
Martin HS 5b9a3ea9d2
core/vm: make all opcodes proper type (#30925)
Noticed this omission while doing some work on goevmlab. We don't
properly type some of the opcodes, but apparently implicit casting works
in all the internal usecases.
2024-12-17 18:37:29 +01:00
Martin HS 5c58612e12
core/vm, go.mod: update uint256 and use faster method to write to memory (#30868)
Updates geth to use the latest uint256, and use faster memory-writer
2024-12-17 08:58:26 +01:00
lightclient f808d7357e
all: implement eip-7702 set code tx (#30078)
This PR implements EIP-7702: "Set EOA account code". 
Specification: https://eips.ethereum.org/EIPS/eip-7702

> Add a new transaction type that adds a list of `[chain_id, address,
nonce, y_parity, r, s]` authorization tuples. For each tuple, write a
delegation designator `(0xef0100 ++ address)` to the signing account’s
code. All code reading operations must load the code pointed to by the
designator.

---------

Co-authored-by: Mario Vega <marioevz@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
2024-12-16 11:29:37 +01:00
Zheyuan He 4ecf08584c
core/vm: remove unnecessary comment (#30887) 2024-12-10 13:10:17 +01:00
Martin HS f0e7382f38
cmd/evm, eth/tracers: refactor structlogger and make it streaming (#30806)
This PR refactors the structlog a bit, making it so that it can be used
in a streaming mode.

-------------

OBS: this PR makes a change in the input `config` config, the third
input-parem field to `debug.traceCall`. Previously, seteting it to e.g.
` {"enableMemory": true, "limit": 1024}` would mean that the response
was limited to `1024` items. Since an 'item' may include both memory and
storage, the actual size of the response was undertermined.
After this change, the response will be limited to `1024` __`bytes`__
(or thereabouts).



-----------


The commandline usage of structlog now uses the streaming mode, leaving
the non-streaming mode of operation for the eth_Call.

There are two benefits of streaming mode 
1. Not have to maintain a long list of operations, 
2. Not have to duplicate / n-plicate data, e.g. memory / stack /
returndata so that each entry has their own private slice.


---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2024-12-04 08:52:59 +01:00
rjl493456442 a793bc7f5f
core: switch EVM tx context in ApplyMessage (#30809)
This change relocates the EVM tx context switching to the ApplyMessage function.
With this change, we can remove a lot of EVM.SetTxContext calls before
message execution.

### Tracing API changes

- This PR replaces the `GasPrice` field of the `VMContext` struct with
  `BaseFee`. Users may instead take the effective gas price from
  `tx.EffectiveGasTipValue(env.BaseFee)`.

---------

Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
2024-11-29 15:39:42 +01:00
wangjingcun 16f2f7155f
all: typos in comments (#30779)
fixes some typos
2024-11-22 09:02:45 +01:00
rjl493456442 e3d61e6db0
core, eth, internal, cmd: rework EVM constructor (#30745)
This pull request refactors the EVM constructor by removing the
TxContext parameter.

The EVM object is frequently overused. Ideally, only a single EVM
instance should be created and reused throughout the entire state
transition of a block, with the transaction context switched as needed
by calling evm.SetTxContext.

Unfortunately, in some parts of the code, the EVM object is repeatedly
created, resulting in unnecessary complexity. This pull request is the
first step towards gradually improving and simplifying this setup.

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
2024-11-20 12:35:52 +01:00
Martin HS 6d3d252a5e
core/vm/program: evm bytecode-building utility (#30725)
In many cases, there is a need to create somewhat nontrivial bytecode. A
recent example is the verkle statetests, where we want a `CREATE2`- op
to create a contract, which can then be invoked, and when invoked does a
selfdestruct-to-self.

It is overkill to go full solidity, but it is also a bit tricky do
assemble this by concatenating bytes. This PR takes an approach that
has been used in in goevmlab for several years.

Using this utility, the case can be expressed as: 
```golang
	// Some runtime code
	runtime := program.New().Ops(vm.ADDRESS, vm.SELFDESTRUCT).Bytecode()
	// A constructor returning the runtime code
	initcode := program.New().ReturnData(runtime).Bytecode()
	// A factory invoking the constructor
	outer := program.New().Create2AndCall(initcode, nil).Bytecode()
```

We have a lot of places in the codebase where we concatenate bytes, cast
from `vm.OpCode` . By taking tihs approach instead, thos places can be made a
bit more maintainable/robust.
2024-11-20 08:40:21 +01:00
Martin HS 014e2b037f
core/vm/runtime: invoke tx-end hook (#30711)
When using the `core/vm/runtime` helpers to execute code, callbacks for the tx end were not invoked. This change fixes it by invoking them.
2024-11-04 11:39:06 +01:00
lightclient 9afb18dd6f
core: add code to witness when state object is accessed (#30698)
I think the core code should generally be agnostic about the witness and
the statedb layer should determine what elements need to be included in
the witness. Because code is accessed via `GetCode`, and
`GetCodeLength`, the statedb will always know when it needs to add that
code into the witness.

The edge case is block hashes, so we continue to add them manually in
the implementation of `BLOCKHASH`.

It probably makes sense to refactor statedb so we have a wrapped
implementation that accumulates the witness, but this is a simpler
change that makes #30078 less aggressive.
2024-10-31 12:19:01 +02:00
Martin HS 25bc07749c
core/vm: speed up push and interpreter loop (#30662)
Looking at the cpu profile of a burntpix benchmark, I noticed that a lot
of time was spent in gas-used, in the interpreter loop. It's an actual
call (not inlined), which explicitly wants to be ignored by tracing
("tracing.GasChangeIgnored"), so it can be safely and simply inlined.

The other change is in `pushX`. These also do a call to
`common.RightPadBytes`. I replaced that by a doing a corresponding `Lsh`
on the `u256` if needed. Note: it's needed only to make the stack output
look right, for fuzzers. It technically doesn't matter what we put
there: if code ends on a pushdata immediate, nothing will consume the
stack element. We could just as well just ignore it, if we didn't care
about fuzzers (which I do).

Seems quite a lot faster on burntpix, according to my runs. 

This PR:
```
EVM gas used:    5642735088
execution time:  34.84609475s
allocations:     915683
allocated bytes: 175334088
```
```
EVM gas used:    5642735088
execution time:  36.671958278s
allocations:     915701
allocated bytes: 175340528
```

Master
```
EVM gas used:    5642735088
execution time:  49.349209526s
allocations:     915684
allocated bytes: 175333368
```
```
EVM gas used:    5642735088
execution time:  46.581006598s
allocations:     915681
allocated bytes: 175330728
```

---------

Co-authored-by: Sina M <1591639+s1na@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2024-10-30 18:01:47 +01:00
Danno Ferrin 1156ca42f2 Limit EXTCODECOPY to eof bytes
When copying EOF contracts, make sure EXTCODECOPY only has access to the EOF magic, not just two bytes total.
2024-10-25 12:27:23 -06:00
jwasinger 24c5493bec
core/vm: remove debug printout in eof test (#30665) 2024-10-24 09:13:01 +02:00
jwasinger 478012ab23
all: remove TerminalTotalDifficultyPassed (#30609)
rebased https://github.com/ethereum/go-ethereum/pull/29766 . The
downstream branch appears to have been deleted and I don't have perms to
push to that fork.

`TerminalTotalDifficultyPassed` is removed. `TerminalTotalDifficulty`
must now be non-nil, and it is expected that networks are already
merged: we can only import PoW/Clique chains, not produce blocks on
them.

---------

Co-authored-by: stevemilk <wangpeculiar@gmail.com>
2024-10-23 08:26:18 +02:00
Martin HS 459bb4a647
core/state: move state log mechanism to a separate layer (#30569)
This PR moves the logging/tracing-facilities out of `*state.StateDB`,
in to a wrapping struct which implements `vm.StateDB` instead.

In most places, it is a pretty straight-forward change: 
- First, hoisting the invocations from state objects up to the statedb. 
- Then making the mutation-methods simply return the previous value, so
that the external logging layer could log everything.

Some internal code uses the direct object-accessors to mutate the state,
particularly in testing and in setting up state overrides, which means
that these changes are unobservable for the hooked layer. Thus, configuring
the overrides are not necessarily part of the API we want to publish.

The trickiest part about the layering is that when the selfdestructs are
finally deleted during `Finalise`, there's the possibility that someone
sent some ether to it, which is burnt at that point, and thus needs to
be logged. The hooked layer reaches into the inner layer to figure out
these events.

In package `vm`, the conversion from `state.StateDB + hooks` into a
hooked `vm.StateDB` is performed where needed.

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2024-10-23 08:03:36 +02:00
Péter Szilágyi a5fe7353cf
common: drop BigMin and BigMax, they pollute our dep graph (#30645)
Way back we've added `common.math.BigMin` and `common.math.BigMax`.
These were kind of cute helpers, but unfortunate ones, because package
all over out codebase added dependencies to this package just to avoid
having to write out 3 lines of code.

Because of this, we've also started having package name clashes with the
stdlib `math`, which got solves even more badly by moving some helpers
over ***from*** the stdlib into our custom lib (e.g. MaxUint64). The
latter ones were nuked out in a previous PR and this PR nukes out BigMin
and BigMax, inlining them at all call sites.

As we're transitioning to uint256, if need be, we can add a min and max
to that.
2024-10-21 12:45:33 +03:00
Péter Szilágyi 48d05c43c9
all: get rid of custom MaxUint64 and MaxUint64 (#30636) 2024-10-20 14:41:51 +03:00
Sina M 978ca5fc5e
eth/tracers: various fixes (#30540)
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.
2024-10-17 06:51:47 +02:00
Martin HS 5adc314817
build: update to golangci-lint 1.61.0 (#30587)
Changelog: https://golangci-lint.run/product/changelog/#1610 

Removes `exportloopref` (no longer needed), replaces it with
`copyloopvar` which is basically the opposite.

Also adds: 
- `durationcheck`
- `gocheckcompilerdirectives`
- `reassign`
- `mirror`
- `tenv`

---------

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
2024-10-14 19:25:22 +02:00
Marius van der Wijden a73a8e7851 happy lint, happy life 2024-10-11 12:42:56 +02:00
Marius van der Wijden d2af47a16d core/vm: fix rebasing issue 2024-10-11 12:42:41 +02:00
Marius van der Wijden 1b300b26b2 core/vm: fix rebasing issue 2024-10-11 12:42:41 +02:00
Marius van der Wijden d0dfef2eb4 core/vm: fix eofcreate auxdata 2024-10-11 12:42:41 +02:00
Marius van der Wijden 1d5144465f core/vm: fix create rules 2024-10-11 12:42:13 +02:00
Marius van der Wijden 3d82fb13a3 core/vm: add gas computation for EOFCREATE, EXT{CALL,DELEGATECALL,STATICCALL} 2024-10-11 12:42:13 +02:00
Marius van der Wijden d206fba16d core/vm: added EXTCALL,EXTDELEGATECALL,EXTSTATICCALL opcode 2024-10-11 12:42:13 +02:00
Marius van der Wijden c7db447b1f core/vm: added RETURNDATALOAD opcode 2024-10-11 12:42:13 +02:00
Marius van der Wijden bb1885c78e core/vm: added DATALOAD,DATALOADN,DATASIZE,DATACOPY opcode 2024-10-11 12:42:13 +02:00
Marius van der Wijden 5992baf543 core/vm: added RETURNCONTRACT opcode 2024-10-11 12:42:13 +02:00
Marius van der Wijden 9fa14a1af4 core/vm: added EOFCREATE opcode 2024-10-11 12:42:13 +02:00
Marius van der Wijden a58ba40cf6 core/vm: added JUMPF opcodes 2024-10-11 12:42:13 +02:00
Marius van der Wijden 026306218b core/vm: added CALLF,RETF opcodes 2024-10-11 12:42:13 +02:00
Marius van der Wijden 866ad956a4 core/vm: added RJUMP,RJUMPI,RJUMPV opcodes 2024-10-11 12:42:13 +02:00
Marius van der Wijden 5bd220b2f0 core/vm: added opSwapN,Exchange,DupN opcodes 2024-10-11 12:42:13 +02:00
Marius van der Wijden 3012db54ee core/vm: added new behavior to legacy opcodes 2024-10-11 12:42:13 +02:00
Marius van der Wijden 8374793fec core/vm: add new eof-behavior to opDelegateCall 2024-10-11 12:42:13 +02:00
Marius van der Wijden 2297ef65dd core/vm: add ReturnStack etc to ScopeContext 2024-10-11 12:42:13 +02:00
Marius van der Wijden d23c5e5e62 core: special case on creation for eof code 2024-10-11 12:42:13 +02:00
Marius van der Wijden d744516b74 core/vm: parse containers on call 2024-10-11 12:42:13 +02:00
Marius van der Wijden 44125c2e45 core/vm: add analysis tests 2024-10-11 12:42:13 +02:00