Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions execution/protocol/block_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/erigontech/erigon/common/u256"
"github.com/erigontech/erigon/diagnostics/metrics"
"github.com/erigontech/erigon/execution/chain"
"github.com/erigontech/erigon/execution/protocol/params"
"github.com/erigontech/erigon/execution/protocol/rules"
"github.com/erigontech/erigon/execution/rlp"
"github.com/erigontech/erigon/execution/state"
Expand Down Expand Up @@ -267,7 +268,7 @@ func SysCallContract(contract accounts.Address, data []byte, chainConfig *chain.
if isBor {
author = accounts.InternAddress(header.Coinbase)
} else {
author = state.SystemAddress
author = params.SystemAddress
}
blockContext := NewEVMBlockContext(header, GetHashFn(header, nil), engine, author, chainConfig)
return SysCallContractWithBlockContext(contract, data, chainConfig, ibs, blockContext, constCall, vmCfg)
Expand All @@ -276,7 +277,7 @@ func SysCallContract(contract accounts.Address, data []byte, chainConfig *chain.
func SysCallContractWithBlockContext(contract accounts.Address, data []byte, chainConfig *chain.Config, ibs *state.IntraBlockState, blockContext evmtypes.BlockContext, constCall bool, vmCfg vm.Config) (result []byte, err error) {
isBor := chainConfig.Bor != nil
msg := types.NewMessage(
state.SystemAddress,
params.SystemAddress,
contract,
0, &u256.Num0,
SysCallGasLimit,
Expand Down
4 changes: 2 additions & 2 deletions execution/protocol/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func NewEVMBlockContext(header *types.Header, blockHashFunc func(n uint64) (comm
transferFunc = engine.GetTransferFunc()
postApplyMessageFunc = engine.GetPostApplyMessageFunc()
} else {
transferFunc = rules.Transfer
postApplyMessageFunc = nil
transferFunc = misc.Transfer
postApplyMessageFunc = misc.LogSelfDestructedAccounts
}
blockContext := evmtypes.BlockContext{
CanTransfer: CanTransfer,
Expand Down
106 changes: 106 additions & 0 deletions execution/protocol/misc/eip7708.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2026 The go-ethereum Authors
// (original work)
// Copyright 2026 The Erigon Authors
// (modifications)
// This file is part of Erigon.
//
// Erigon 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.
//
// Erigon 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 Erigon. If not, see <http://www.gnu.org/licenses/>.

package misc

import (
"sort"

"github.com/holiman/uint256"

"github.com/erigontech/erigon/common"
"github.com/erigontech/erigon/execution/chain"
"github.com/erigontech/erigon/execution/protocol/params"
"github.com/erigontech/erigon/execution/tracing"
"github.com/erigontech/erigon/execution/types"
"github.com/erigontech/erigon/execution/types/accounts"
"github.com/erigontech/erigon/execution/vm/evmtypes"
)

var (
// keccak256('Transfer(address,address,uint256)')
EthTransferLogEvent = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")

// keccak256('Selfdestruct(address,uint256)')
EthSelfDestructLogEvent = common.HexToHash("0x4bfaba3443c1a1836cd362418edc679fc96cae8449cbefccb6457cdf2c943083")
)

// EthTransferLog creates and ETH transfer log according to EIP-7708.
// Specification: https://eips.ethereum.org/EIPS/eip-7708
func EthTransferLog(from, to common.Address, amount uint256.Int) *types.Log {
amount32 := amount.Bytes32()
return &types.Log{
Address: params.SystemAddress.Value(),
Topics: []common.Hash{
EthTransferLogEvent,
from.Hash(),
to.Hash(),
},
Data: amount32[:],
}
}

// EthSelfDestructLog creates and ETH self-destruct burn log according to EIP-7708.
// Specification: https://eips.ethereum.org/EIPS/eip-7708
func EthSelfDestructLog(from common.Address, amount uint256.Int) *types.Log {
amount32 := amount.Bytes32()
return &types.Log{
Address: params.SystemAddress.Value(),
Topics: []common.Hash{
EthSelfDestructLogEvent,
from.Hash(),
},
Data: amount32[:],
}
}

// Transfer subtracts amount from sender and adds amount to recipient using the given Db
func Transfer(db evmtypes.IntraBlockState, sender, recipient accounts.Address, amount uint256.Int, bailout bool, rules *chain.Rules) error {
if !bailout {
err := db.SubBalance(sender, amount, tracing.BalanceChangeTransfer)
if err != nil {
return err
}
}
err := db.AddBalance(recipient, amount, tracing.BalanceChangeTransfer)
if err != nil {
return err
}
if rules.IsAmsterdam && !amount.IsZero() { // EIP-7708
db.AddLog(EthTransferLog(sender.Value(), recipient.Value(), amount))
}
return nil
}

func LogSelfDestructedAccounts(ibs evmtypes.IntraBlockState, sender accounts.Address, coinbase accounts.Address, result *evmtypes.ExecutionResult, rules *chain.Rules) {
if !rules.IsAmsterdam {
return
}
// Emit SelfDestruct logs where accounts with non-empty balances have been deleted
// See case (2) in https://eips.ethereum.org/EIPS/eip-7708#selfdestruct-processing
removedWithBalance := ibs.GetRemovedAccountsWithBalance()
if removedWithBalance != nil {
sort.Slice(removedWithBalance, func(i, j int) bool {
return removedWithBalance[i].Address.Cmp(removedWithBalance[j].Address) < 0
})
for _, sd := range removedWithBalance {
ibs.AddLog(EthSelfDestructLog(sd.Address, sd.Balance))
}
}
}
5 changes: 4 additions & 1 deletion execution/protocol/params/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ const (
var DelegatedDesignationPrefix = []byte{0xef, 0x01, 0x00}
var DelegatedCodeHash = common.HexToHash("0xeadcdba66a79ab5dce91622d1d75c8cff5cff0b96944c3bf1072cd08ce018329")

// SystemAddress is where the system-transaction is sent from as per EIP-4788
var SystemAddress = accounts.InternAddress(common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe"))

// EIP-4788: Beacon block root in the EVM
var BeaconRootsAddress = accounts.InternAddress(common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"))

Expand All @@ -223,7 +226,7 @@ var HistoryStorageAddress = accounts.InternAddress(common.HexToAddress("0x0000F9
// EIP-7002: Execution layer triggerable withdrawals
var WithdrawalRequestAddress = accounts.InternAddress(common.HexToAddress("0x00000961Ef480Eb55e80D19ad83579A64c007002"))

// EIP-7251
// EIP-7251: Increase the MAX_EFFECTIVE_BALANCE
var ConsolidationRequestAddress = accounts.InternAddress(common.HexToAddress("0x0000BBdDc7CE488642fb579F8B00f3a590007251"))

// Gas discount table for BLS12-381 G1 and G2 multi exponentiation operations
Expand Down
3 changes: 2 additions & 1 deletion execution/protocol/rules/aura/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/erigontech/erigon/common/log/v3"
"github.com/erigontech/erigon/db/kv"
"github.com/erigontech/erigon/execution/chain"
"github.com/erigontech/erigon/execution/protocol/misc"
"github.com/erigontech/erigon/execution/protocol/rules"
"github.com/erigontech/erigon/execution/protocol/rules/clique"
"github.com/erigontech/erigon/execution/protocol/rules/ethash"
Expand Down Expand Up @@ -1162,7 +1163,7 @@ func (c *AuRa) ExecuteSystemWithdrawals(withdrawals []*types.Withdrawal, syscall
}

func (c *AuRa) GetTransferFunc() evmtypes.TransferFunc {
return rules.Transfer
return misc.Transfer
}

func (c *AuRa) GetPostApplyMessageFunc() evmtypes.PostApplyMessageFunc {
Expand Down
3 changes: 2 additions & 1 deletion execution/protocol/rules/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/erigontech/erigon/db/services"
"github.com/erigontech/erigon/execution/chain"
chainspec "github.com/erigontech/erigon/execution/chain/spec"
"github.com/erigontech/erigon/execution/protocol/misc"
"github.com/erigontech/erigon/execution/protocol/rules"
"github.com/erigontech/erigon/execution/rlp"
"github.com/erigontech/erigon/execution/state"
Expand Down Expand Up @@ -641,7 +642,7 @@ func (c *Clique) snapshots(latest uint64, total int) ([]*Snapshot, error) {
}

func (c *Clique) GetTransferFunc() evmtypes.TransferFunc {
return rules.Transfer
return misc.Transfer
}

func (c *Clique) GetPostApplyMessageFunc() evmtypes.PostApplyMessageFunc {
Expand Down
3 changes: 2 additions & 1 deletion execution/protocol/rules/ethash/ethash.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
dir2 "github.com/erigontech/erigon/common/dir"
"github.com/erigontech/erigon/common/log/v3"
"github.com/erigontech/erigon/common/math"
"github.com/erigontech/erigon/execution/protocol/misc"
"github.com/erigontech/erigon/execution/protocol/rules"
"github.com/erigontech/erigon/execution/protocol/rules/ethash/ethashcfg"
"github.com/erigontech/erigon/execution/types"
Expand Down Expand Up @@ -580,7 +581,7 @@ func SeedHash(block uint64) []byte {
}

func (ethash *Ethash) GetTransferFunc() evmtypes.TransferFunc {
return rules.Transfer
return misc.Transfer
}

func (ethash *Ethash) GetPostApplyMessageFunc() evmtypes.PostApplyMessageFunc {
Expand Down
2 changes: 1 addition & 1 deletion execution/protocol/rules/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (s *Merge) GetTransferFunc() evmtypes.TransferFunc {
}

func (s *Merge) GetPostApplyMessageFunc() evmtypes.PostApplyMessageFunc {
return s.eth1Engine.GetPostApplyMessageFunc()
return misc.LogSelfDestructedAccounts // EIP-7708
}

func (s *Merge) Close() error {
Expand Down
13 changes: 1 addition & 12 deletions execution/protocol/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"github.com/holiman/uint256"

common "github.com/erigontech/erigon/common"
"github.com/erigontech/erigon/common"
"github.com/erigontech/erigon/common/log/v3"
"github.com/erigontech/erigon/execution/chain"
"github.com/erigontech/erigon/execution/state"
Expand Down Expand Up @@ -200,14 +200,3 @@ type PoW interface {
// Hashrate returns the current mining hashrate of a PoW rules engine.
Hashrate() float64
}

// Transfer subtracts amount from sender and adds amount to recipient using the given Db
func Transfer(db evmtypes.IntraBlockState, sender, recipient accounts.Address, amount uint256.Int, bailout bool) error {
if !bailout {
err := db.SubBalance(sender, amount, tracing.BalanceChangeTransfer)
if err != nil {
return err
}
}
return db.AddBalance(recipient, amount, tracing.BalanceChangeTransfer)
}
6 changes: 3 additions & 3 deletions execution/protocol/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func applyMessage(evm *vm.EVM, msg Message, gp *GasPool, refunds bool, gasBailou
// Only zero-gas transactions may be service ones
if msg.FeeCap().IsZero() && !msg.IsFree() && engine != nil {
blockContext := evm.Context
blockContext.Coinbase = state.SystemAddress
blockContext.Coinbase = params.SystemAddress
syscall := func(contract accounts.Address, data []byte) ([]byte, error) {
ret, err := SysCallContractWithBlockContext(contract, data, evm.ChainConfig(), evm.IntraBlockState(), blockContext, true, evm.Config())
return ret, err
Expand Down Expand Up @@ -399,7 +399,7 @@ func (st *StateTransition) ApplyFrame() (*evmtypes.ExecutionResult, error) {
}

if st.evm.Context.PostApplyMessage != nil {
st.evm.Context.PostApplyMessage(st.state, msg.From(), coinbase, result)
st.evm.Context.PostApplyMessage(st.state, msg.From(), coinbase, result, rules)
}

return result, nil
Expand Down Expand Up @@ -614,7 +614,7 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (result *
result.BurntContractAddress = burntContractAddress

if st.evm.Context.PostApplyMessage != nil {
st.evm.Context.PostApplyMessage(st.state, msg.From(), coinbase, result)
st.evm.Context.PostApplyMessage(st.state, msg.From(), coinbase, result, rules)
}

return result, nil
Expand Down
3 changes: 2 additions & 1 deletion execution/stagedsync/bal_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/erigontech/erigon/common"
"github.com/erigontech/erigon/common/log/v3"
"github.com/erigontech/erigon/execution/protocol/params"
"github.com/erigontech/erigon/execution/state"
"github.com/erigontech/erigon/execution/types"
"github.com/erigontech/erigon/execution/types/accounts"
Expand Down Expand Up @@ -169,7 +170,7 @@ func updateAccountWrite(account *accountState, vw *state.VersionedWrite, accessI
}

func isSystemBALAddress(addr accounts.Address) bool {
return addr == state.SystemAddress
return addr == params.SystemAddress
}

func hasStorageWrite(ac *types.AccountChanges, slot accounts.StorageKey) bool {
Expand Down
7 changes: 5 additions & 2 deletions execution/stagedsync/exec3_parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,11 @@ func (result *execResult) finalize(prevReceipt *types.Receipt, engine rules.Engi
}
ibs.SetTrace(txTask.Trace)

rules := txTask.EvmBlockContext.Rules(txTask.Config)

if task.IsBlockEnd() || txIndex < 0 {
if blockNum == 0 || txTask.Config.IsByzantium(blockNum) {
if err := ibs.FinalizeTx(txTask.EvmBlockContext.Rules(txTask.Config), stateWriter); err != nil {
if err := ibs.FinalizeTx(rules, stateWriter); err != nil {
return nil, nil, nil, err
}
}
Expand Down Expand Up @@ -1038,6 +1040,7 @@ func (result *execResult) finalize(prevReceipt *types.Receipt, engine rules.Engi
message.From(),
result.Coinbase,
&execResult,
rules,
)

// capture postApplyMessageFunc side affects
Expand All @@ -1059,7 +1062,7 @@ func (result *execResult) finalize(prevReceipt *types.Receipt, engine rules.Engi
vm.SetTrace(false)

if txTask.Config.IsByzantium(blockNum) {
ibs.FinalizeTx(txTask.EvmBlockContext.Rules(txTask.Config), stateWriter)
ibs.FinalizeTx(rules, stateWriter)
}

receipt, err := result.CreateNextReceipt(prevReceipt)
Expand Down
Loading
Loading