diff --git a/core/types/tx_access_list.go b/core/types/tx_access_list.go index 915de9a8ab..2d5fad10de 100644 --- a/core/types/tx_access_list.go +++ b/core/types/tx_access_list.go @@ -128,17 +128,30 @@ func (tx *AccessListTx) decode(input []byte) error { return rlp.DecodeBytes(input, tx) } +// accessListTxSigHash represents the fields used for computing the signature hash +// of an AccessListTx transaction. +type accessListTxSigHash struct { + ChainID *big.Int + Nonce uint64 + GasPrice *big.Int + Gas uint64 + To *common.Address `rlp:"nil"` + Value *big.Int + Data []byte + AccessList AccessList +} + func (tx *AccessListTx) sigHash(chainID *big.Int) common.Hash { return prefixedRlpHash( AccessListTxType, - []any{ - chainID, - tx.Nonce, - tx.GasPrice, - tx.Gas, - tx.To, - tx.Value, - tx.Data, - tx.AccessList, + &accessListTxSigHash{ + ChainID: chainID, + Nonce: tx.Nonce, + GasPrice: tx.GasPrice, + Gas: tx.Gas, + To: tx.To, + Value: tx.Value, + Data: tx.Data, + AccessList: tx.AccessList, }) } diff --git a/core/types/tx_blob.go b/core/types/tx_blob.go index bbfd3c98db..99c7606817 100644 --- a/core/types/tx_blob.go +++ b/core/types/tx_blob.go @@ -421,20 +421,36 @@ func (tx *BlobTx) decode(input []byte) error { return nil } +// blobTxSigHash represents the fields used for computing the signature hash +// of a BlobTx transaction. +type blobTxSigHash struct { + ChainID *big.Int + Nonce uint64 + GasTipCap *uint256.Int + GasFeeCap *uint256.Int + Gas uint64 + To common.Address + Value *uint256.Int + Data []byte + AccessList AccessList + BlobFeeCap *uint256.Int + BlobHashes []common.Hash +} + func (tx *BlobTx) sigHash(chainID *big.Int) common.Hash { return prefixedRlpHash( BlobTxType, - []any{ - chainID, - tx.Nonce, - tx.GasTipCap, - tx.GasFeeCap, - tx.Gas, - tx.To, - tx.Value, - tx.Data, - tx.AccessList, - tx.BlobFeeCap, - tx.BlobHashes, + &blobTxSigHash{ + ChainID: chainID, + Nonce: tx.Nonce, + GasTipCap: tx.GasTipCap, + GasFeeCap: tx.GasFeeCap, + Gas: tx.Gas, + To: tx.To, + Value: tx.Value, + Data: tx.Data, + AccessList: tx.AccessList, + BlobFeeCap: tx.BlobFeeCap, + BlobHashes: tx.BlobHashes, }) } diff --git a/core/types/tx_dynamic_fee.go b/core/types/tx_dynamic_fee.go index bba81464f8..928f1244e7 100644 --- a/core/types/tx_dynamic_fee.go +++ b/core/types/tx_dynamic_fee.go @@ -124,18 +124,32 @@ func (tx *DynamicFeeTx) decode(input []byte) error { return rlp.DecodeBytes(input, tx) } +// dynamicFeeTxSigHash represents the fields used for computing the signature hash +// of a DynamicFeeTx transaction. +type dynamicFeeTxSigHash struct { + ChainID *big.Int + Nonce uint64 + GasTipCap *big.Int + GasFeeCap *big.Int + Gas uint64 + To *common.Address `rlp:"nil"` + Value *big.Int + Data []byte + AccessList AccessList +} + func (tx *DynamicFeeTx) sigHash(chainID *big.Int) common.Hash { return prefixedRlpHash( DynamicFeeTxType, - []any{ - chainID, - tx.Nonce, - tx.GasTipCap, - tx.GasFeeCap, - tx.Gas, - tx.To, - tx.Value, - tx.Data, - tx.AccessList, + &dynamicFeeTxSigHash{ + ChainID: chainID, + Nonce: tx.Nonce, + GasTipCap: tx.GasTipCap, + GasFeeCap: tx.GasFeeCap, + Gas: tx.Gas, + To: tx.To, + Value: tx.Value, + Data: tx.Data, + AccessList: tx.AccessList, }) } diff --git a/core/types/tx_legacy.go b/core/types/tx_legacy.go index 49f0a98809..9bc392931b 100644 --- a/core/types/tx_legacy.go +++ b/core/types/tx_legacy.go @@ -124,15 +124,31 @@ func (tx *LegacyTx) decode([]byte) error { panic("decode called on LegacyTx)") } +// legacyTxSigHash represents the fields used for computing the signature hash +// of a LegacyTx transaction (post-EIP155). +type legacyTxSigHash struct { + Nonce uint64 + GasPrice *big.Int + Gas uint64 + To *common.Address `rlp:"nil"` + Value *big.Int + Data []byte + ChainID *big.Int + V uint + R uint +} + // OBS: This is the post-EIP155 hash, the pre-EIP155 does not contain a chainID. func (tx *LegacyTx) sigHash(chainID *big.Int) common.Hash { - return rlpHash([]any{ - tx.Nonce, - tx.GasPrice, - tx.Gas, - tx.To, - tx.Value, - tx.Data, - chainID, uint(0), uint(0), + return rlpHash(&legacyTxSigHash{ + Nonce: tx.Nonce, + GasPrice: tx.GasPrice, + Gas: tx.Gas, + To: tx.To, + Value: tx.Value, + Data: tx.Data, + ChainID: chainID, + V: uint(0), + R: uint(0), }) } diff --git a/core/types/tx_setcode.go b/core/types/tx_setcode.go index f2281d4ae7..20aa27eabc 100644 --- a/core/types/tx_setcode.go +++ b/core/types/tx_setcode.go @@ -225,19 +225,34 @@ func (tx *SetCodeTx) decode(input []byte) error { return rlp.DecodeBytes(input, tx) } +// setCodeTxSigHash represents the fields used for computing the signature hash +// of a SetCodeTx transaction. +type setCodeTxSigHash struct { + ChainID *big.Int + Nonce uint64 + GasTipCap *uint256.Int + GasFeeCap *uint256.Int + Gas uint64 + To common.Address + Value *uint256.Int + Data []byte + AccessList AccessList + AuthList []SetCodeAuthorization +} + func (tx *SetCodeTx) sigHash(chainID *big.Int) common.Hash { return prefixedRlpHash( SetCodeTxType, - []any{ - chainID, - tx.Nonce, - tx.GasTipCap, - tx.GasFeeCap, - tx.Gas, - tx.To, - tx.Value, - tx.Data, - tx.AccessList, - tx.AuthList, + &setCodeTxSigHash{ + ChainID: chainID, + Nonce: tx.Nonce, + GasTipCap: tx.GasTipCap, + GasFeeCap: tx.GasFeeCap, + Gas: tx.Gas, + To: tx.To, + Value: tx.Value, + Data: tx.Data, + AccessList: tx.AccessList, + AuthList: tx.AuthList, }) }