From 53940420a2bd1cfd66fa13e3bfbd3ac189dd63c7 Mon Sep 17 00:00:00 2001 From: 0rac1e Date: Fri, 7 Apr 2023 11:33:54 +0600 Subject: [PATCH] zksync fix V value in ValidateSignatureValues --- core/types/transaction_marshalling.go | 6 +----- crypto/crypto.go | 5 ++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core/types/transaction_marshalling.go b/core/types/transaction_marshalling.go index b864d4088924b..aad31a5a97e2e 100644 --- a/core/types/transaction_marshalling.go +++ b/core/types/transaction_marshalling.go @@ -148,11 +148,7 @@ func (t *Transaction) UnmarshalJSON(input []byte) error { itx.S = (*big.Int)(dec.S) withSignature := itx.V.Sign() != 0 || itx.R.Sign() != 0 || itx.S.Sign() != 0 if withSignature { - mayBeProtected := true - if byte(itx.V.Uint64()) < 27 { - mayBeProtected = false - } - if err := sanityCheckSignature(itx.V, itx.R, itx.S, mayBeProtected); err != nil { + if err := sanityCheckSignature(itx.V, itx.R, itx.S, true); err != nil { return err } } diff --git a/crypto/crypto.go b/crypto/crypto.go index 45ea72747e6d9..e7f8793c44d5d 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -35,7 +35,7 @@ import ( "golang.org/x/crypto/sha3" ) -//SignatureLength indicates the byte length required to carry a signature with recovery id. +// SignatureLength indicates the byte length required to carry a signature with recovery id. const SignatureLength = 64 + 1 // 64 bytes ECDSA signature + 1 byte recovery id // RecoveryIDOffset points to the byte offset within the signature that contains the recovery id. @@ -269,6 +269,9 @@ func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool { return false } // Frontier: allow s to be in full N range + if v > 1 { + v = v + 27 + } return r.Cmp(secp256k1N) < 0 && s.Cmp(secp256k1N) < 0 && (v == 0 || v == 1) }