validate signature size on SendTransactionWithSignature (#1401)
* chekc signature size to avoid panic from go-ethereum * add comment and constant * add test
This commit is contained in:
parent
cf8f20b23c
commit
b3e2cb2965
|
@ -3,6 +3,7 @@ package transactions
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -24,8 +25,13 @@ const (
|
||||||
sendTxTimeout = 300 * time.Second
|
sendTxTimeout = 300 * time.Second
|
||||||
|
|
||||||
defaultGas = 90000
|
defaultGas = 90000
|
||||||
|
|
||||||
|
validSignatureSize = 65
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrInvalidSignatureSize is returned if a signature is not 65 bytes to avoid panic from go-ethereum
|
||||||
|
var ErrInvalidSignatureSize = errors.New("signature size must be 65")
|
||||||
|
|
||||||
type ErrBadNonce struct {
|
type ErrBadNonce struct {
|
||||||
nonce uint64
|
nonce uint64
|
||||||
expectedNonce uint64
|
expectedNonce uint64
|
||||||
|
@ -88,6 +94,10 @@ func (t *Transactor) SendTransactionWithSignature(args SendTxArgs, sig []byte) (
|
||||||
return hash, ErrInvalidSendTxArgs
|
return hash, ErrInvalidSendTxArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(sig) != validSignatureSize {
|
||||||
|
return hash, ErrInvalidSignatureSize
|
||||||
|
}
|
||||||
|
|
||||||
chainID := big.NewInt(int64(t.networkID))
|
chainID := big.NewInt(int64(t.networkID))
|
||||||
signer := types.NewEIP155Signer(chainID)
|
signer := types.NewEIP155Signer(chainID)
|
||||||
|
|
||||||
|
|
|
@ -374,6 +374,12 @@ func (s *TransactorSuite) TestSendTransactionWithSignature() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *TransactorSuite) TestSendTransactionWithSignature_InvalidSignature() {
|
||||||
|
args := SendTxArgs{}
|
||||||
|
_, err := s.manager.SendTransactionWithSignature(args, []byte{})
|
||||||
|
s.Equal(ErrInvalidSignatureSize, err)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *TransactorSuite) TestHashTransaction() {
|
func (s *TransactorSuite) TestHashTransaction() {
|
||||||
privKey, err := crypto.GenerateKey()
|
privKey, err := crypto.GenerateKey()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
Loading…
Reference in New Issue