Skip to content

Commit e98aef2

Browse files
committed
all: implement eip-7702 set code tx 30078
1 parent d49f590 commit e98aef2

17 files changed

+483
-27
lines changed

common/constants.all.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type constant struct {
6464
tipEpochHalving *big.Int
6565
eip1559Block *big.Int
6666
cancunBlock *big.Int
67+
pragueBlock *big.Int
6768

6869
trc21IssuerSMC Address
6970
xdcxListingSMC Address
@@ -98,6 +99,7 @@ var (
9899
TIPXDCXReceiverDisable = MaintnetConstant.tipXDCXReceiverDisable
99100
Eip1559Block = MaintnetConstant.eip1559Block
100101
CancunBlock = MaintnetConstant.cancunBlock
102+
PragueBlock = MaintnetConstant.pragueBlock
101103
TIPUpgradeReward = MaintnetConstant.tipUpgradeReward
102104
TipUpgradePenalty = MaintnetConstant.tipUpgradePenalty
103105
TIPEpochHalving = MaintnetConstant.tipEpochHalving
@@ -160,6 +162,7 @@ func CopyConstants(chainID uint64) {
160162
TIPXDCXReceiverDisable = c.tipXDCXReceiverDisable
161163
Eip1559Block = c.eip1559Block
162164
CancunBlock = c.cancunBlock
165+
PragueBlock = c.pragueBlock
163166
TIPUpgradeReward = c.tipUpgradeReward
164167
TipUpgradePenalty = c.tipUpgradePenalty
165168
TIPEpochHalving = c.tipEpochHalving

common/constants.devnet.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var DevnetConstant = constant{
2828
tipXDCXReceiverDisable: big.NewInt(0),
2929
eip1559Block: big.NewInt(32400),
3030
cancunBlock: big.NewInt(43200),
31+
pragueBlock: big.NewInt(9999999999),
3132
tipUpgradeReward: big.NewInt(9999999999),
3233
tipUpgradePenalty: big.NewInt(9999999999),
3334
tipEpochHalving: big.NewInt(9999999999),

common/constants.local.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var localConstant = constant{
2828
tipXDCXReceiverDisable: big.NewInt(0),
2929
eip1559Block: big.NewInt(0),
3030
cancunBlock: big.NewInt(0),
31+
pragueBlock: big.NewInt(9999999999),
3132
tipUpgradeReward: big.NewInt(999999999),
3233
tipUpgradePenalty: big.NewInt(999999999),
3334
tipEpochHalving: big.NewInt(999999999),

common/constants.mainnet.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var MaintnetConstant = constant{
2828
tipXDCXReceiverDisable: big.NewInt(80370900), // Target 2nd Oct 2024, safer to release after disable miner
2929
eip1559Block: big.NewInt(9999999999),
3030
cancunBlock: big.NewInt(9999999999),
31+
pragueBlock: big.NewInt(9999999999),
3132
tipUpgradeReward: big.NewInt(9999999999),
3233
tipUpgradePenalty: big.NewInt(9999999999),
3334
tipEpochHalving: big.NewInt(9999999999),

common/constants.testnet.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var TestnetConstant = constant{
2828
tipXDCXReceiverDisable: big.NewInt(66825000), // Target 26 Aug 2024
2929
eip1559Block: big.NewInt(71550000), // Target 14th Feb 2025
3030
cancunBlock: big.NewInt(71551800),
31+
pragueBlock: big.NewInt(9999999999),
3132
tipUpgradeReward: big.NewInt(9999999999),
3233
tipUpgradePenalty: big.NewInt(9999999999),
3334
tipEpochHalving: big.NewInt(9999999999),

core/error.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,25 @@ var (
9999
// ErrSenderNoEOA is returned if the sender of a transaction is a contract.
100100
ErrSenderNoEOA = errors.New("sender not an eoa")
101101

102-
ErrNotXDPoS = errors.New("XDPoS not found in config")
103-
104-
ErrNotFoundM1 = errors.New("list M1 not found ")
102+
// -- XDPoS errors --
105103

104+
ErrNotXDPoS = errors.New("XDPoS not found in config")
105+
ErrNotFoundM1 = errors.New("list M1 not found ")
106106
ErrStopPreparingBlock = errors.New("stop calculating a block not verified by M2")
107+
108+
// -- EIP-7702 errors --
109+
110+
// Message validation errors:
111+
ErrEmptyAuthList = errors.New("EIP-7702 transaction with empty auth list")
112+
ErrSetCodeTxCreate = errors.New("EIP-7702 transaction cannot be used to create contract")
113+
)
114+
115+
// EIP-7702 state transition errors.
116+
// Note these are just informational, and do not cause tx execution abort.
117+
var (
118+
ErrAuthorizationWrongChainID = errors.New("EIP-7702 authorization chain ID mismatch")
119+
ErrAuthorizationNonceOverflow = errors.New("EIP-7702 authorization nonce > 64 bit")
120+
ErrAuthorizationInvalidSignature = errors.New("EIP-7702 authorization has invalid signature")
121+
ErrAuthorizationDestinationHasCode = errors.New("EIP-7702 authorization destination is a contract")
122+
ErrAuthorizationNonceMismatch = errors.New("EIP-7702 authorization nonce does not match current account nonce")
107123
)

core/state/journal.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ func (j *journal) length() int {
8585
return len(j.entries)
8686
}
8787

88+
func (j *journal) setCode(address common.Address, prevCode []byte) {
89+
j.append(codeChange{
90+
account: address,
91+
prevCode: prevCode,
92+
})
93+
}
94+
8895
type (
8996
// Changes to the account trie.
9097
createObjectChange struct {

core/state/state_object.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"io"
2323
"math/big"
24+
"slices"
2425
"time"
2526

2627
"github.com/XinFinOrg/XDPoSChain/common"
@@ -437,16 +438,14 @@ func (s *stateObject) CodeSize(db Database) int {
437438
return size
438439
}
439440

440-
func (s *stateObject) SetCode(codeHash common.Hash, code []byte) {
441-
prevCode := s.Code(s.db.db)
442-
s.db.journal.append(codeChange{
443-
account: s.address,
444-
prevCode: prevCode,
445-
})
441+
func (s *stateObject) SetCode(codeHash common.Hash, code []byte) []byte {
442+
prevCode := slices.Clone(s.code)
443+
s.db.journal.setCode(s.address, prevCode)
446444
if s.db.logger != nil && s.db.logger.OnCodeChange != nil {
447445
s.db.logger.OnCodeChange(s.address, common.BytesToHash(s.CodeHash()), prevCode, codeHash, code)
448446
}
449447
s.setCode(codeHash, code)
448+
return prevCode
450449
}
451450

452451
func (s *stateObject) setCode(codeHash common.Hash, code []byte) {

core/state/statedb.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,12 @@ func (s *StateDB) SetNonce(addr common.Address, nonce uint64) {
405405
}
406406
}
407407

408-
func (s *StateDB) SetCode(addr common.Address, code []byte) {
408+
func (s *StateDB) SetCode(addr common.Address, code []byte) []byte {
409409
stateObject := s.GetOrNewStateObject(addr)
410410
if stateObject != nil {
411-
stateObject.SetCode(crypto.Keccak256Hash(code), code)
411+
return stateObject.SetCode(crypto.Keccak256Hash(code), code)
412412
}
413+
return nil
413414
}
414415

415416
func (s *StateDB) SetState(addr common.Address, key, value common.Hash) {

core/types/transaction.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ var (
5050

5151
// Transaction types.
5252
const (
53-
LegacyTxType = iota
54-
AccessListTxType
55-
DynamicFeeTxType
53+
LegacyTxType = 0x00
54+
AccessListTxType = 0x01
55+
DynamicFeeTxType = 0x02
56+
BlobTxType = 0x03
57+
SetCodeTxType = 0x04
5658
)
5759

5860
// Transaction is an Ethereum transaction.

0 commit comments

Comments
 (0)