Merge pull request #350 from tsuzukit/feature/eip155

Use EIP155 signer when needed
This commit is contained in:
Samer Falah 2018-05-23 11:25:26 -04:00 committed by GitHub
commit b6cee6dd83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -40,9 +40,6 @@ type sigCache struct {
// MakeSigner returns a Signer based on the given chain config and block number.
func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer {
if config.IsQuorum {
return HomesteadSigner{}
}
var signer Signer
switch {
case config.IsEIP155(blockNumber):
@ -128,6 +125,9 @@ func (s EIP155Signer) Equal(s2 Signer) bool {
var big8 = big.NewInt(8)
func (s EIP155Signer) Sender(tx *Transaction) (common.Address, error) {
if tx.IsPrivate() {
return HomesteadSigner{}.Sender(tx)
}
if !tx.Protected() {
return HomesteadSigner{}.Sender(tx)
}
@ -136,12 +136,16 @@ func (s EIP155Signer) Sender(tx *Transaction) (common.Address, error) {
}
V := new(big.Int).Sub(tx.data.V, s.chainIdMul)
V.Sub(V, big8)
return recoverPlain(s.Hash(tx), tx.data.R, tx.data.S, V, true, false)
return recoverPlain(s.Hash(tx), tx.data.R, tx.data.S, V, true, tx.IsPrivate())
}
// WithSignature returns a new transaction with the given signature. This signature
// needs to be in the [R || S || V] format where V is 0 or 1.
func (s EIP155Signer) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big.Int, err error) {
if tx.IsPrivate() {
return HomesteadSigner{}.SignatureValues(tx, sig)
}
R, S, V, err = HomesteadSigner{}.SignatureValues(tx, sig)
if err != nil {
return nil, nil, nil, err