-
Notifications
You must be signed in to change notification settings - Fork 21.4k
core: fix TestStateProcessorErrors test #31051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core: fix TestStateProcessorErrors test #31051
Conversation
|
We should probably add an error case somewhere in package types to catch this condition. I feel like panic is not a good option. If panic is wanted, |
|
Okay I fixed it a different way now, which creates a lot more allocations, but I don't think we need to care about that... In Our implementation broke this assumption, with the fix I added, we are back to that assumption. |
|
Alternative: diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go
index 030fc472a0..8fdf3998ee 100644
--- a/core/types/transaction_signing.go
+++ b/core/types/transaction_signing.go
@@ -219,6 +219,9 @@ 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,
// because it indicates that the chain ID was not specified in the tx.
+ if txdata.ChainID == nil {
+ return nil, nil, nil, fmt.Errorf("%w: nil chainID", 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)
}
@@ -287,6 +290,9 @@ 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,
// because it indicates that the chain ID was not specified in the tx.
+ if txdata.ChainID == nil {
+ return nil, nil, nil, fmt.Errorf("%w: nil chainID", 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)
}
``` |
|
I would prefer to fix the test, rather than adding the nil-handling in the chainID function. Reasons:
Therefore, it's impossible to have a nil chainID except the tests, if I understand correctly? |
|
The modified function |
| func (tx *SetCodeTx) txType() byte { return SetCodeTxType } | ||
| func (tx *SetCodeTx) chainID() *big.Int { return tx.ChainID.ToBig() } | ||
| func (tx *SetCodeTx) txType() byte { return SetCodeTxType } | ||
| func (tx *SetCodeTx) chainID() *big.Int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's impossible to have nil chainID if the tx is constructed from the json unmarshal or rlp decode, right?
it's only possible for the manual constructed one.
maybe the default zero value is unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep its only possible for hand-created transactions, I added it, because we have this comment here:
// ChainId returns the EIP155 chain ID of the transaction. The return value will always be
// non-nil. For legacy transactions which are not replay-protected, the return value is
// zero.
func (tx *Transaction) ChainId() *big.Int {
return tx.inner.chainID()
}
I can revert, but then I would also remove this comment
|
Hey, I have another approach, just let it be consistent with blobTx |
|
Closing because this got merged: #31054 |
#31032 was merged under the assumption that chainID will never be nil in our code (since that is checked during unmarshalling). However during some hand-constructed tests, we kept the chainID unset, which resulted in a panic'ing test