Skip to content
Draft
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
97 changes: 97 additions & 0 deletions execution/protocol/misc/eip7708.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// 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"
)

// 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{
params.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{
params.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
}
// (EIP-7708) Emit SelfDestruct logs where accounts with non-empty balances have been deleted
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))
}
}
}
29 changes: 21 additions & 8 deletions execution/protocol/params/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,30 @@ const (
var DelegatedDesignationPrefix = []byte{0xef, 0x01, 0x00}
var DelegatedCodeHash = common.HexToHash("0xeadcdba66a79ab5dce91622d1d75c8cff5cff0b96944c3bf1072cd08ce018329")

// EIP-4788: Beacon block root in the EVM
var BeaconRootsAddress = accounts.InternAddress(common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"))
// System contracts
var (
// SystemAddress is where the system-transaction is sent from as per EIP-4788
SystemAddress = accounts.InternAddress(common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe"))

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

// EIP-2935: Historical block hashes in state
var HistoryStorageAddress = accounts.InternAddress(common.HexToAddress("0x0000F90827F1C53a10cb7A02335B175320002935"))
// EIP-2935: Historical block hashes in state
HistoryStorageAddress = accounts.InternAddress(common.HexToAddress("0x0000F90827F1C53a10cb7A02335B175320002935"))

// EIP-7002: Execution layer triggerable withdrawals
var WithdrawalRequestAddress = accounts.InternAddress(common.HexToAddress("0x00000961Ef480Eb55e80D19ad83579A64c007002"))
// EIP-7002: Execution layer triggerable withdrawals
WithdrawalRequestAddress = accounts.InternAddress(common.HexToAddress("0x00000961Ef480Eb55e80D19ad83579A64c007002"))

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

// System log events
var (
// EIP-7708 - System logs emitted for ETH transfer and self-destruct balance burn
EthTransferLogEvent = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") // keccak256('Transfer(address,address,uint256)')
EthSelfDestructLogEvent = common.HexToHash("0x4bfaba3443c1a1836cd362418edc679fc96cae8449cbefccb6457cdf2c943083") // keccak256('Selfdestruct(address,uint256)')
)

// Gas discount table for BLS12-381 G1 and G2 multi exponentiation operations
var Bls12381MSMDiscountTableG1 = [128]uint64{1000, 949, 848, 797, 764, 750, 738, 728, 719, 712, 705, 698, 692, 687, 682, 677, 673, 669, 665, 661, 658, 654, 651, 648, 645, 642, 640, 637, 635, 632, 630, 627, 625, 623, 621, 619, 617, 615, 613, 611, 609, 608, 606, 604, 603, 601, 599, 598, 596, 595, 593, 592, 591, 589, 588, 586, 585, 584, 582, 581, 580, 579, 577, 576, 575, 574, 573, 572, 570, 569, 568, 567, 566, 565, 564, 563, 562, 561, 560, 559, 558, 557, 556, 555, 554, 553, 552, 551, 550, 549, 548, 547, 547, 546, 545, 544, 543, 542, 541, 540, 540, 539, 538, 537, 536, 536, 535, 534, 533, 532, 532, 531, 530, 529, 528, 528, 527, 526, 525, 525, 524, 523, 522, 522, 521, 520, 520, 519}
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
}

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 @@ -976,9 +976,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 @@ -1022,6 +1024,7 @@ func (result *execResult) finalize(prevReceipt *types.Receipt, engine rules.Engi
message.From(),
result.Coinbase,
&execResult,
rules,
)

// capture postApplyMessageFunc side affects
Expand All @@ -1043,7 +1046,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