From b8fb4d68deba505a3fce861abe1dcaa0eff18610 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 2 Dec 2024 11:51:09 +0100 Subject: [PATCH] core/types: remove AuthorizationList and use Authorization as value instead of pointer --- core/blockchain_test.go | 7 ++-- core/state_transition.go | 4 +-- core/types/transaction.go | 2 +- core/types/transaction_marshalling.go | 38 +++++++++++----------- core/types/tx_setcode.go | 15 ++++----- internal/ethapi/api.go | 46 +++++++++++++-------------- internal/ethapi/transaction_args.go | 6 ++-- tests/state_test_util.go | 13 ++++---- 8 files changed, 63 insertions(+), 68 deletions(-) diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 03aca0c7eb..a54a907766 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -4273,13 +4273,12 @@ 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.SignAuth(types.Authorization{ ChainID: gspec.Config.ChainID.Uint64(), Address: aa, Nonce: 1, }, key1) - - auth2, _ := types.SignAuth(&types.Authorization{ + auth2, _ := types.SignAuth(types.Authorization{ ChainID: 0, Address: bb, Nonce: 0, @@ -4294,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.Authorization{auth1, auth2}, } tx := types.MustSignNewTx(key1, signer, txdata) b.AddTx(tx) diff --git a/core/state_transition.go b/core/state_transition.go index ae883687b4..de30771f83 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.AuthorizationList, isContractCreation, isHomestead, isEIP2028, isEIP3860 bool) (uint64, error) { +func IntrinsicGas(data []byte, accessList types.AccessList, authList []types.Authorization, 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.AuthorizationList + AuthList []types.Authorization // When SkipNonceChecks is true, the message nonce is not checked against the // account nonce in state. diff --git a/core/types/transaction.go b/core/types/transaction.go index 6276c4e23f..b5fb3e2db2 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() AuthorizationList { +func (tx *Transaction) AuthList() []Authorization { setcodetx, ok := tx.inner.(*SetCodeTx) if !ok { return nil diff --git a/core/types/transaction_marshalling.go b/core/types/transaction_marshalling.go index b2a306639a..4176a8220c 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 *AuthorizationList `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 []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"` // Blob transaction sidecar encoding: Blobs []kzg4844.Blob `json:"blobs,omitempty"` @@ -164,7 +164,7 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) { enc.Value = (*hexutil.Big)(itx.Value.ToBig()) enc.Input = (*hexutil.Bytes)(&itx.Data) enc.AccessList = &itx.AccessList - enc.AuthorizationList = &itx.AuthList + enc.AuthorizationList = itx.AuthList enc.V = (*hexutil.Big)(itx.V.ToBig()) enc.R = (*hexutil.Big)(itx.R.ToBig()) enc.S = (*hexutil.Big)(itx.S.ToBig()) @@ -467,7 +467,7 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error { if dec.AuthorizationList == nil { return errors.New("missing required field 'authorizationList' in transaction") } - itx.AuthList = *dec.AuthorizationList + itx.AuthList = dec.AuthorizationList // signature R var overflow bool diff --git a/core/types/tx_setcode.go b/core/types/tx_setcode.go index 42166da7fe..f2e3bd7550 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 AuthorizationList + AuthList []Authorization // Signature values V *uint256.Int `json:"v" gencodec:"required"` @@ -89,7 +89,7 @@ type authorizationMarshaling struct { } // SignAuth signs the provided authorization. -func SignAuth(auth *Authorization, prv *ecdsa.PrivateKey) (*Authorization, error) { +func SignAuth(auth Authorization, prv *ecdsa.PrivateKey) (Authorization, error) { h := prefixedRlpHash( 0x05, []interface{}{ @@ -100,16 +100,16 @@ func SignAuth(auth *Authorization, prv *ecdsa.PrivateKey) (*Authorization, error sig, err := crypto.Sign(h[:], prv) if err != nil { - return nil, err + return Authorization{}, 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 { +func (a *Authorization) withSignature(sig []byte) Authorization { r, s, _ := decodeSignature(sig) - cpy := Authorization{ + return Authorization{ ChainID: a.ChainID, Address: a.Address, Nonce: a.Nonce, @@ -117,11 +117,8 @@ func (a *Authorization) withSignature(sig []byte) *Authorization { R: r, S: s, } - return &cpy } -type AuthorizationList []*Authorization - // Authority recovers the authorizing func (a Authorization) Authority() (common.Address, error) { sighash := prefixedRlpHash( @@ -162,7 +159,7 @@ func (tx *SetCodeTx) copy() TxData { Gas: tx.Gas, // These are copied below. AccessList: make(AccessList, len(tx.AccessList)), - AuthList: make(AuthorizationList, len(tx.AuthList)), + AuthList: make([]Authorization, 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 b4a7aea122..f5b4d57202 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.AuthorizationList `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.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"` } // 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 d8c602acd2..9f194d78d5 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 - AuthList *types.AuthorizationList `json:"authList"` + AuthList []types.Authorization `json:"authList"` // This configures whether blobs are allowed to be passed. blobSidecarAllowed bool @@ -496,9 +496,9 @@ func (args *TransactionArgs) ToTransaction(defaultType int) *types.Transaction { if args.AccessList != nil { al = *args.AccessList } - authList := types.AuthorizationList{} + authList := []types.Authorization{} if args.AuthList != nil { - authList = *args.AuthList + authList = args.AuthList } data = &types.SetCodeTx{ To: *args.To, diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 3d1981855c..6a3ac952ed 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -138,8 +138,7 @@ type stTransactionMarshaling struct { //go:generate go run github.com/fjl/gencodec -type stAuthorization -field-override stAuthorizationMarshaling -out gen_stauthorization.go -// Authorization is an authorization from an account to deploy code at it's -// address. +// Authorization is an authorization from an account to deploy code at it's address. type stAuthorization struct { ChainID uint64 Address common.Address `json:"address" gencodec:"required"` @@ -442,18 +441,18 @@ 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.AuthorizationList + var authList []types.Authorization if tx.AuthorizationList != nil { - authList = make(types.AuthorizationList, 0) - for _, auth := range tx.AuthorizationList { - authList = append(authList, &types.Authorization{ + authList = make([]types.Authorization, len(tx.AuthorizationList)) + for i, auth := range tx.AuthorizationList { + authList[i] = types.Authorization{ ChainID: auth.ChainID, Address: auth.Address, Nonce: auth.Nonce, V: auth.V, R: auth.R, S: auth.S, - }) + } } }