core/types: check non-nil chainID during signatureValue recovery

This commit is contained in:
Marius van der Wijden 2025-01-20 14:35:50 +01:00
parent 163e4639ec
commit 1bcd49e187
2 changed files with 10 additions and 2 deletions

View file

@ -97,6 +97,7 @@ func TestStateProcessorErrors(t *testing.T) {
} }
var mkBlobTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap, blobGasFeeCap *big.Int, hashes []common.Hash) *types.Transaction { var mkBlobTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap, blobGasFeeCap *big.Int, hashes []common.Hash) *types.Transaction {
tx, err := types.SignTx(types.NewTx(&types.BlobTx{ tx, err := types.SignTx(types.NewTx(&types.BlobTx{
ChainID: new(uint256.Int),
Nonce: nonce, Nonce: nonce,
GasTipCap: uint256.MustFromBig(gasTipCap), GasTipCap: uint256.MustFromBig(gasTipCap),
GasFeeCap: uint256.MustFromBig(gasFeeCap), GasFeeCap: uint256.MustFromBig(gasFeeCap),
@ -113,6 +114,7 @@ func TestStateProcessorErrors(t *testing.T) {
} }
var mkSetCodeTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap *big.Int, authlist []types.SetCodeAuthorization) *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{ tx, err := types.SignTx(types.NewTx(&types.SetCodeTx{
ChainID: new(uint256.Int),
Nonce: nonce, Nonce: nonce,
GasTipCap: uint256.MustFromBig(gasTipCap), GasTipCap: uint256.MustFromBig(gasTipCap),
GasFeeCap: uint256.MustFromBig(gasFeeCap), GasFeeCap: uint256.MustFromBig(gasFeeCap),

View file

@ -219,7 +219,10 @@ func (s pragueSigner) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big
} }
// Check that chain ID of tx matches the signer. We also accept ID zero here, // 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. // because it indicates that the chain ID was not specified in the tx.
if tx.ChainId().Sign() != 0 && tx.ChainId().Cmp(s.chainId) != 0 { if txdata.ChainID == nil {
return nil, nil, nil, fmt.Errorf("%w: chainID not set", ErrInvalidChainId)
}
if txdata.ChainID.Sign() != 0 && txdata.ChainID.CmpBig(s.chainId) != 0 {
return nil, nil, nil, fmt.Errorf("%w: have %d want %d", ErrInvalidChainId, txdata.ChainID, s.chainId) return nil, nil, nil, fmt.Errorf("%w: have %d want %d", ErrInvalidChainId, txdata.ChainID, s.chainId)
} }
R, S, _ = decodeSignature(sig) R, S, _ = decodeSignature(sig)
@ -287,7 +290,10 @@ func (s cancunSigner) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big
} }
// Check that chain ID of tx matches the signer. We also accept ID zero here, // 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. // because it indicates that the chain ID was not specified in the tx.
if tx.ChainId().Sign() != 0 && tx.ChainId().Cmp(s.chainId) != 0 { if txdata.ChainID == nil {
return nil, nil, nil, fmt.Errorf("%w: chainID not set", ErrInvalidChainId)
}
if txdata.ChainID.Sign() != 0 && txdata.ChainID.CmpBig(s.chainId) != 0 {
return nil, nil, nil, fmt.Errorf("%w: have %d want %d", ErrInvalidChainId, txdata.ChainID, s.chainId) return nil, nil, nil, fmt.Errorf("%w: have %d want %d", ErrInvalidChainId, txdata.ChainID, s.chainId)
} }
R, S, _ = decodeSignature(sig) R, S, _ = decodeSignature(sig)