-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing pubkey and signature validation for blsVerify()? #2695
Comments
The new document in https://github.com/status-im/nim-blscurve/blob/e9b75abc/docs/bls_types_guarantees.md addresses those concerns. All paths that create a public key (from a As suggested in cfrg/draft-irtf-cfrg-bls-signature#33 (comment)
and also for performance reason, we "cache the subgroup checks and infinity point checks" by only doing them at deserialization instead of redoing them for each single or aggregate verifications, this is mentioned in func coreVerifyNoGroupCheck*[T: byte|char](
publicKey: PublicKey,
message: openarray[T],
sig_or_proof: Signature or ProofOfPossession,
domainSepTag: static string): bool {.noinline.} =
## Check that a signature (or proof-of-possession) is valid
## for a message (or serialized publickey) under the provided public key
## This assumes that the Public Key and Signatures
## have been pre group checked (likely on deserialization) The future draft of the BLS signature spec should make it clearer that |
Makes sense, thanks. I did not find where the deserial checks are done though (on keys and sigs). |
In the https://github.com/status-im/nim-blscurve/blob/e9b75abc/blscurve/blst/bls_sig_io.nim#L42-L99 func fromBytes*(
obj: var (Signature|ProofOfPossession),
raw: array[96, byte] or array[192, byte]
): bool {.inline.} =
## Initialize a BLS signature scheme object from
## its raw bytes representation.
## Returns true on success and false otherwise
result =
when raw.len == 96:
obj.point.blst_p2_uncompress(raw) == BLST_SUCCESS
elif raw.len == 192:
obj.point.blst_p2_deserialize(raw) == BLST_SUCCESS
else: false
# Infinity signatures are allowed if we receive an empty aggregated signature
if result:
result = bool obj.point.blst_p2_affine_in_g2()
func fromBytesKnownOnCurve*(
obj: var (Signature|ProofOfPossession),
raw: array[96, byte] or array[192, byte]
): bool {.inline.} =
## Initialize a BLS signature scheme object from
## its raw bytes representation.
## Returns true on success and false otherwise
##
## The point is known to be on curve and is not group checked
result =
when raw.len == 96:
obj.point.blst_p2_uncompress(raw) == BLST_SUCCESS
elif raw.len == 192:
obj.point.blst_p2_deserialize(raw) == BLST_SUCCESS
else: false
# Infinity signatures are allowed if we receive an empty aggregated signature
# Skipped - Known on curve
# if result:
# result = bool obj.point.blst_p2_affine_in_g2()
func fromBytes*(
obj: var PublicKey,
raw: array[48, byte] or array[96, byte]
): bool {.inline.} =
## Initialize a BLS signature scheme object from
## its raw bytes representation.
## Returns true on success and false otherwise
result =
when raw.len == 48:
obj.point.blst_p1_uncompress(raw) == BLST_SUCCESS
elif raw.len == 96:
obj.point.blst_p1_deserialize(raw) == BLST_SUCCESS
else: false
# Infinity public keys are not allowed
if result:
result = not bool obj.point.blst_p1_affine_is_inf()
if result:
result = bool obj.point.blst_p1_affine_in_g1() And they are called in Nimbus by the nimbus-eth2/beacon_chain/spec/crypto.nim Lines 107 to 157 in 44f652f
|
Maybe we missed something here:
The
verify()
used by 'blsVerify()' functions in https://github.com/status-im/nimbus-eth2/blob/stable/beacon_chain/spec/crypto.nim ultimately callcoreVerifyNoGroupCheck()
from nim-blscurve, adding the warning:https://github.com/status-im/nim-blscurve/blob/fd4956f5d65129e9b475e654903a84303395eb92/blscurve/bls_sig_min_pubkey.nim#L120-L125
However,
publicFromPrivate()
does not do subgroup check (nor correct infinity point check, as noted in #2693), and the signature does not seem to be checked at all (as required in https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bls-signature-04#section-2.7).The text was updated successfully, but these errors were encountered: