github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/state/crypto.go (about)

     1  package state
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/ethereum/go-ethereum/core/types"
     7  	"github.com/ethereum/go-ethereum/crypto"
     8  )
     9  
    10  var (
    11  	// ErrInvalidSig indicates the signature of the transaction is not valid
    12  	ErrInvalidSig = errors.New("invalid transaction v, r, s values")
    13  )
    14  
    15  // CheckSignature checks a transaction signature
    16  func CheckSignature(tx types.Transaction) error {
    17  	// Check Signature
    18  	v, r, s := tx.RawSignatureValues()
    19  	plainV := byte(0)
    20  	chainID := tx.ChainId().Uint64()
    21  	if chainID != 0 {
    22  		plainV = byte(v.Uint64() - 35 - 2*(chainID))
    23  	}
    24  	if !crypto.ValidateSignatureValues(plainV, r, s, false) {
    25  		return ErrInvalidSig
    26  	}
    27  
    28  	return nil
    29  }