From 2f1cb3525201ffa115b5fe4999a3e9e85b159466 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 7 Mar 2024 13:55:30 +0100 Subject: [PATCH] copy DynamicFeeTx for DelegateTX I got confused between type 1 and type 2, and based the implementation on eip-5806 on type 1 when it should have been on type 2. --- core/types/receipt.go | 2 +- core/types/transaction_signing.go | 8 +++--- core/types/tx_delegate.go | 44 +++++++++++++++++++++---------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/core/types/receipt.go b/core/types/receipt.go index e5d5b92fe6..952e795b54 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -204,7 +204,7 @@ func (r *Receipt) decodeTyped(b []byte) error { return errShortTypedReceipt } switch b[0] { - case DynamicFeeTxType, AccessListTxType, BlobTxType, DelegateTxType: + case AccessListTxType, DynamicFeeTxType, BlobTxType, DelegateTxType: var data receiptRLP err := rlp.DecodeBytes(b[1:], &data) if err != nil { diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index 4d58b45703..70dee0776e 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -326,7 +326,7 @@ func (s eip2930Signer) Sender(tx *Transaction) (common.Address, error) { switch tx.Type() { case LegacyTxType: return s.EIP155Signer.Sender(tx) - case AccessListTxType, DelegateTxType: + case AccessListTxType: // AL txs are defined to use 0 and 1 as their recovery // id, add 27 to become equivalent to unprotected Homestead signatures. V = new(big.Int).Add(V, big.NewInt(27)) @@ -343,11 +343,11 @@ func (s eip2930Signer) SignatureValues(tx *Transaction, sig []byte) (R, S, V *bi switch txdata := tx.inner.(type) { case *LegacyTx: return s.EIP155Signer.SignatureValues(tx, sig) - case *AccessListTx, *DelegateTx: + case *AccessListTx: // Check that chain ID of tx matches the signer. We also accept ID zero here, // because it indicates that the chain ID was not specified in the tx. - if txdata.chainID().Sign() != 0 && txdata.chainID().Cmp(s.chainId) != 0 { - return nil, nil, nil, fmt.Errorf("%w: have %d want %d", ErrInvalidChainId, txdata.chainID(), s.chainId) + if txdata.ChainID.Sign() != 0 && txdata.ChainID.Cmp(s.chainId) != 0 { + return nil, nil, nil, fmt.Errorf("%w: have %d want %d", ErrInvalidChainId, txdata.ChainID, s.chainId) } R, S, _ = decodeSignature(sig) V = big.NewInt(int64(sig[64])) diff --git a/core/types/tx_delegate.go b/core/types/tx_delegate.go index be59b7a245..49ebaab6f6 100644 --- a/core/types/tx_delegate.go +++ b/core/types/tx_delegate.go @@ -26,14 +26,19 @@ import ( // DelegateTx represents an EIP-5806 transaction. type DelegateTx struct { - ChainID *big.Int // destination chain ID - Nonce uint64 // nonce of sender account - GasPrice *big.Int // wei per gas - Gas uint64 // gas limit + ChainID *big.Int + Nonce uint64 + GasTipCap *big.Int // a.k.a. maxPriorityFeePerGas + GasFeeCap *big.Int // a.k.a. maxFeePerGas + Gas uint64 To *common.Address `rlp:"nil"` // nil means contract creation - Data []byte // contract invocation input data - AccessList AccessList // EIP-2930 access list - V, R, S *big.Int // signature values + Data []byte + AccessList AccessList + + // Signature values + V *big.Int `json:"v" gencodec:"required"` + R *big.Int `json:"r" gencodec:"required"` + S *big.Int `json:"s" gencodec:"required"` } // copy creates a deep copy of the transaction data and initializes all fields. @@ -46,7 +51,8 @@ func (tx *DelegateTx) copy() TxData { // These are copied below. AccessList: make(AccessList, len(tx.AccessList)), ChainID: new(big.Int), - GasPrice: new(big.Int), + GasTipCap: new(big.Int), + GasFeeCap: new(big.Int), V: new(big.Int), R: new(big.Int), S: new(big.Int), @@ -55,8 +61,11 @@ func (tx *DelegateTx) copy() TxData { if tx.ChainID != nil { cpy.ChainID.Set(tx.ChainID) } - if tx.GasPrice != nil { - cpy.GasPrice.Set(tx.GasPrice) + if tx.GasTipCap != nil { + cpy.GasTipCap.Set(tx.GasTipCap) + } + if tx.GasFeeCap != nil { + cpy.GasFeeCap.Set(tx.GasFeeCap) } if tx.V != nil { cpy.V.Set(tx.V) @@ -76,15 +85,22 @@ func (tx *DelegateTx) chainID() *big.Int { return tx.ChainID } func (tx *DelegateTx) accessList() AccessList { return tx.AccessList } func (tx *DelegateTx) data() []byte { return tx.Data } func (tx *DelegateTx) gas() uint64 { return tx.Gas } -func (tx *DelegateTx) gasPrice() *big.Int { return tx.GasPrice } -func (tx *DelegateTx) gasTipCap() *big.Int { return tx.GasPrice } -func (tx *DelegateTx) gasFeeCap() *big.Int { return tx.GasPrice } +func (tx *DelegateTx) gasFeeCap() *big.Int { return tx.GasFeeCap } +func (tx *DelegateTx) gasTipCap() *big.Int { return tx.GasTipCap } +func (tx *DelegateTx) gasPrice() *big.Int { return tx.GasFeeCap } func (tx *DelegateTx) value() *big.Int { return big.NewInt(0) } func (tx *DelegateTx) nonce() uint64 { return tx.Nonce } func (tx *DelegateTx) to() *common.Address { return tx.To } func (tx *DelegateTx) effectiveGasPrice(dst *big.Int, baseFee *big.Int) *big.Int { - return dst.Set(tx.GasPrice) + if baseFee == nil { + return dst.Set(tx.GasFeeCap) + } + tip := dst.Sub(tx.GasFeeCap, baseFee) + if tip.Cmp(tx.GasTipCap) > 0 { + tip.Set(tx.GasTipCap) + } + return tip.Add(tip, baseFee) } func (tx *DelegateTx) rawSignatureValues() (v, r, s *big.Int) {