Commit Graph

2726 Commits

Author SHA1 Message Date
Felix Lange ed1d46b3d3
consensus/misc/eip4844: more changes for blob gas calculation (#31128)
This PR changes the signature of `CalcExcessBlobGas` to take in just
the header timestamp instead of the whole object. It also adds a sanity
check for the parent->child block order to `VerifyEIP4844Header`.
2025-02-05 10:35:03 +01:00
lightclient c4ad459bd2
consensus/misc/eip4844: use head's target blobs, not parent (#31101)
A clarification was made to EIP-7691 stating that at the fork boundary
it is required to use the target blob count associated with the head
block, rather than the parent as implemented here.

See for more: https://github.com/ethereum/EIPs/pull/9249
2025-02-04 21:43:18 +01:00
Marius van der Wijden 59d2eec9fc
core/txpool/blobpool: fix incorrect arguments in test (#31127)
Fixes the linter on master which was broken by
https://github.com/ethereum/go-ethereum/pull/30559
2025-02-04 18:10:40 +01:00
Martin HS 7c7b7f6ab1
core/txpool: remove locals-tracking from txpools (#30559)
Replaces  #29297, descendant from #27535

---------

This PR removes `locals` as a concept from transaction pools. Therefore,
the pool now acts as very a good simulation/approximation of how our
peers' pools behave. What this PR does instead, is implement a
locals-tracker, which basically is a little thing which, from time to
time, asks the pool "did you forget this transaction?". If it did, the
tracker resubmits it.

If the txpool _had_ forgotten it, chances are that the peers had also
forgotten it. It will be propagated again.

Doing this change means that we can simplify the pool internals, quite a
lot.

### The semantics of `local` 

Historically, there has been two features, or usecases, that has been
combined into the concept of `locals`.

1. "I want my local node to remember this transaction indefinitely, and
resubmit to the network occasionally"
2. "I want this (valid) transaction included to be top-prio for my
miner"


This PR splits these features up, let's call it `1: local` and `2:
prio`. The `prio` is not actually individual transaction, but rather a
set of `address`es to prioritize.
The attribute `local` means it will be tracked, and `prio` means it will
be prioritized by miner.

For `local`: anything transaction received via the RPC is marked as
`local`, and tracked by the tracker.
For `prio`: any transactions from this sender is included first, when
building a block. The existing commandline-flag `--txpool.locals` sets
the set of `prio` addresses.

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2025-02-04 17:23:01 +01:00
Felix Lange e332431cb2
core: assign default difficulty to zero for chain without ethash (#31067)
I hit this case while trying something with the simulated backend. The
EVM only enables instruction set forks after the merge when 'Random' is
set. In the simulated backend, the random value will be set via the
engine API for all blocks after genesis. But for the genesis block
itself, the random value will not be assigned in the vm.BlockContext
because the genesis has a non-zero difficulty. For my case, this meant
that estimateGas did not work for the first transaction sent on the
simulated chain, since the contract contained a PUSH0 instruction.

This could also be fixed by explicitly configuring a zero difficulty in
the simulated backend. However, I think that zero difficulty is a better
default these days.

---------

Co-authored-by: lightclient <lightclient@protonmail.com>
2025-02-04 17:16:26 +01:00
lightclient e6f3ce7b16
params,core: add max and target value to chain config (#31002)
Implements [EIP-7840](https://github.com/ethereum/EIPs/pull/9129) and
[EIP-7691](d96625a4dc/EIPS/eip-7691.md).

---------

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-02-04 15:43:18 +01:00
Marius van der Wijden eee868226a
params: start osaka fork (#31125)
This PR defines the Osaka fork. An easy first step to start our work on
the next hardfork

(This is needed for EOF testing as well)

---------

Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com>
2025-02-04 15:29:51 +01:00
Marius van der Wijden 665c8512f3
core: copy genesis before modifying (#31097)
This PR fixes a data race in SetupGenesisWithOverride.
2025-02-04 14:22:30 +01:00
rjl493456442 0ad0966cec
core/rawdb: introduce flush offset in freezer (#30392)
This is a follow-up PR to #29792 to get rid of the data file sync.

**This is a non-backward compatible change, which increments the
database version from 8 to 9**.

We introduce a flushOffset for each freezer table, which tracks the position
of the most recently fsync’d item in the index file. When this offset moves
forward, it indicates that all index entries below it, along with their corresponding
data items, have been properly persisted to disk. The offset can also be moved
backward when truncating from either the head or tail of the file.

Previously, the data file required an explicit fsync after every mutation, which
was highly inefficient. With the introduction of the flush offset, the synchronization
strategy becomes more flexible, allowing the freezer to sync every 30 seconds
instead.

The data items above the flush offset are regarded volatile and callers must ensure
they are recoverable after the unclean shutdown, or explicitly sync the freezer
before any proceeding operations.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-02-04 11:45:45 +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
Sina M 0e1a19da76
core: implement eip-7623 floor data gas (#30946)
This PR builds on #29040 and updates it to the new version of the spec.
I filled the EEST tests and they pass.

Link to spec: https://eips.ethereum.org/EIPS/eip-7623

---------

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com>
Co-authored-by: lightclient <lightclient@protonmail.com>
2025-01-30 09:07:45 -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
Péter Szilágyi 39638c81c5
all: nuke total difficulty (#30744)
The total difficulty is the sum of all block difficulties from genesis
to a certain block. This value was used in PoW for deciding which chain
is heavier, and thus which chain to select. Since PoS has a different
fork selection algorithm, all blocks since the merge have a difficulty
of 0, and all total difficulties are the same for the past 2 years.

Whilst the TDs are mostly useless nowadays, there was never really a
reason to mess around removing them since they are so tiny. This
reasoning changes when we go down the path of pruned chain history. In
order to reconstruct any TD, we **must** retrieve all the headers from
chain head to genesis and then iterate all the difficulties to compute
the TD.

In a world where we completely prune past chain segments (bodies,
receipts, headers), it is not possible to reconstruct the TD at all. In
a world where we still keep chain headers and prune only the rest,
reconstructing it possible as long as we process (or download) the chain
forward from genesis, but trying to snap sync the head first and
backfill later hits the same issue, the TD becomes impossible to
calculate until genesis is backfilled.

All in all, the TD is a messy out-of-state, out-of-consensus computed
field that is overall useless nowadays, but code relying on it forces
the client into certain modes of operation and prevents other modes or
other optimizations. This PR completely nukes out the TD from the node.
It doesn't compute it, it doesn't operate on it, it's as if it didn't
even exist.

Caveats:

- Whenever we have APIs that return TD (devp2p handshake, tracer, etc.)
we return a TD of 0.
- For era files, we recompute the TD during export time (fairly quick)
to retain the format content.
- It is not possible to "verify" the merge point (i.e. with TD gone, TTD
is useless). Since we're not verifying PoW any more, just blindly trust
it, not verifying but blindly trusting the many year old merge point
seems just the same trust model.
- Our tests still need to be able to generate pre and post merge blocks,
so they need a new way to split the merge without TTD. The PR introduces
a settable ttdBlock field on the consensus object which is used by tests
as the block where originally the TTD happened. This is not needed for
live nodes, we never want to generate old blocks.
- One merge transition consensus test was disabled. With a
non-operational TD, testing how the client reacts to TTD is useless, it
cannot react.

Questions:

- Should we also drop total terminal difficulty from the genesis json?
It's a number we cannot react on any more, so maybe it would be cleaner
to get rid of even more concepts.

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2025-01-28 18:55:41 +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
jwasinger e25cedf16d
core/txpool: terminate subpool reset goroutine if pool was closed (#31030)
if the pool terminates before `resetDone` can be read, then the
go-routine will hang.
2025-01-21 11:42:05 +08:00
Shude Li 530adfc8e3
core/types: initialize ChainID in SetCodeTx copy method (#31054) 2025-01-20 17:06:39 +01:00
Shude Li 17199daa76
core/types: correct chainId check for pragueSigner (#31032)
Use zero value check for the pragueSigner

This aligns with cancunSigner and londonSigner as well.
2025-01-20 10:12:36 +01:00
rjl493456442 a7f9523ae1
all: implement state history v2 (#30107)
This pull request delivers the new version of the state history, where
the raw storage key is used instead of the hash.

Before the cancun fork, it's supported by protocol to destruct a
specific account and therefore, all the storage slot owned by it should
be wiped in the same transition.

Technically, storage wiping should be performed through storage
iteration, and only the storage key hash will be available for traversal
if the state snapshot is not available. Therefore, the storage key hash
is chosen as the identifier in the old version state history.

Fortunately, account self-destruction has been deprecated by the
protocol since the Cancun fork, and there are no empty accounts eligible
for deletion under EIP-158. Therefore, we can conclude that no storage
wiping should occur after the Cancun fork. In this case, it makes no
sense to keep using hash.

Besides, another big reason for making this change is the current format
state history is unusable if verkle is activated. Verkle tree has a
different key derivation scheme (merkle uses keccak256), the preimage of
key hash must be provided in order to make verkle rollback functional.
This pull request is a prerequisite for landing verkle.

Additionally, the raw storage key is more human-friendly for those who
want to manually check the history, even though Solidity already
performs some hashing to derive the storage location.

---

This pull request doesn't bump the database version, as I believe the
database should still be compatible if users degrade from the new geth
version to old one, the only side effect is the persistent new version
state history will be unusable.

---------

Co-authored-by: Zsolt Felfoldi <zsfelfoldi@gmail.com>
2025-01-17 02:59:02 +01:00
Matthieu Vachon 4d94bd83b2
core/tracing: document `OnCodeChange` now being called from SelfDestruct (#31007)
Co-authored-by: Sina M <1591639+s1na@users.noreply.github.com>
2025-01-16 15:58:16 +01:00
jwasinger 47d17acdc9
core/txpool/legacypool: ensure pending nonces are reset by SubPool.Clear (#31020)
closes https://github.com/ethereum/go-ethereum/issues/30842
2025-01-16 14:40:15 +01:00
georgehao 9e4f08c25d
core: use sync.Once for SenderCacher initialization (#31029)
This changes the SenderCacher so its goroutines will only be started on first use.
Avoids starting them when package core is just imported but core.BlockChain isn't used.
2025-01-16 14:36:45 +01:00
Felix Lange 04a336aee8
core/types: change SetCodeTx.ChainID to uint256 (#30982)
We still need to decide how to handle non-specfic `chainId` in the JSON
encoding of authorizations. With `chainId` being a uint64, the previous
implementation just used value zero. However, it might actually be more
correct to use the value `null` for this case.
2025-01-14 06:42:18 -07:00
georgehao 1843f27766
all: fix some typos in comments and names (#31023) 2025-01-14 14:16:15 +01:00
rjl493456442 37c0e6992e
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:

**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.

A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize 
the genesis in Verkle mode.

In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.

**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.

Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 11:49:30 +01:00
Paul Lange 864e717b56
core: remove unused function parameters (#31001) 2025-01-13 19:35:49 +01:00
Quentin McGaw fcf5204a02
core/txpool/legacypool: fix flaky test TestAllowedTxSize (#30975)
- it was failing because the maximum data length (previously `dataSize`)
was set to `txMaxSize - 213` but should had been `txMaxSize - 103` and
the last call `dataSize+1+uint64(rand.Intn(10*txMaxSize)))` would
sometimes fail depending on rand.Intn.
- Maximal transaction data size comment (invalid) replaced by code logic
to find the maximum tx length without its data length
- comments and variable naming improved for clarity
- 3rd pool add test replaced to add just 1 above the maximum length,
which is important to ensure the logic is correct
2025-01-13 19:33:49 +01:00
Daniel Liu c0882429f0
build: upgrade golangci-lint to v1.63.4 (#31019)
This PR upgrades `golangci-lint` to v1.63.4 and fixes a warn message
which is reported by v1.63.4:

```text
WARN [config_reader] The configuration option `run.skip-dirs-use-default` is deprecated, please use `issues.exclude-dirs-use-default`.
```

Also fixes 2 warnings which are reported by v1.63.4:

```text
core/txpool/blobpool/blobpool.go:1754:12: S1005: unnecessary assignment to the blank identifier (gosimple)
        for acct, _ := range p.index {
                  ^
core/txpool/legacypool/legacypool.go:1989:19: S1005: unnecessary assignment to the blank identifier (gosimple)
        for localSender, _ := range pool.locals.accounts {
                         ^
```
2025-01-13 08:26:10 +01:00
rjl493456442 82e963e5c9
triedb/pathdb: configure different node hasher in pathdb (#31008)
As the node hash scheme in verkle and merkle are totally different, the
original default node hasher in pathdb is no longer suitable. Therefore,
this pull request configures different node hasher respectively.
2025-01-10 20:51:19 +08:00
georgehao 6897a4a9e0
core/types: improve printList in DeriveSha test (#30969) 2025-01-06 16:28:28 +01:00
Marius van der Wijden c5a8d34851
core/rawdb: fix panic in freezer (#30973)
Fixes an issue where the node panics when an LStat fails with something 
other than os.ErrNotExist

closes https://github.com/ethereum/go-ethereum/issues/30968
2025-01-06 14:52:01 +08:00
gitglorythegreat 85ffbde427
all: use cmp.Compare (#30958) 2025-01-02 14:06:47 +01:00
Felix Lange f1e6372eea
core, core/types: rename AuthList to SetCodeAuthorizations (#30935)
As a follow-up to #30933, I propose to also use the SetCode prefix in
our internal APIs for the authorization list.
2024-12-19 10:06:33 +01:00
Felix Lange 73a4ecf675 core/types: rename SetCodeAuthorization 'v' to 'yParity'
The API spec requires the name yParity.
2024-12-18 19:46:15 +01:00
Felix Lange 9d4b29f291
core/types: updates for EIP-7702 API functions (#30933)
Here I am proposing two small changes to the exported API for EIP-7702:

(1) `Authorization` has a very generic name, but it is in fact only used
for one niche use case: authorizing code in a `SetCodeTx`. So I propose
calling it `SetCodeAuthorization` instead. The signing function is
renamed to `SignSetCode` instead of `SignAuth`.
   
(2) The signing function for authorizations should take key as the first
parameter, and the authorization second. The key will almost always be
in a variable, while the authorization can be given as a literal.
2024-12-18 19:10:53 +01:00
Felix Lange 06dfb42365
core/types, internal/ethapi: fixes for prague RPC encoding (#30926)
Fixing some issues I found while regenerating RPC tests for Prague:

- Authorization signature values were not encoded as hex
- `requestsRoot` in block should be `requestsHash`
- `authorizationList` should work for `eth_call`
2024-12-17 19:47:10 +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
Felix Lange 71c28d8d2b
core: fixes for Prague fork in GenerateChain (#30924)
Adding some missing functionality I noticed while updating the hivechain
tool for the Prague fork:

- we forgot to process the parent block hash
- added `ConsensusLayerRequests` to get the requests list of the block
2024-12-17 15:16:17 +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
gitglorythegreat c7e740f40c
core/state: remove pointless wrapper functions (#30891) 2024-12-11 11:05:59 +01:00
Martin HS 9045b79bc2
metrics, cmd/geth: change init-process of metrics (#30814)
This PR modifies how the metrics library handles `Enabled`: previously,
the package `init` decided whether to serve real metrics or just
dummy-types.

This has several drawbacks: 
- During pkg init, we need to determine whether metrics are enabled or
not. So we first hacked in a check if certain geth-specific
commandline-flags were enabled. Then we added a similar check for
geth-env-vars. Then we almost added a very elaborate check for
toml-config-file, plus toml parsing.

- Using "real" types and dummy types interchangeably means that
everything is hidden behind interfaces. This has a performance penalty,
and also it just adds a lot of code.

This PR removes the interface stuff, uses concrete types, and allows for
the setting of Enabled to happen later. It is still assumed that
`metrics.Enable()` is invoked early on.

The somewhat 'heavy' operations, such as ticking meters and exp-decay,
now checks the enable-flag to prevent resource leak.

The change may be large, but it's mostly pretty trivial, and from the
last time I gutted the metrics, I ensured that we have fairly good test
coverage.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2024-12-10 13:27:29 +01:00
Zheyuan He 4ecf08584c
core/vm: remove unnecessary comment (#30887) 2024-12-10 13:10:17 +01:00
rjl493456442 a91dcf3ee5
core/state: enable partial-functional reader (snapshot integration pt 3) (#30650)
It's a pull request based on https://github.com/ethereum/go-ethereum/pull/30643

In this pull request, the partial functional state reader is enabled if **legacy snapshot
is not enabled**. The tracked flat states in pathdb will be used to serve the state
retrievals, as the second implementation to fasten the state access.

This pull request should be a noop change in normal cases.
2024-12-10 10:10:49 +08:00
steven a722adb774
core/txpool: remove unused parameter `local` (#30871) 2024-12-09 19:29:19 +01:00
Guillaume Ballet 08e6bdb550
trie/utils: ensure master can generate a correct genesis for kaustinen7 (#30856)
This imports the following fixes:

 - update gnark to 1.1.0
 - update go-verkle to 0.2.2
 - fix: main storage offset bug (gballet/go-ethereum#329)
 - fix: tree key generation (gballet/go-ethereum#401)

---------

Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>
2024-12-06 12:14:05 +01:00
Nebojsa Urosevic 67a3b08795
core/tracing: extends tracing.Hooks with OnSystemCallStartV2 (#30786)
This PR extends the Hooks interface with a new method,
`OnSystemCallStartV2`, which takes `VMContext` as its parameter.

Motivation

By including `VMContext` as a parameter, the `OnSystemCallStartV2` hook
achieves parity with the `OnTxStart` hook in terms of provided insights.
This alignment simplifies the inner tracer logic, enabling consistent
handling of state changes and internal calls within the same framework.

---------

Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
2024-12-04 09:40:37 +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