mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
core/types: reduce allocations in transaction signing
This commit is contained in:
parent
9baab1311a
commit
95b0563898
1 changed files with 6 additions and 5 deletions
|
|
@ -327,7 +327,7 @@ func NewEIP2930Signer(chainId *big.Int) Signer {
|
||||||
// are replay-protected as well as unprotected homestead transactions.
|
// are replay-protected as well as unprotected homestead transactions.
|
||||||
// Deprecated: always use the Signer interface type
|
// Deprecated: always use the Signer interface type
|
||||||
type EIP155Signer struct {
|
type EIP155Signer struct {
|
||||||
chainId, chainIdMul *big.Int
|
chainId *big.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEIP155Signer(chainId *big.Int) EIP155Signer {
|
func NewEIP155Signer(chainId *big.Int) EIP155Signer {
|
||||||
|
|
@ -335,8 +335,7 @@ func NewEIP155Signer(chainId *big.Int) EIP155Signer {
|
||||||
chainId = new(big.Int)
|
chainId = new(big.Int)
|
||||||
}
|
}
|
||||||
return EIP155Signer{
|
return EIP155Signer{
|
||||||
chainId: chainId,
|
chainId: chainId,
|
||||||
chainIdMul: new(big.Int).Mul(chainId, big.NewInt(2)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -362,7 +361,8 @@ func (s EIP155Signer) Sender(tx *Transaction) (common.Address, error) {
|
||||||
return common.Address{}, fmt.Errorf("%w: have %d want %d", ErrInvalidChainId, tx.ChainId(), s.chainId)
|
return common.Address{}, fmt.Errorf("%w: have %d want %d", ErrInvalidChainId, tx.ChainId(), s.chainId)
|
||||||
}
|
}
|
||||||
V, R, S := tx.RawSignatureValues()
|
V, R, S := tx.RawSignatureValues()
|
||||||
V = new(big.Int).Sub(V, s.chainIdMul)
|
V = new(big.Int).Sub(V, s.chainId)
|
||||||
|
V = new(big.Int).Sub(V, s.chainId)
|
||||||
V.Sub(V, big8)
|
V.Sub(V, big8)
|
||||||
return recoverPlain(s.Hash(tx), R, S, V, true)
|
return recoverPlain(s.Hash(tx), R, S, V, true)
|
||||||
}
|
}
|
||||||
|
|
@ -376,7 +376,8 @@ func (s EIP155Signer) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big
|
||||||
R, S, V = decodeSignature(sig)
|
R, S, V = decodeSignature(sig)
|
||||||
if s.chainId.Sign() != 0 {
|
if s.chainId.Sign() != 0 {
|
||||||
V = big.NewInt(int64(sig[64] + 35))
|
V = big.NewInt(int64(sig[64] + 35))
|
||||||
V.Add(V, s.chainIdMul)
|
V.Add(V, s.chainId)
|
||||||
|
V.Add(V, s.chainId)
|
||||||
}
|
}
|
||||||
return R, S, V, nil
|
return R, S, V, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue