Просмотр исходного кода

sdk/ecvrf: Enforce that the public key is not the identity point

parazyd 2 лет назад
Родитель
Сommit
8636fb2641
1 измененных файлов с 6 добавлено и 1 удалено
  1. 6 1
      src/sdk/src/crypto/ecvrf.rs

+ 6 - 1
src/sdk/src/crypto/ecvrf.rs

@@ -27,7 +27,7 @@ use pasta_curves::{
     arithmetic::CurveExt,
     group::{
         ff::{Field, FromUniformBytes},
-        GroupEncoding,
+        Group, GroupEncoding,
     },
     pallas,
 };
@@ -51,6 +51,7 @@ impl VrfProof {
     /// a seed input `alpha_string`, and an RNG instance.
     pub fn prove(x: SecretKey, alpha_string: &[u8], rng: &mut (impl CryptoRng + RngCore)) -> Self {
         let Y = PublicKey::from_secret(x);
+        assert!(!bool::from(Y.inner().is_identity()));
 
         let mut message = vec![];
         message.extend_from_slice(&Y.to_bytes());
@@ -80,6 +81,10 @@ impl VrfProof {
 
     /// Verify a `VrfProof` given a `Publickey` and a seed input `alpha_string`.
     pub fn verify(&self, Y: PublicKey, alpha_string: &[u8]) -> bool {
+        if bool::from(Y.inner().is_identity()) {
+            return false
+        }
+
         let mut message = vec![];
         message.extend_from_slice(&Y.to_bytes());
         message.extend_from_slice(alpha_string);