Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
tx, err := types.SignTx(types.NewTx(&types.BlobTx{
ChainID: new(uint256.Int),
Nonce: nonce,
GasTipCap: uint256.MustFromBig(gasTipCap),
GasFeeCap: uint256.MustFromBig(gasFeeCap),
Expand All @@ -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 {
tx, err := types.SignTx(types.NewTx(&types.SetCodeTx{
ChainID: new(uint256.Int),
Nonce: nonce,
GasTipCap: uint256.MustFromBig(gasTipCap),
GasFeeCap: uint256.MustFromBig(gasFeeCap),
Expand Down
6 changes: 6 additions & 0 deletions core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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)
}
Expand Down Expand Up @@ -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: 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)
}
Expand Down
9 changes: 7 additions & 2 deletions core/types/tx_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,13 @@ func (tx *BlobTx) copy() TxData {
}

// accessors for innerTx.
func (tx *BlobTx) txType() byte { return BlobTxType }
func (tx *BlobTx) chainID() *big.Int { return tx.ChainID.ToBig() }
func (tx *BlobTx) txType() byte { return BlobTxType }
func (tx *BlobTx) chainID() *big.Int {
if tx.ChainID == nil {
return new(big.Int)
}
return tx.ChainID.ToBig()
}
func (tx *BlobTx) accessList() AccessList { return tx.AccessList }
func (tx *BlobTx) data() []byte { return tx.Data }
func (tx *BlobTx) gas() uint64 { return tx.Gas }
Expand Down
9 changes: 7 additions & 2 deletions core/types/tx_setcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,13 @@ func (tx *SetCodeTx) copy() TxData {
}

// accessors for innerTx.
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 {
Copy link
Member

@rjl493456442 rjl493456442 Jan 20, 2025

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

Copy link
Member Author

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

if tx.ChainID == nil {
return new(big.Int)
}
return tx.ChainID.ToBig()
}
func (tx *SetCodeTx) accessList() AccessList { return tx.AccessList }
func (tx *SetCodeTx) data() []byte { return tx.Data }
func (tx *SetCodeTx) gas() uint64 { return tx.Gas }
Expand Down