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

bin/darkirc: do not insert non-genesis event

dasman 1 месяц назад
Родитель
Сommit
757ee1c4cc
2 измененных файлов с 52 добавлено и 61 удалено
  1. 35 38
      bin/darkirc/src/crypto/rln.rs
  2. 17 23
      bin/darkirc/src/irc/services/nickserv.rs

+ 35 - 38
bin/darkirc/src/crypto/rln.rs

@@ -18,10 +18,7 @@
 
 use darkfi::{
     event_graph::{
-        rln::{
-            epoch_of, hash_event, Blob, RegistrationAttestation, RegistrationBlob, MAX_MSG_LIMIT,
-            RLN2_REGISTER_ZKBIN, RLN2_SIGNAL_ZKBIN,
-        },
+        rln::{epoch_of, hash_event, Blob, RegistrationAttestation, RLN2_SIGNAL_ZKBIN},
         Event, EventGraphPtr,
     },
     zk::{
@@ -136,40 +133,40 @@ impl RlnIdentity {
     /// Build a [`RegistrationBlob`] suitable for broadcast as a
     /// `StaticPut`. The proving key comes from the EventGraph's
     /// shared `ZkKeys` cache.
-    pub fn create_registration(&self, eg: &EventGraphPtr) -> Result<RegistrationBlob> {
-        let zkbin = ZkBinary::decode(RLN2_REGISTER_ZKBIN, false)?;
-
-        // Witness order MUST match the rlnv2-diff-register.zk circuit.
-        let witnesses = vec![
-            Witness::Base(Value::known(self.nullifier)),
-            Witness::Base(Value::known(self.trapdoor)),
-            Witness::Base(Value::known(pallas::Base::from(self.user_message_limit))),
-            Witness::Base(Value::known(pallas::Base::from(MAX_MSG_LIMIT))),
-        ];
-        // Public-input order MUST match `constrain_instance` in the
-        // same .zk file.
-        let pi = vec![
-            self.commitment(),
-            pallas::Base::from(self.user_message_limit),
-            pallas::Base::from(MAX_MSG_LIMIT),
-        ];
-        let circuit = ZkCircuit::new(witnesses, &zkbin);
-        let pk = eg.zk_keys.load_register_pk()?;
-
-        info!(
-            target: "darkirc::crypto::rln",
-            "[RLN] Creating registration proof for commitment {:?}",
-            self.commitment(),
-        );
-        let proof = Proof::create(&pk, &[circuit], &pi, &mut OsRng)?;
-
-        Ok(RegistrationBlob {
-            proof,
-            user_message_limit: self.user_message_limit,
-            max_message_limit: MAX_MSG_LIMIT,
-            attestation: RegistrationAttestation::SPECIAL,
-        })
-    }
+    // pub fn create_registration(&self, eg: &EventGraphPtr) -> Result<RegistrationBlob> {
+    //     let zkbin = ZkBinary::decode(RLN2_REGISTER_ZKBIN, false)?;
+
+    //     // Witness order MUST match the rlnv2-diff-register.zk circuit.
+    //     let witnesses = vec![
+    //         Witness::Base(Value::known(self.nullifier)),
+    //         Witness::Base(Value::known(self.trapdoor)),
+    //         Witness::Base(Value::known(pallas::Base::from(self.user_message_limit))),
+    //         Witness::Base(Value::known(pallas::Base::from(MAX_MSG_LIMIT))),
+    //     ];
+    //     // Public-input order MUST match `constrain_instance` in the
+    //     // same .zk file.
+    //     let pi = vec![
+    //         self.commitment(),
+    //         pallas::Base::from(self.user_message_limit),
+    //         pallas::Base::from(MAX_MSG_LIMIT),
+    //     ];
+    //     let circuit = ZkCircuit::new(witnesses, &zkbin);
+    //     let pk = eg.zk_keys.load_register_pk()?;
+
+    //     info!(
+    //         target: "darkirc::crypto::rln",
+    //         "[RLN] Creating registration proof for commitment {:?}",
+    //         self.commitment(),
+    //     );
+    //     let proof = Proof::create(&pk, &[circuit], &pi, &mut OsRng)?;
+
+    //     Ok(RegistrationBlob {
+    //         proof,
+    //         user_message_limit: self.user_message_limit,
+    //         max_message_limit: MAX_MSG_LIMIT,
+    //         attestation: RegistrationAttestation::SPECIAL,
+    //     })
+    // }
 
     /// Build a signal [`Blob`] for the given event using `message_id`.
     ///

+ 17 - 23
bin/darkirc/src/irc/services/nickserv.rs

@@ -80,17 +80,17 @@ pub const ACCOUNTS_KEY_RLN_IDENTITY: &[u8] = b"rln_identity";
 /// `IrcServer::new` reads this on startup.
 pub const ACCOUNTS_DEFAULT_TREE: &str = "darkirc_account_default";
 
-/// Outcome of the `static_broadcast` call inside REGISTER. Used to
-/// pick which "what just happened" notice we send back to the user.
-#[derive(PartialEq, Eq)]
-enum BroadcastStatus {
-    /// Local node was synced; broadcast was issued immediately.
-    Sent,
-    /// Local node was unsynced; the (event, blob) pair was queued
-    /// in `IrcServer::pending_static_broadcasts` and a watcher task
-    /// will broadcast it once sync completes.
-    Deferred,
-}
+// /// Outcome of the `static_broadcast` call inside REGISTER. Used to
+// /// pick which "what just happened" notice we send back to the user.
+// #[derive(PartialEq, Eq)]
+// enum BroadcastStatus {
+//     /// Local node was synced; broadcast was issued immediately.
+//     Sent,
+//     /// Local node was unsynced; the (event, blob) pair was queued
+//     /// in `IrcServer::pending_static_broadcasts` and a watcher task
+//     /// will broadcast it once sync completes.
+//     Deferred,
+// }
 
 const NICKSERV_USAGE: &str = r#"***** NickServ Help *****
 
@@ -533,19 +533,11 @@ impl NickServ {
                 ));
             }
             return Ok(replies)
+        } else {
+            let replies =
+                vec![notice(nick, format!("Failed to register account \"{account_name}\""))];
+            return Ok(replies)
         }
-
-        // Build the static-DAG event and the registration blob.
-        // The blob format is `RegistrationBlob` (proof +
-        // user_message_limit + max_message_limit + attestation),
-        // verified by the EG via `rln_verify_static_event`.
-        let evgr = &self.server.darkirc.event_graph;
-        let rln_node = RLNNode::Registration(new_rln_identity.commitment());
-        let event = Event::new_static(serialize_async(&rln_node).await, evgr).await;
-
-        let registration_blob = new_rln_identity.create_registration(evgr)?;
-        let blob_bytes = serialize_async(&registration_blob).await;
-
         // Apply the registration through the canonical pipeline:
         //
         // 1. `apply_rln_static_event` mutates the SMT and records
@@ -568,6 +560,7 @@ impl NickServ {
         //    too). When unsynced, we defer the broadcast to a
         //    watcher task that drains the pending queue once sync
         //    completes.
+        /*
         evgr.apply_rln_static_event(&event, &rln_node).await?;
         evgr.static_blob_store(&event.id(), &blob_bytes)?;
         evgr.static_insert(&event).await?;
@@ -600,6 +593,7 @@ impl NickServ {
         }
 
         Ok(replies)
+        */
     }
 
     /// Handle the DEREGISTER command.