core/types: remove AuthorizationList and use Authorization as value instead of pointer

This commit is contained in:
Felix Lange 2024-12-02 11:51:09 +01:00 committed by lightclient
parent d3e82b485d
commit b8fb4d68de
No known key found for this signature in database
GPG key ID: 75C916AFEE20183E
8 changed files with 63 additions and 68 deletions

View file

@ -4273,13 +4273,12 @@ func TestEIP7702(t *testing.T) {
// 1. tx -> addr1 which is delegated to 0xaaaa // 1. tx -> addr1 which is delegated to 0xaaaa
// 2. addr1:0xaaaa calls into addr2:0xbbbb // 2. addr1:0xaaaa calls into addr2:0xbbbb
// 3. addr2:0xbbbb writes to storage // 3. addr2:0xbbbb writes to storage
auth1, _ := types.SignAuth(&types.Authorization{ auth1, _ := types.SignAuth(types.Authorization{
ChainID: gspec.Config.ChainID.Uint64(), ChainID: gspec.Config.ChainID.Uint64(),
Address: aa, Address: aa,
Nonce: 1, Nonce: 1,
}, key1) }, key1)
auth2, _ := types.SignAuth(types.Authorization{
auth2, _ := types.SignAuth(&types.Authorization{
ChainID: 0, ChainID: 0,
Address: bb, Address: bb,
Nonce: 0, Nonce: 0,
@ -4294,7 +4293,7 @@ func TestEIP7702(t *testing.T) {
Gas: 500000, Gas: 500000,
GasFeeCap: uint256.MustFromBig(newGwei(5)), GasFeeCap: uint256.MustFromBig(newGwei(5)),
GasTipCap: uint256.NewInt(2), GasTipCap: uint256.NewInt(2),
AuthList: []*types.Authorization{auth1, auth2}, AuthList: []types.Authorization{auth1, auth2},
} }
tx := types.MustSignNewTx(key1, signer, txdata) tx := types.MustSignNewTx(key1, signer, txdata)
b.AddTx(tx) b.AddTx(tx)

View file

@ -67,7 +67,7 @@ func (result *ExecutionResult) Revert() []byte {
} }
// IntrinsicGas computes the 'intrinsic gas' for a message with the given data. // 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 // Set the starting gas for the raw transaction
var gas uint64 var gas uint64
if isContractCreation && isHomestead { if isContractCreation && isHomestead {
@ -143,7 +143,7 @@ type Message struct {
AccessList types.AccessList AccessList types.AccessList
BlobGasFeeCap *big.Int BlobGasFeeCap *big.Int
BlobHashes []common.Hash BlobHashes []common.Hash
AuthList types.AuthorizationList AuthList []types.Authorization
// When SkipNonceChecks is true, the message nonce is not checked against the // When SkipNonceChecks is true, the message nonce is not checked against the
// account nonce in state. // account nonce in state.

View file

@ -475,7 +475,7 @@ func (tx *Transaction) WithBlobTxSidecar(sideCar *BlobTxSidecar) *Transaction {
} }
// AuthList returns the authorizations list of the transaction. // AuthList returns the authorizations list of the transaction.
func (tx *Transaction) AuthList() AuthorizationList { func (tx *Transaction) AuthList() []Authorization {
setcodetx, ok := tx.inner.(*SetCodeTx) setcodetx, ok := tx.inner.(*SetCodeTx)
if !ok { if !ok {
return nil return nil

View file

@ -43,7 +43,7 @@ type txJSON struct {
Input *hexutil.Bytes `json:"input"` Input *hexutil.Bytes `json:"input"`
AccessList *AccessList `json:"accessList,omitempty"` AccessList *AccessList `json:"accessList,omitempty"`
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"` BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
AuthorizationList *AuthorizationList `json:"authorizationList,omitempty"` AuthorizationList []Authorization `json:"authorizationList,omitempty"`
V *hexutil.Big `json:"v"` V *hexutil.Big `json:"v"`
R *hexutil.Big `json:"r"` R *hexutil.Big `json:"r"`
S *hexutil.Big `json:"s"` S *hexutil.Big `json:"s"`
@ -164,7 +164,7 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
enc.Value = (*hexutil.Big)(itx.Value.ToBig()) enc.Value = (*hexutil.Big)(itx.Value.ToBig())
enc.Input = (*hexutil.Bytes)(&itx.Data) enc.Input = (*hexutil.Bytes)(&itx.Data)
enc.AccessList = &itx.AccessList enc.AccessList = &itx.AccessList
enc.AuthorizationList = &itx.AuthList enc.AuthorizationList = itx.AuthList
enc.V = (*hexutil.Big)(itx.V.ToBig()) enc.V = (*hexutil.Big)(itx.V.ToBig())
enc.R = (*hexutil.Big)(itx.R.ToBig()) enc.R = (*hexutil.Big)(itx.R.ToBig())
enc.S = (*hexutil.Big)(itx.S.ToBig()) enc.S = (*hexutil.Big)(itx.S.ToBig())
@ -467,7 +467,7 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
if dec.AuthorizationList == nil { if dec.AuthorizationList == nil {
return errors.New("missing required field 'authorizationList' in transaction") return errors.New("missing required field 'authorizationList' in transaction")
} }
itx.AuthList = *dec.AuthorizationList itx.AuthList = dec.AuthorizationList
// signature R // signature R
var overflow bool var overflow bool

View file

@ -58,7 +58,7 @@ type SetCodeTx struct {
Value *uint256.Int Value *uint256.Int
Data []byte Data []byte
AccessList AccessList AccessList AccessList
AuthList AuthorizationList AuthList []Authorization
// Signature values // Signature values
V *uint256.Int `json:"v" gencodec:"required"` V *uint256.Int `json:"v" gencodec:"required"`
@ -89,7 +89,7 @@ type authorizationMarshaling struct {
} }
// SignAuth signs the provided authorization. // 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( h := prefixedRlpHash(
0x05, 0x05,
[]interface{}{ []interface{}{
@ -100,16 +100,16 @@ func SignAuth(auth *Authorization, prv *ecdsa.PrivateKey) (*Authorization, error
sig, err := crypto.Sign(h[:], prv) sig, err := crypto.Sign(h[:], prv)
if err != nil { if err != nil {
return nil, err return Authorization{}, err
} }
return auth.withSignature(sig), nil return auth.withSignature(sig), nil
} }
// withSignature updates the signature of an Authorization to be equal the // withSignature updates the signature of an Authorization to be equal the
// decoded signature provided in sig. // decoded signature provided in sig.
func (a *Authorization) withSignature(sig []byte) *Authorization { func (a *Authorization) withSignature(sig []byte) Authorization {
r, s, _ := decodeSignature(sig) r, s, _ := decodeSignature(sig)
cpy := Authorization{ return Authorization{
ChainID: a.ChainID, ChainID: a.ChainID,
Address: a.Address, Address: a.Address,
Nonce: a.Nonce, Nonce: a.Nonce,
@ -117,11 +117,8 @@ func (a *Authorization) withSignature(sig []byte) *Authorization {
R: r, R: r,
S: s, S: s,
} }
return &cpy
} }
type AuthorizationList []*Authorization
// Authority recovers the authorizing // Authority recovers the authorizing
func (a Authorization) Authority() (common.Address, error) { func (a Authorization) Authority() (common.Address, error) {
sighash := prefixedRlpHash( sighash := prefixedRlpHash(
@ -162,7 +159,7 @@ func (tx *SetCodeTx) copy() TxData {
Gas: tx.Gas, Gas: tx.Gas,
// These are copied below. // These are copied below.
AccessList: make(AccessList, len(tx.AccessList)), AccessList: make(AccessList, len(tx.AccessList)),
AuthList: make(AuthorizationList, len(tx.AuthList)), AuthList: make([]Authorization, len(tx.AuthList)),
Value: new(uint256.Int), Value: new(uint256.Int),
ChainID: tx.ChainID, ChainID: tx.ChainID,
GasTipCap: new(uint256.Int), GasTipCap: new(uint256.Int),

View file

@ -955,7 +955,7 @@ type RPCTransaction struct {
Accesses *types.AccessList `json:"accessList,omitempty"` Accesses *types.AccessList `json:"accessList,omitempty"`
ChainID *hexutil.Big `json:"chainId,omitempty"` ChainID *hexutil.Big `json:"chainId,omitempty"`
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"` BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
AuthorizationList types.AuthorizationList `json:"authorizationList,omitempty"` AuthorizationList []types.Authorization `json:"authorizationList,omitempty"`
V *hexutil.Big `json:"v"` V *hexutil.Big `json:"v"`
R *hexutil.Big `json:"r"` R *hexutil.Big `json:"r"`
S *hexutil.Big `json:"s"` S *hexutil.Big `json:"s"`

View file

@ -73,7 +73,7 @@ type TransactionArgs struct {
Proofs []kzg4844.Proof `json:"proofs"` Proofs []kzg4844.Proof `json:"proofs"`
// For SetCodeTxType // For SetCodeTxType
AuthList *types.AuthorizationList `json:"authList"` AuthList []types.Authorization `json:"authList"`
// This configures whether blobs are allowed to be passed. // This configures whether blobs are allowed to be passed.
blobSidecarAllowed bool blobSidecarAllowed bool
@ -496,9 +496,9 @@ func (args *TransactionArgs) ToTransaction(defaultType int) *types.Transaction {
if args.AccessList != nil { if args.AccessList != nil {
al = *args.AccessList al = *args.AccessList
} }
authList := types.AuthorizationList{} authList := []types.Authorization{}
if args.AuthList != nil { if args.AuthList != nil {
authList = *args.AuthList authList = args.AuthList
} }
data = &types.SetCodeTx{ data = &types.SetCodeTx{
To: *args.To, To: *args.To,

View file

@ -138,8 +138,7 @@ type stTransactionMarshaling struct {
//go:generate go run github.com/fjl/gencodec -type stAuthorization -field-override stAuthorizationMarshaling -out gen_stauthorization.go //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 // Authorization is an authorization from an account to deploy code at it's address.
// address.
type stAuthorization struct { type stAuthorization struct {
ChainID uint64 ChainID uint64
Address common.Address `json:"address" gencodec:"required"` 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 { if gasPrice == nil {
return nil, errors.New("no gas price provided") return nil, errors.New("no gas price provided")
} }
var authList types.AuthorizationList var authList []types.Authorization
if tx.AuthorizationList != nil { if tx.AuthorizationList != nil {
authList = make(types.AuthorizationList, 0) authList = make([]types.Authorization, len(tx.AuthorizationList))
for _, auth := range tx.AuthorizationList { for i, auth := range tx.AuthorizationList {
authList = append(authList, &types.Authorization{ authList[i] = types.Authorization{
ChainID: auth.ChainID, ChainID: auth.ChainID,
Address: auth.Address, Address: auth.Address,
Nonce: auth.Nonce, Nonce: auth.Nonce,
V: auth.V, V: auth.V,
R: auth.R, R: auth.R,
S: auth.S, S: auth.S,
}) }
} }
} }