From 71c28d8d2b2049738660a56effcfd0c70f8012d9 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 17 Dec 2024 15:16:17 +0100 Subject: [PATCH 01/10] 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 --- core/chain_makers.go | 65 +++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index 97c785d52b..26714845eb 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -293,6 +293,41 @@ func (b *BlockGen) OffsetTime(seconds int64) { b.header.Difficulty = b.engine.CalcDifficulty(b.cm, b.header.Time, b.parent.Header()) } +// ConsensusLayerRequests returns the EIP-7685 requests which have accumulated so far. +func (b *BlockGen) ConsensusLayerRequests() [][]byte { + return b.collectRequests(true) +} + +func (b *BlockGen) collectRequests(readonly bool) (requests [][]byte) { + statedb := b.statedb + if readonly { + // The system contracts clear themselves on a system-initiated read. + // When reading the requests mid-block, we don't want this behavior, so fork + // off the statedb before executing the system calls. + statedb = statedb.Copy() + } + + if b.cm.config.IsPrague(b.header.Number, b.header.Time) { + requests = [][]byte{} + // EIP-6110 deposits + var blockLogs []*types.Log + for _, r := range b.receipts { + blockLogs = append(blockLogs, r.Logs...) + } + if err := ParseDepositLogs(&requests, blockLogs, b.cm.config); err != nil { + panic(fmt.Sprintf("failed to parse deposit log: %v", err)) + } + // create EVM for system calls + blockContext := NewEVMBlockContext(b.header, b.cm, &b.header.Coinbase) + evm := vm.NewEVM(blockContext, statedb, b.cm.config, vm.Config{}) + // EIP-7002 + ProcessWithdrawalQueue(&requests, evm) + // EIP-7251 + ProcessConsolidationQueue(&requests, evm) + } + return requests +} + // GenerateChain creates a chain of n blocks. The first block's // parent will be the provided parent. db is used to store // intermediate states and should contain the parent's state trie. @@ -330,6 +365,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse b.header.Difficulty = big.NewInt(0) } } + // Mutate the state and block according to any hard-fork specs if daoBlock := config.DAOForkBlock; daoBlock != nil { limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange) @@ -342,30 +378,21 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse if config.DAOForkSupport && config.DAOForkBlock != nil && config.DAOForkBlock.Cmp(b.header.Number) == 0 { misc.ApplyDAOHardFork(statedb) } + + if config.IsPrague(b.header.Number, b.header.Time) { + // EIP-2935 + blockContext := NewEVMBlockContext(b.header, cm, &b.header.Coinbase) + blockContext.Random = &common.Hash{} // enable post-merge instruction set + evm := vm.NewEVM(blockContext, statedb, cm.config, vm.Config{}) + ProcessParentBlockHash(b.header.ParentHash, evm) + } + // Execute any user modifications to the block if gen != nil { gen(i, b) } - var requests [][]byte - if config.IsPrague(b.header.Number, b.header.Time) { - requests = [][]byte{} - // EIP-6110 deposits - var blockLogs []*types.Log - for _, r := range b.receipts { - blockLogs = append(blockLogs, r.Logs...) - } - if err := ParseDepositLogs(&requests, blockLogs, config); err != nil { - panic(fmt.Sprintf("failed to parse deposit log: %v", err)) - } - // create EVM for system calls - blockContext := NewEVMBlockContext(b.header, cm, &b.header.Coinbase) - evm := vm.NewEVM(blockContext, statedb, cm.config, vm.Config{}) - // EIP-7002 - ProcessWithdrawalQueue(&requests, evm) - // EIP-7251 - ProcessConsolidationQueue(&requests, evm) - } + requests := b.collectRequests(false) if requests != nil { reqHash := types.CalcRequestsHash(requests) b.header.RequestsHash = &reqHash From feaf1c95b13b78f06d93a840dde1585eba0e5608 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:26:03 +0100 Subject: [PATCH 02/10] build(deps): bump golang.org/x/crypto from 0.26.0 to 0.31.0 (#30921) Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.26.0 to 0.31.0. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 0f000636c3..35018fbe08 100644 --- a/go.mod +++ b/go.mod @@ -64,11 +64,11 @@ require ( github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/urfave/cli/v2 v2.25.7 go.uber.org/automaxprocs v1.5.2 - golang.org/x/crypto v0.26.0 + golang.org/x/crypto v0.31.0 golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa golang.org/x/sync v0.10.0 golang.org/x/sys v0.28.0 - golang.org/x/text v0.17.0 + golang.org/x/text v0.21.0 golang.org/x/time v0.5.0 golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d google.golang.org/protobuf v1.34.2 diff --git a/go.sum b/go.sum index e79fc6941c..ded07f4867 100644 --- a/go.sum +++ b/go.sum @@ -528,8 +528,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= -golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -698,8 +698,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From 5b9a3ea9d2930eb2228c5203d1afe40776e70af3 Mon Sep 17 00:00:00 2001 From: Martin HS Date: Tue, 17 Dec 2024 18:37:29 +0100 Subject: [PATCH 03/10] 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. --- core/vm/opcodes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/vm/opcodes.go b/core/vm/opcodes.go index 162be8f6c8..0820b20fb1 100644 --- a/core/vm/opcodes.go +++ b/core/vm/opcodes.go @@ -164,7 +164,7 @@ const ( // 0x80 range - dups. const ( - DUP1 = 0x80 + iota + DUP1 OpCode = 0x80 + iota DUP2 DUP3 DUP4 @@ -184,7 +184,7 @@ const ( // 0x90 range - swaps. const ( - SWAP1 = 0x90 + iota + SWAP1 OpCode = 0x90 + iota SWAP2 SWAP3 SWAP4 From 06dfb42365a33b4d47af9731892de2eb4e3b6f19 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 17 Dec 2024 19:47:10 +0100 Subject: [PATCH 04/10] 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` --- core/types/block.go | 2 +- core/types/gen_authorization.go | 16 ++++++++-------- core/types/gen_header_json.go | 4 ++-- core/types/tx_setcode.go | 2 ++ internal/ethapi/api.go | 2 +- internal/ethapi/transaction_args.go | 1 + 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index ad6c86398d..c3db4d89e8 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -105,7 +105,7 @@ type Header struct { ParentBeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"` // RequestsHash was added by EIP-7685 and is ignored in legacy headers. - RequestsHash *common.Hash `json:"requestsRoot" rlp:"optional"` + RequestsHash *common.Hash `json:"requestsHash" rlp:"optional"` } // field type overrides for gencodec diff --git a/core/types/gen_authorization.go b/core/types/gen_authorization.go index b598b64ff7..cc8fe138ea 100644 --- a/core/types/gen_authorization.go +++ b/core/types/gen_authorization.go @@ -20,16 +20,16 @@ func (a Authorization) MarshalJSON() ([]byte, error) { Address common.Address `json:"address" gencodec:"required"` Nonce hexutil.Uint64 `json:"nonce" gencodec:"required"` V hexutil.Uint64 `json:"v" gencodec:"required"` - R uint256.Int `json:"r" gencodec:"required"` - S uint256.Int `json:"s" gencodec:"required"` + R hexutil.U256 `json:"r" gencodec:"required"` + S hexutil.U256 `json:"s" gencodec:"required"` } var enc Authorization enc.ChainID = hexutil.Uint64(a.ChainID) enc.Address = a.Address enc.Nonce = hexutil.Uint64(a.Nonce) enc.V = hexutil.Uint64(a.V) - enc.R = a.R - enc.S = a.S + enc.R = hexutil.U256(a.R) + enc.S = hexutil.U256(a.S) return json.Marshal(&enc) } @@ -40,8 +40,8 @@ func (a *Authorization) UnmarshalJSON(input []byte) error { Address *common.Address `json:"address" gencodec:"required"` Nonce *hexutil.Uint64 `json:"nonce" gencodec:"required"` V *hexutil.Uint64 `json:"v" gencodec:"required"` - R *uint256.Int `json:"r" gencodec:"required"` - S *uint256.Int `json:"s" gencodec:"required"` + R *hexutil.U256 `json:"r" gencodec:"required"` + S *hexutil.U256 `json:"s" gencodec:"required"` } var dec Authorization if err := json.Unmarshal(input, &dec); err != nil { @@ -66,10 +66,10 @@ func (a *Authorization) UnmarshalJSON(input []byte) error { if dec.R == nil { return errors.New("missing required field 'r' for Authorization") } - a.R = *dec.R + a.R = uint256.Int(*dec.R) if dec.S == nil { return errors.New("missing required field 's' for Authorization") } - a.S = *dec.S + a.S = uint256.Int(*dec.S) return nil } diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index 322c5d5642..0af12500bd 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -36,7 +36,7 @@ func (h Header) MarshalJSON() ([]byte, error) { BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"` ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"` ParentBeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"` - RequestsHash *common.Hash `json:"requestsRoot" rlp:"optional"` + RequestsHash *common.Hash `json:"requestsHash" rlp:"optional"` Hash common.Hash `json:"hash"` } var enc Header @@ -88,7 +88,7 @@ func (h *Header) UnmarshalJSON(input []byte) error { BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"` ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"` ParentBeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"` - RequestsHash *common.Hash `json:"requestsRoot" rlp:"optional"` + RequestsHash *common.Hash `json:"requestsHash" rlp:"optional"` } var dec Header if err := json.Unmarshal(input, &dec); err != nil { diff --git a/core/types/tx_setcode.go b/core/types/tx_setcode.go index 0fea9a63a7..b251cd1812 100644 --- a/core/types/tx_setcode.go +++ b/core/types/tx_setcode.go @@ -83,6 +83,8 @@ type authorizationMarshaling struct { ChainID hexutil.Uint64 Nonce hexutil.Uint64 V hexutil.Uint64 + R hexutil.U256 + S hexutil.U256 } // SignAuth signs the provided authorization. diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 3f9ce46ddb..a983d4ecc9 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -895,7 +895,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} { result["parentBeaconBlockRoot"] = head.ParentBeaconRoot } if head.RequestsHash != nil { - result["requestsRoot"] = head.RequestsHash + result["requestsHash"] = head.RequestsHash } return result } diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index 3942540b04..89d1595681 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -466,6 +466,7 @@ func (args *TransactionArgs) ToMessage(baseFee *big.Int, skipNonceCheck, skipEoA AccessList: accessList, BlobGasFeeCap: (*big.Int)(args.BlobFeeCap), BlobHashes: args.BlobHashes, + AuthList: args.AuthorizationList, SkipNonceChecks: skipNonceCheck, SkipFromEOACheck: skipEoACheck, } From 1321a4252544c6451ed1867f6d2714f0fd6b30a9 Mon Sep 17 00:00:00 2001 From: Martin HS Date: Wed, 18 Dec 2024 00:18:36 +0100 Subject: [PATCH 05/10] cmd/evm: make evm statetest accept non-json files (#30927) This fixes a regression introduced recently. Without this fix, it's not possible to use statetests without `.json` suffix. This is problematic for goevmlab `minimizer`, which appends the suffix `.min` during processing. --- cmd/evm/blockrunner.go | 2 +- cmd/evm/main.go | 11 ++++++++--- cmd/evm/staterunner.go | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/evm/blockrunner.go b/cmd/evm/blockrunner.go index 2cb0531e28..9a04807b33 100644 --- a/cmd/evm/blockrunner.go +++ b/cmd/evm/blockrunner.go @@ -50,7 +50,7 @@ func blockTestCmd(ctx *cli.Context) error { return errors.New("path argument required") } var ( - collected = collectJSONFiles(path) + collected = collectFiles(path) results []testResult ) for _, fname := range collected { diff --git a/cmd/evm/main.go b/cmd/evm/main.go index 0e6f6fa5be..2079425416 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -262,10 +262,15 @@ func tracerFromFlags(ctx *cli.Context) *tracing.Hooks { } } -// collectJSONFiles walks the given path and accumulates all files with json -// extension. -func collectJSONFiles(path string) []string { +// collectFiles walks the given path. If the path is a directory, it will +// return a list of all accumulates all files with json extension. +// Otherwise (if path points to a file), it will return the path. +func collectFiles(path string) []string { var out []string + if info, err := os.Stat(path); err == nil && !info.IsDir() { + // User explicitly pointed out a file, ignore extension. + return []string{path} + } err := filepath.Walk(path, func(path string, info fs.FileInfo, err error) error { if err != nil { return err diff --git a/cmd/evm/staterunner.go b/cmd/evm/staterunner.go index 323b7d60ab..4c2dfeabc6 100644 --- a/cmd/evm/staterunner.go +++ b/cmd/evm/staterunner.go @@ -63,7 +63,7 @@ func stateTestCmd(ctx *cli.Context) error { // If path is provided, run the tests at that path. if len(path) != 0 { var ( - collected = collectJSONFiles(path) + collected = collectFiles(path) results []testResult ) for _, fname := range collected { From 9d4b29f291652c1f681afd616d4427bfedf08c7a Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 18 Dec 2024 19:10:53 +0100 Subject: [PATCH 06/10] 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. --- core/blockchain_test.go | 10 +++--- core/state_processor_test.go | 2 +- core/state_transition.go | 8 ++--- core/types/gen_authorization.go | 48 +++++++++++++-------------- core/types/transaction.go | 2 +- core/types/transaction_marshalling.go | 34 +++++++++---------- core/types/tx_setcode.go | 36 +++++++++----------- internal/ethapi/api.go | 46 ++++++++++++------------- internal/ethapi/transaction_args.go | 4 +-- tests/state_test_util.go | 6 ++-- 10 files changed, 95 insertions(+), 101 deletions(-) diff --git a/core/blockchain_test.go b/core/blockchain_test.go index a54a907766..fc0e3d8446 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -4273,16 +4273,16 @@ func TestEIP7702(t *testing.T) { // 1. tx -> addr1 which is delegated to 0xaaaa // 2. addr1:0xaaaa calls into addr2:0xbbbb // 3. addr2:0xbbbb writes to storage - auth1, _ := types.SignAuth(types.Authorization{ + auth1, _ := types.SignSetCode(key1, types.SetCodeAuthorization{ ChainID: gspec.Config.ChainID.Uint64(), Address: aa, Nonce: 1, - }, key1) - auth2, _ := types.SignAuth(types.Authorization{ + }) + auth2, _ := types.SignSetCode(key2, types.SetCodeAuthorization{ ChainID: 0, Address: bb, Nonce: 0, - }, key2) + }) _, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) { b.SetCoinbase(aa) @@ -4293,7 +4293,7 @@ func TestEIP7702(t *testing.T) { Gas: 500000, GasFeeCap: uint256.MustFromBig(newGwei(5)), GasTipCap: uint256.NewInt(2), - AuthList: []types.Authorization{auth1, auth2}, + AuthList: []types.SetCodeAuthorization{auth1, auth2}, } tx := types.MustSignNewTx(key1, signer, txdata) b.AddTx(tx) diff --git a/core/state_processor_test.go b/core/state_processor_test.go index e8d8c2ca2e..2f841eb64a 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -111,7 +111,7 @@ func TestStateProcessorErrors(t *testing.T) { } return tx } - var mkSetCodeTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap *big.Int, authlist []types.Authorization) *types.Transaction { + var mkSetCodeTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap *big.Int, authlist []types.SetCodeAuthorization) *types.Transaction { tx, err := types.SignTx(types.NewTx(&types.SetCodeTx{ Nonce: nonce, GasTipCap: uint256.MustFromBig(gasTipCap), diff --git a/core/state_transition.go b/core/state_transition.go index 58728e470e..1f6abed91d 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -67,7 +67,7 @@ func (result *ExecutionResult) Revert() []byte { } // IntrinsicGas computes the 'intrinsic gas' for a message with the given data. -func IntrinsicGas(data []byte, accessList types.AccessList, authList []types.Authorization, isContractCreation, isHomestead, isEIP2028, isEIP3860 bool) (uint64, error) { +func IntrinsicGas(data []byte, accessList types.AccessList, authList []types.SetCodeAuthorization, isContractCreation, isHomestead, isEIP2028, isEIP3860 bool) (uint64, error) { // Set the starting gas for the raw transaction var gas uint64 if isContractCreation && isHomestead { @@ -143,7 +143,7 @@ type Message struct { AccessList types.AccessList BlobGasFeeCap *big.Int BlobHashes []common.Hash - AuthList []types.Authorization + AuthList []types.SetCodeAuthorization // When SkipNonceChecks is true, the message nonce is not checked against the // account nonce in state. @@ -528,7 +528,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { } // validateAuthorization validates an EIP-7702 authorization against the state. -func (st *stateTransition) validateAuthorization(auth *types.Authorization) (authority common.Address, err error) { +func (st *stateTransition) validateAuthorization(auth *types.SetCodeAuthorization) (authority common.Address, err error) { // Verify chain ID is 0 or equal to current chain ID. if auth.ChainID != 0 && st.evm.ChainConfig().ChainID.Uint64() != auth.ChainID { return authority, ErrAuthorizationWrongChainID @@ -559,7 +559,7 @@ func (st *stateTransition) validateAuthorization(auth *types.Authorization) (aut } // applyAuthorization applies an EIP-7702 code delegation to the state. -func (st *stateTransition) applyAuthorization(msg *Message, auth *types.Authorization) error { +func (st *stateTransition) applyAuthorization(msg *Message, auth *types.SetCodeAuthorization) error { authority, err := st.validateAuthorization(auth) if err != nil { return err diff --git a/core/types/gen_authorization.go b/core/types/gen_authorization.go index cc8fe138ea..c9ab3590bf 100644 --- a/core/types/gen_authorization.go +++ b/core/types/gen_authorization.go @@ -14,8 +14,8 @@ import ( var _ = (*authorizationMarshaling)(nil) // MarshalJSON marshals as JSON. -func (a Authorization) MarshalJSON() ([]byte, error) { - type Authorization struct { +func (s SetCodeAuthorization) MarshalJSON() ([]byte, error) { + type SetCodeAuthorization struct { ChainID hexutil.Uint64 `json:"chainId" gencodec:"required"` Address common.Address `json:"address" gencodec:"required"` Nonce hexutil.Uint64 `json:"nonce" gencodec:"required"` @@ -23,19 +23,19 @@ func (a Authorization) MarshalJSON() ([]byte, error) { R hexutil.U256 `json:"r" gencodec:"required"` S hexutil.U256 `json:"s" gencodec:"required"` } - var enc Authorization - enc.ChainID = hexutil.Uint64(a.ChainID) - enc.Address = a.Address - enc.Nonce = hexutil.Uint64(a.Nonce) - enc.V = hexutil.Uint64(a.V) - enc.R = hexutil.U256(a.R) - enc.S = hexutil.U256(a.S) + var enc SetCodeAuthorization + enc.ChainID = hexutil.Uint64(s.ChainID) + enc.Address = s.Address + enc.Nonce = hexutil.Uint64(s.Nonce) + enc.V = hexutil.Uint64(s.V) + enc.R = hexutil.U256(s.R) + enc.S = hexutil.U256(s.S) return json.Marshal(&enc) } // UnmarshalJSON unmarshals from JSON. -func (a *Authorization) UnmarshalJSON(input []byte) error { - type Authorization struct { +func (s *SetCodeAuthorization) UnmarshalJSON(input []byte) error { + type SetCodeAuthorization struct { ChainID *hexutil.Uint64 `json:"chainId" gencodec:"required"` Address *common.Address `json:"address" gencodec:"required"` Nonce *hexutil.Uint64 `json:"nonce" gencodec:"required"` @@ -43,33 +43,33 @@ func (a *Authorization) UnmarshalJSON(input []byte) error { R *hexutil.U256 `json:"r" gencodec:"required"` S *hexutil.U256 `json:"s" gencodec:"required"` } - var dec Authorization + var dec SetCodeAuthorization if err := json.Unmarshal(input, &dec); err != nil { return err } if dec.ChainID == nil { - return errors.New("missing required field 'chainId' for Authorization") + return errors.New("missing required field 'chainId' for SetCodeAuthorization") } - a.ChainID = uint64(*dec.ChainID) + s.ChainID = uint64(*dec.ChainID) if dec.Address == nil { - return errors.New("missing required field 'address' for Authorization") + return errors.New("missing required field 'address' for SetCodeAuthorization") } - a.Address = *dec.Address + s.Address = *dec.Address if dec.Nonce == nil { - return errors.New("missing required field 'nonce' for Authorization") + return errors.New("missing required field 'nonce' for SetCodeAuthorization") } - a.Nonce = uint64(*dec.Nonce) + s.Nonce = uint64(*dec.Nonce) if dec.V == nil { - return errors.New("missing required field 'v' for Authorization") + return errors.New("missing required field 'v' for SetCodeAuthorization") } - a.V = uint8(*dec.V) + s.V = uint8(*dec.V) if dec.R == nil { - return errors.New("missing required field 'r' for Authorization") + return errors.New("missing required field 'r' for SetCodeAuthorization") } - a.R = uint256.Int(*dec.R) + s.R = uint256.Int(*dec.R) if dec.S == nil { - return errors.New("missing required field 's' for Authorization") + return errors.New("missing required field 's' for SetCodeAuthorization") } - a.S = uint256.Int(*dec.S) + s.S = uint256.Int(*dec.S) return nil } diff --git a/core/types/transaction.go b/core/types/transaction.go index b5fb3e2db2..24b110fa18 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -475,7 +475,7 @@ func (tx *Transaction) WithBlobTxSidecar(sideCar *BlobTxSidecar) *Transaction { } // AuthList returns the authorizations list of the transaction. -func (tx *Transaction) AuthList() []Authorization { +func (tx *Transaction) AuthList() []SetCodeAuthorization { setcodetx, ok := tx.inner.(*SetCodeTx) if !ok { return nil diff --git a/core/types/transaction_marshalling.go b/core/types/transaction_marshalling.go index 4176a8220c..993d633c6f 100644 --- a/core/types/transaction_marshalling.go +++ b/core/types/transaction_marshalling.go @@ -31,23 +31,23 @@ import ( type txJSON struct { Type hexutil.Uint64 `json:"type"` - ChainID *hexutil.Big `json:"chainId,omitempty"` - Nonce *hexutil.Uint64 `json:"nonce"` - To *common.Address `json:"to"` - Gas *hexutil.Uint64 `json:"gas"` - GasPrice *hexutil.Big `json:"gasPrice"` - MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas"` - MaxFeePerGas *hexutil.Big `json:"maxFeePerGas"` - MaxFeePerBlobGas *hexutil.Big `json:"maxFeePerBlobGas,omitempty"` - Value *hexutil.Big `json:"value"` - Input *hexutil.Bytes `json:"input"` - AccessList *AccessList `json:"accessList,omitempty"` - BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"` - AuthorizationList []Authorization `json:"authorizationList,omitempty"` - V *hexutil.Big `json:"v"` - R *hexutil.Big `json:"r"` - S *hexutil.Big `json:"s"` - YParity *hexutil.Uint64 `json:"yParity,omitempty"` + ChainID *hexutil.Big `json:"chainId,omitempty"` + Nonce *hexutil.Uint64 `json:"nonce"` + To *common.Address `json:"to"` + Gas *hexutil.Uint64 `json:"gas"` + GasPrice *hexutil.Big `json:"gasPrice"` + MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas"` + MaxFeePerGas *hexutil.Big `json:"maxFeePerGas"` + MaxFeePerBlobGas *hexutil.Big `json:"maxFeePerBlobGas,omitempty"` + Value *hexutil.Big `json:"value"` + Input *hexutil.Bytes `json:"input"` + AccessList *AccessList `json:"accessList,omitempty"` + BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"` + AuthorizationList []SetCodeAuthorization `json:"authorizationList,omitempty"` + V *hexutil.Big `json:"v"` + R *hexutil.Big `json:"r"` + S *hexutil.Big `json:"s"` + YParity *hexutil.Uint64 `json:"yParity,omitempty"` // Blob transaction sidecar encoding: Blobs []kzg4844.Blob `json:"blobs,omitempty"` diff --git a/core/types/tx_setcode.go b/core/types/tx_setcode.go index b251cd1812..1be90df615 100644 --- a/core/types/tx_setcode.go +++ b/core/types/tx_setcode.go @@ -58,7 +58,7 @@ type SetCodeTx struct { Value *uint256.Int Data []byte AccessList AccessList - AuthList []Authorization + AuthList []SetCodeAuthorization // Signature values V *uint256.Int `json:"v" gencodec:"required"` @@ -66,10 +66,10 @@ type SetCodeTx struct { S *uint256.Int `json:"s" gencodec:"required"` } -//go:generate go run github.com/fjl/gencodec -type Authorization -field-override authorizationMarshaling -out gen_authorization.go +//go:generate go run github.com/fjl/gencodec -type SetCodeAuthorization -field-override authorizationMarshaling -out gen_authorization.go -// Authorization is an authorization from an account to deploy code at its address. -type Authorization struct { +// SetCodeAuthorization is an authorization from an account to deploy code at its address. +type SetCodeAuthorization struct { ChainID uint64 `json:"chainId" gencodec:"required"` Address common.Address `json:"address" gencodec:"required"` Nonce uint64 `json:"nonce" gencodec:"required"` @@ -87,31 +87,25 @@ type authorizationMarshaling struct { S hexutil.U256 } -// SignAuth signs the provided authorization. -func SignAuth(auth Authorization, prv *ecdsa.PrivateKey) (Authorization, error) { +// SignSetCode creates a signed the SetCode authorization. +func SignSetCode(prv *ecdsa.PrivateKey, auth SetCodeAuthorization) (SetCodeAuthorization, error) { sighash := auth.sigHash() sig, err := crypto.Sign(sighash[:], prv) if err != nil { - return Authorization{}, err + return SetCodeAuthorization{}, err } - return auth.withSignature(sig), nil -} - -// withSignature updates the signature of an Authorization to be equal the -// decoded signature provided in sig. -func (a *Authorization) withSignature(sig []byte) Authorization { r, s, _ := decodeSignature(sig) - return Authorization{ - ChainID: a.ChainID, - Address: a.Address, - Nonce: a.Nonce, + return SetCodeAuthorization{ + ChainID: auth.ChainID, + Address: auth.Address, + Nonce: auth.Nonce, V: sig[64], R: *uint256.MustFromBig(r), S: *uint256.MustFromBig(s), - } + }, nil } -func (a *Authorization) sigHash() common.Hash { +func (a *SetCodeAuthorization) sigHash() common.Hash { return prefixedRlpHash(0x05, []any{ a.ChainID, a.Address, @@ -120,7 +114,7 @@ func (a *Authorization) sigHash() common.Hash { } // Authority recovers the the authorizing account of an authorization. -func (a *Authorization) Authority() (common.Address, error) { +func (a *SetCodeAuthorization) Authority() (common.Address, error) { sighash := a.sigHash() if !crypto.ValidateSignatureValues(a.V, a.R.ToBig(), a.S.ToBig(), true) { return common.Address{}, ErrInvalidSig @@ -152,7 +146,7 @@ func (tx *SetCodeTx) copy() TxData { Gas: tx.Gas, // These are copied below. AccessList: make(AccessList, len(tx.AccessList)), - AuthList: make([]Authorization, len(tx.AuthList)), + AuthList: make([]SetCodeAuthorization, len(tx.AuthList)), Value: new(uint256.Int), ChainID: tx.ChainID, GasTipCap: new(uint256.Int), diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index a983d4ecc9..2ba27f43a8 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -937,29 +937,29 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param // RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction type RPCTransaction struct { - BlockHash *common.Hash `json:"blockHash"` - BlockNumber *hexutil.Big `json:"blockNumber"` - From common.Address `json:"from"` - Gas hexutil.Uint64 `json:"gas"` - GasPrice *hexutil.Big `json:"gasPrice"` - GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"` - GasTipCap *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"` - MaxFeePerBlobGas *hexutil.Big `json:"maxFeePerBlobGas,omitempty"` - Hash common.Hash `json:"hash"` - Input hexutil.Bytes `json:"input"` - Nonce hexutil.Uint64 `json:"nonce"` - To *common.Address `json:"to"` - TransactionIndex *hexutil.Uint64 `json:"transactionIndex"` - Value *hexutil.Big `json:"value"` - Type hexutil.Uint64 `json:"type"` - Accesses *types.AccessList `json:"accessList,omitempty"` - ChainID *hexutil.Big `json:"chainId,omitempty"` - BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"` - AuthorizationList []types.Authorization `json:"authorizationList,omitempty"` - V *hexutil.Big `json:"v"` - R *hexutil.Big `json:"r"` - S *hexutil.Big `json:"s"` - YParity *hexutil.Uint64 `json:"yParity,omitempty"` + BlockHash *common.Hash `json:"blockHash"` + BlockNumber *hexutil.Big `json:"blockNumber"` + From common.Address `json:"from"` + Gas hexutil.Uint64 `json:"gas"` + GasPrice *hexutil.Big `json:"gasPrice"` + GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"` + GasTipCap *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"` + MaxFeePerBlobGas *hexutil.Big `json:"maxFeePerBlobGas,omitempty"` + Hash common.Hash `json:"hash"` + Input hexutil.Bytes `json:"input"` + Nonce hexutil.Uint64 `json:"nonce"` + To *common.Address `json:"to"` + TransactionIndex *hexutil.Uint64 `json:"transactionIndex"` + Value *hexutil.Big `json:"value"` + Type hexutil.Uint64 `json:"type"` + Accesses *types.AccessList `json:"accessList,omitempty"` + ChainID *hexutil.Big `json:"chainId,omitempty"` + BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"` + AuthorizationList []types.SetCodeAuthorization `json:"authorizationList,omitempty"` + V *hexutil.Big `json:"v"` + R *hexutil.Big `json:"r"` + S *hexutil.Big `json:"s"` + YParity *hexutil.Uint64 `json:"yParity,omitempty"` } // newRPCTransaction returns a transaction that will serialize to the RPC diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index 89d1595681..a9b563de74 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -73,7 +73,7 @@ type TransactionArgs struct { Proofs []kzg4844.Proof `json:"proofs"` // For SetCodeTxType - AuthorizationList []types.Authorization `json:"authorizationList"` + AuthorizationList []types.SetCodeAuthorization `json:"authorizationList"` // This configures whether blobs are allowed to be passed. blobSidecarAllowed bool @@ -497,7 +497,7 @@ func (args *TransactionArgs) ToTransaction(defaultType int) *types.Transaction { if args.AccessList != nil { al = *args.AccessList } - authList := []types.Authorization{} + authList := []types.SetCodeAuthorization{} if args.AuthorizationList != nil { authList = args.AuthorizationList } diff --git a/tests/state_test_util.go b/tests/state_test_util.go index e735ce2fb8..266bd7fd23 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -441,11 +441,11 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (*core.Mess if gasPrice == nil { return nil, errors.New("no gas price provided") } - var authList []types.Authorization + var authList []types.SetCodeAuthorization if tx.AuthorizationList != nil { - authList = make([]types.Authorization, len(tx.AuthorizationList)) + authList = make([]types.SetCodeAuthorization, len(tx.AuthorizationList)) for i, auth := range tx.AuthorizationList { - authList[i] = types.Authorization{ + authList[i] = types.SetCodeAuthorization{ ChainID: auth.ChainID, Address: auth.Address, Nonce: auth.Nonce, From 73a4ecf675f6714e1fdf49904ce9426841de2e02 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 18 Dec 2024 19:46:15 +0100 Subject: [PATCH 07/10] core/types: rename SetCodeAuthorization 'v' to 'yParity' The API spec requires the name yParity. --- core/types/gen_authorization.go | 6 +++--- core/types/tx_setcode.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/types/gen_authorization.go b/core/types/gen_authorization.go index c9ab3590bf..be5467c50d 100644 --- a/core/types/gen_authorization.go +++ b/core/types/gen_authorization.go @@ -19,7 +19,7 @@ func (s SetCodeAuthorization) MarshalJSON() ([]byte, error) { ChainID hexutil.Uint64 `json:"chainId" gencodec:"required"` Address common.Address `json:"address" gencodec:"required"` Nonce hexutil.Uint64 `json:"nonce" gencodec:"required"` - V hexutil.Uint64 `json:"v" gencodec:"required"` + V hexutil.Uint64 `json:"yParity" gencodec:"required"` R hexutil.U256 `json:"r" gencodec:"required"` S hexutil.U256 `json:"s" gencodec:"required"` } @@ -39,7 +39,7 @@ func (s *SetCodeAuthorization) UnmarshalJSON(input []byte) error { ChainID *hexutil.Uint64 `json:"chainId" gencodec:"required"` Address *common.Address `json:"address" gencodec:"required"` Nonce *hexutil.Uint64 `json:"nonce" gencodec:"required"` - V *hexutil.Uint64 `json:"v" gencodec:"required"` + V *hexutil.Uint64 `json:"yParity" gencodec:"required"` R *hexutil.U256 `json:"r" gencodec:"required"` S *hexutil.U256 `json:"s" gencodec:"required"` } @@ -60,7 +60,7 @@ func (s *SetCodeAuthorization) UnmarshalJSON(input []byte) error { } s.Nonce = uint64(*dec.Nonce) if dec.V == nil { - return errors.New("missing required field 'v' for SetCodeAuthorization") + return errors.New("missing required field 'yParity' for SetCodeAuthorization") } s.V = uint8(*dec.V) if dec.R == nil { diff --git a/core/types/tx_setcode.go b/core/types/tx_setcode.go index 1be90df615..f14ae3bc9d 100644 --- a/core/types/tx_setcode.go +++ b/core/types/tx_setcode.go @@ -73,7 +73,7 @@ type SetCodeAuthorization struct { ChainID uint64 `json:"chainId" gencodec:"required"` Address common.Address `json:"address" gencodec:"required"` Nonce uint64 `json:"nonce" gencodec:"required"` - V uint8 `json:"v" gencodec:"required"` + V uint8 `json:"yParity" gencodec:"required"` R uint256.Int `json:"r" gencodec:"required"` S uint256.Int `json:"s" gencodec:"required"` } From f861535f1ecc59ad279c35f77f3962efc14dcf98 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 18 Dec 2024 20:17:49 +0100 Subject: [PATCH 08/10] cmd/evm: update tests for SetCodeAuthorization JSON encoding change (#30936) Fixing a regression introduced by 73a4ecf675f6, which I accidentally pushed to the master branch directly. --- cmd/evm/testdata/33/txs.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/evm/testdata/33/txs.json b/cmd/evm/testdata/33/txs.json index 9c4db138c8..c96cdb03ea 100644 --- a/cmd/evm/testdata/33/txs.json +++ b/cmd/evm/testdata/33/txs.json @@ -16,7 +16,7 @@ "chainId": "0x1", "address": "0x000000000000000000000000000000000000aaaa", "nonce": "0x1", - "v": "0x1", + "yParity": "0x1", "r": "0xf7e3e597fc097e71ed6c26b14b25e5395bc8510d58b9136af439e12715f2d721", "s": "0x6cf7c3d7939bfdb784373effc0ebb0bd7549691a513f395e3cdabf8602724987" }, @@ -24,7 +24,7 @@ "chainId": "0x0", "address": "0x000000000000000000000000000000000000bbbb", "nonce": "0x0", - "v": "0x1", + "yParity": "0x1", "r": "0x5011890f198f0356a887b0779bde5afa1ed04e6acb1e3f37f8f18c7b6f521b98", "s": "0x56c3fa3456b103f3ef4a0acb4b647b9cab9ec4bc68fbcdf1e10b49fb2bcbcf61" } From f1e6372eeadf02f46e0930eeb58910b84f3655dd Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 19 Dec 2024 10:06:33 +0100 Subject: [PATCH 09/10] 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. --- cmd/evm/internal/t8ntool/transaction.go | 2 +- core/state_transition.go | 64 ++++++++++++------------- core/txpool/validation.go | 2 +- core/types/transaction.go | 4 +- core/types/transaction_signing.go | 2 +- eth/tracers/native/prestate.go | 2 +- internal/ethapi/api.go | 2 +- internal/ethapi/transaction_args.go | 30 ++++++------ tests/state_test_util.go | 26 +++++----- tests/transaction_test_util.go | 2 +- 10 files changed, 68 insertions(+), 68 deletions(-) diff --git a/cmd/evm/internal/t8ntool/transaction.go b/cmd/evm/internal/t8ntool/transaction.go index 64e21b24fd..6dac4301dd 100644 --- a/cmd/evm/internal/t8ntool/transaction.go +++ b/cmd/evm/internal/t8ntool/transaction.go @@ -133,7 +133,7 @@ func Transaction(ctx *cli.Context) error { r.Address = sender } // Check intrinsic gas - if gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.AuthList(), tx.To() == nil, + if gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil, chainConfig.IsHomestead(new(big.Int)), chainConfig.IsIstanbul(new(big.Int)), chainConfig.IsShanghai(new(big.Int), 0)); err != nil { r.Error = err results = append(results, r) diff --git a/core/state_transition.go b/core/state_transition.go index 1f6abed91d..93d72d16b7 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -131,19 +131,19 @@ func toWordSize(size uint64) uint64 { // A Message contains the data derived from a single transaction that is relevant to state // processing. type Message struct { - To *common.Address - From common.Address - Nonce uint64 - Value *big.Int - GasLimit uint64 - GasPrice *big.Int - GasFeeCap *big.Int - GasTipCap *big.Int - Data []byte - AccessList types.AccessList - BlobGasFeeCap *big.Int - BlobHashes []common.Hash - AuthList []types.SetCodeAuthorization + To *common.Address + From common.Address + Nonce uint64 + Value *big.Int + GasLimit uint64 + GasPrice *big.Int + GasFeeCap *big.Int + GasTipCap *big.Int + Data []byte + AccessList types.AccessList + BlobGasFeeCap *big.Int + BlobHashes []common.Hash + SetCodeAuthorizations []types.SetCodeAuthorization // When SkipNonceChecks is true, the message nonce is not checked against the // account nonce in state. @@ -157,20 +157,20 @@ type Message struct { // TransactionToMessage converts a transaction into a Message. func TransactionToMessage(tx *types.Transaction, s types.Signer, baseFee *big.Int) (*Message, error) { msg := &Message{ - Nonce: tx.Nonce(), - GasLimit: tx.Gas(), - GasPrice: new(big.Int).Set(tx.GasPrice()), - GasFeeCap: new(big.Int).Set(tx.GasFeeCap()), - GasTipCap: new(big.Int).Set(tx.GasTipCap()), - To: tx.To(), - Value: tx.Value(), - Data: tx.Data(), - AccessList: tx.AccessList(), - AuthList: tx.AuthList(), - SkipNonceChecks: false, - SkipFromEOACheck: false, - BlobHashes: tx.BlobHashes(), - BlobGasFeeCap: tx.BlobGasFeeCap(), + Nonce: tx.Nonce(), + GasLimit: tx.Gas(), + GasPrice: new(big.Int).Set(tx.GasPrice()), + GasFeeCap: new(big.Int).Set(tx.GasFeeCap()), + GasTipCap: new(big.Int).Set(tx.GasTipCap()), + To: tx.To(), + Value: tx.Value(), + Data: tx.Data(), + AccessList: tx.AccessList(), + SetCodeAuthorizations: tx.SetCodeAuthorizations(), + SkipNonceChecks: false, + SkipFromEOACheck: false, + BlobHashes: tx.BlobHashes(), + BlobGasFeeCap: tx.BlobGasFeeCap(), } // If baseFee provided, set gasPrice to effectiveGasPrice. if baseFee != nil { @@ -372,11 +372,11 @@ func (st *stateTransition) preCheck() error { } } // Check that EIP-7702 authorization list signatures are well formed. - if msg.AuthList != nil { + if msg.SetCodeAuthorizations != nil { if msg.To == nil { return fmt.Errorf("%w (sender %v)", ErrSetCodeTxCreate, msg.From) } - if len(msg.AuthList) == 0 { + if len(msg.SetCodeAuthorizations) == 0 { return fmt.Errorf("%w (sender %v)", ErrEmptyAuthList, msg.From) } } @@ -417,7 +417,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { ) // Check clauses 4-5, subtract intrinsic gas if everything is correct - gas, err := IntrinsicGas(msg.Data, msg.AccessList, msg.AuthList, contractCreation, rules.IsHomestead, rules.IsIstanbul, rules.IsShanghai) + gas, err := IntrinsicGas(msg.Data, msg.AccessList, msg.SetCodeAuthorizations, contractCreation, rules.IsHomestead, rules.IsIstanbul, rules.IsShanghai) if err != nil { return nil, err } @@ -467,8 +467,8 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { st.state.SetNonce(msg.From, st.state.GetNonce(msg.From)+1) // Apply EIP-7702 authorizations. - if msg.AuthList != nil { - for _, auth := range msg.AuthList { + if msg.SetCodeAuthorizations != nil { + for _, auth := range msg.SetCodeAuthorizations { // Note errors are ignored, we simply skip invalid authorizations here. st.applyAuthorization(msg, &auth) } diff --git a/core/txpool/validation.go b/core/txpool/validation.go index 908945471d..412418dcc9 100644 --- a/core/txpool/validation.go +++ b/core/txpool/validation.go @@ -108,7 +108,7 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types } // Ensure the transaction has more gas than the bare minimum needed to cover // the transaction metadata - intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.AuthList(), tx.To() == nil, true, opts.Config.IsIstanbul(head.Number), opts.Config.IsShanghai(head.Number, head.Time)) + intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil, true, opts.Config.IsIstanbul(head.Number), opts.Config.IsShanghai(head.Number, head.Time)) if err != nil { return err } diff --git a/core/types/transaction.go b/core/types/transaction.go index 24b110fa18..35dc1ea3f9 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -474,8 +474,8 @@ func (tx *Transaction) WithBlobTxSidecar(sideCar *BlobTxSidecar) *Transaction { return cpy } -// AuthList returns the authorizations list of the transaction. -func (tx *Transaction) AuthList() []SetCodeAuthorization { +// SetCodeAuthorizations returns the authorizations list of the transaction. +func (tx *Transaction) SetCodeAuthorizations() []SetCodeAuthorization { setcodetx, ok := tx.inner.(*SetCodeTx) if !ok { return nil diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index 78fa2fc8ef..d72643b4a8 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -245,7 +245,7 @@ func (s pragueSigner) Hash(tx *Transaction) common.Hash { tx.Value(), tx.Data(), tx.AccessList(), - tx.AuthList(), + tx.SetCodeAuthorizations(), }) } diff --git a/eth/tracers/native/prestate.go b/eth/tracers/native/prestate.go index 5776275c2b..e04b77f61f 100644 --- a/eth/tracers/native/prestate.go +++ b/eth/tracers/native/prestate.go @@ -161,7 +161,7 @@ func (t *prestateTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction t.lookupAccount(env.Coinbase) // Add accounts with authorizations to the prestate before they get applied. - for _, auth := range tx.AuthList() { + for _, auth := range tx.SetCodeAuthorizations() { addr, err := auth.Authority() if err != nil { continue diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 2ba27f43a8..d9cec560ea 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1049,7 +1049,7 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber } else { result.GasPrice = (*hexutil.Big)(tx.GasFeeCap()) } - result.AuthorizationList = tx.AuthList() + result.AuthorizationList = tx.SetCodeAuthorizations() } return result } diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index a9b563de74..a39a6666f4 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -454,21 +454,21 @@ func (args *TransactionArgs) ToMessage(baseFee *big.Int, skipNonceCheck, skipEoA accessList = *args.AccessList } return &core.Message{ - From: args.from(), - To: args.To, - Value: (*big.Int)(args.Value), - Nonce: uint64(*args.Nonce), - GasLimit: uint64(*args.Gas), - GasPrice: gasPrice, - GasFeeCap: gasFeeCap, - GasTipCap: gasTipCap, - Data: args.data(), - AccessList: accessList, - BlobGasFeeCap: (*big.Int)(args.BlobFeeCap), - BlobHashes: args.BlobHashes, - AuthList: args.AuthorizationList, - SkipNonceChecks: skipNonceCheck, - SkipFromEOACheck: skipEoACheck, + From: args.from(), + To: args.To, + Value: (*big.Int)(args.Value), + Nonce: uint64(*args.Nonce), + GasLimit: uint64(*args.Gas), + GasPrice: gasPrice, + GasFeeCap: gasFeeCap, + GasTipCap: gasTipCap, + Data: args.data(), + AccessList: accessList, + BlobGasFeeCap: (*big.Int)(args.BlobFeeCap), + BlobHashes: args.BlobHashes, + SetCodeAuthorizations: args.AuthorizationList, + SkipNonceChecks: skipNonceCheck, + SkipFromEOACheck: skipEoACheck, } } diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 266bd7fd23..6e66bbaa72 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -457,19 +457,19 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (*core.Mess } msg := &core.Message{ - From: from, - To: to, - Nonce: tx.Nonce, - Value: value, - GasLimit: gasLimit, - GasPrice: gasPrice, - GasFeeCap: tx.MaxFeePerGas, - GasTipCap: tx.MaxPriorityFeePerGas, - Data: data, - AccessList: accessList, - BlobHashes: tx.BlobVersionedHashes, - BlobGasFeeCap: tx.BlobGasFeeCap, - AuthList: authList, + From: from, + To: to, + Nonce: tx.Nonce, + Value: value, + GasLimit: gasLimit, + GasPrice: gasPrice, + GasFeeCap: tx.MaxFeePerGas, + GasTipCap: tx.MaxPriorityFeePerGas, + Data: data, + AccessList: accessList, + BlobHashes: tx.BlobVersionedHashes, + BlobGasFeeCap: tx.BlobGasFeeCap, + SetCodeAuthorizations: authList, } return msg, nil } diff --git a/tests/transaction_test_util.go b/tests/transaction_test_util.go index 4da27ff943..55b76df89c 100644 --- a/tests/transaction_test_util.go +++ b/tests/transaction_test_util.go @@ -59,7 +59,7 @@ func (tt *TransactionTest) Run(config *params.ChainConfig) error { return nil, nil, err } // Intrinsic gas - requiredGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.AuthList(), tx.To() == nil, isHomestead, isIstanbul, false) + requiredGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), tx.To() == nil, isHomestead, isIstanbul, false) if err != nil { return nil, nil, err } From 341647f1865dab437a690dc1424ba71495de2dd8 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 19 Dec 2024 16:03:05 +0100 Subject: [PATCH 10/10] params: update system contracts for prague devnet-5 (#30938) --- params/protocol_params.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/params/protocol_params.go b/params/protocol_params.go index 4d2baf8054..b46e8d66b2 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -200,14 +200,14 @@ var ( BeaconRootsCode = common.FromHex("3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500") // EIP-2935 - Serve historical block hashes from state - HistoryStorageAddress = common.HexToAddress("0x0aae40965e6800cd9b1f4b05ff21581047e3f91e") - HistoryStorageCode = common.FromHex("3373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500") + HistoryStorageAddress = common.HexToAddress("0x0F792be4B0c0cb4DAE440Ef133E90C0eCD48CCCC") + HistoryStorageCode = common.FromHex("3373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500") // EIP-7002 - Execution layer triggerable withdrawals - WithdrawalQueueAddress = common.HexToAddress("0x09Fc772D0857550724b07B850a4323f39112aAaA") - WithdrawalQueueCode = common.FromHex("3373fffffffffffffffffffffffffffffffffffffffe1460c7573615156028575f545f5260205ff35b36603814156101f05760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f057600182026001905f5b5f821115608057810190830284830290049160010191906065565b9093900434106101f057600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160db575060105b5f5b81811461017f5780604c02838201600302600401805490600101805490600101549160601b83528260140152807fffffffffffffffffffffffffffffffff0000000000000000000000000000000016826034015260401c906044018160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160dd565b9101809214610191579060025561019c565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101c957505f5b6001546002828201116101de5750505f6101e4565b01600290035b5f555f600155604c025ff35b5f5ffd") + WithdrawalQueueAddress = common.HexToAddress("0x0c15F14308530b7CDB8460094BbB9cC28b9AaaAA") + WithdrawalQueueCode = common.FromHex("3373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160df575060105b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd") // EIP-7251 - Increase the MAX_EFFECTIVE_BALANCE - ConsolidationQueueAddress = common.HexToAddress("0x01aBEa29659e5e97C95107F20bb753cD3e09bBBb") - ConsolidationQueueCode = common.FromHex("3373fffffffffffffffffffffffffffffffffffffffe1460cf573615156028575f545f5260205ff35b366060141561019a5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f821115608057810190830284830290049160010191906065565b90939004341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060011160e3575060015b5f5b8181146101295780607402838201600402600401805490600101805490600101805490600101549260601b84529083601401528260340152906054015260010160e5565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd") + ConsolidationQueueAddress = common.HexToAddress("0x00431F263cE400f4455c2dCf564e53007Ca4bbBb") + ConsolidationQueueCode = common.FromHex("3373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060021160e7575060025b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd") )