Skip to content

Commit

Permalink
don't scale v if already 0 or 1 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
poly-rodr authored Dec 22, 2022
1 parent e94463f commit d721f39
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ func Sign(privateKey *ecdsa.PrivateKey, hashedData common.Hash) ([]byte, error)
func ValidateSignature(signer common.Address, hashedData common.Hash, signature []byte) (bool, error) {
sigCopy := make([]byte, len(signature))
copy(sigCopy, signature)
sigCopy[64] -= 27 // Transform V from 27/28 to 0/1 according to the yellow paper

if sigCopy[64] != 0 && sigCopy[64] != 1 { // in case of ledger signing v might already be 0 or 1
sigCopy[64] -= 27 // Transform V from 27/28 to 0/1 according to the yellow paper
}

sigPublicKey, err := crypto.Ecrecover(hashedData.Bytes(), sigCopy)
if err != nil {
Expand Down

0 comments on commit d721f39

Please sign in to comment.