Skip to content

Commit

Permalink
Add zero check in tx.Sender func (#10737)
Browse files Browse the repository at this point in the history
This is an additional check as #9990 could not be reliably reproduced.
The conjecture is that at some point there is a race condition somewhere
related to either storing snapshot file for an older block or updating
the DB for a more recent block.
Somewhere the code sets sender value directly to zero or overwrites a
pointer, leading to sender address being incorrectly assigned to ZERO.
  • Loading branch information
somnathb1 authored Jun 28, 2024
1 parent d983933 commit b7942be
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion core/types/access_list_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,10 @@ func (tx *AccessListTx) GetChainID() *uint256.Int {

func (tx *AccessListTx) Sender(signer Signer) (libcommon.Address, error) {
if sc := tx.from.Load(); sc != nil {
return sc.(libcommon.Address), nil
zeroAddr := libcommon.Address{}
if sc.(libcommon.Address) != zeroAddr { // Sender address can never be zero in a transaction with a valid signer
return sc.(libcommon.Address), nil
}
}
addr, err := signer.Sender(tx)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion core/types/blob_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ func (stx *BlobTx) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Me

func (stx *BlobTx) Sender(signer Signer) (libcommon.Address, error) {
if sc := stx.from.Load(); sc != nil {
return sc.(libcommon.Address), nil
zeroAddr := libcommon.Address{}
if sc.(libcommon.Address) != zeroAddr { // Sender address can never be zero in a transaction with a valid signer
return sc.(libcommon.Address), nil
}
}
addr, err := signer.Sender(stx)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion core/types/dynamic_fee_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,10 @@ func (tx *DynamicFeeTransaction) GetChainID() *uint256.Int {

func (tx *DynamicFeeTransaction) Sender(signer Signer) (libcommon.Address, error) {
if sc := tx.from.Load(); sc != nil {
return sc.(libcommon.Address), nil
zeroAddr := libcommon.Address{}
if sc.(libcommon.Address) != zeroAddr { // Sender address can never be zero in a transaction with a valid signer
return sc.(libcommon.Address), nil
}
}
addr, err := signer.Sender(tx)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion core/types/legacy_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,10 @@ func (tx *LegacyTx) GetChainID() *uint256.Int {

func (tx *LegacyTx) Sender(signer Signer) (libcommon.Address, error) {
if sc := tx.from.Load(); sc != nil {
return sc.(libcommon.Address), nil
zeroAddr := libcommon.Address{}
if sc.(libcommon.Address) != zeroAddr { // Sender address can never be zero in a transaction with a valid signer
return sc.(libcommon.Address), nil
}
}
addr, err := signer.Sender(tx)
if err != nil {
Expand Down

0 comments on commit b7942be

Please sign in to comment.