Kaynağa Gözat

book: update broken link. run cargo fmt

lunar-mining 3 yıl önce
ebeveyn
işleme
29cfa5dc3c

+ 1 - 1
README.md

@@ -7,7 +7,7 @@
 
 ## Connect to DarkFi IRC
 
-Follow the [installation instructions](https://darkrenaissance.github.io/darkfi/misc/ircd.html#installation)
+Follow the [installation instructions](https://darkrenaissance.github.io/darkfi/misc/ircd/ircd.html)
 for the P2P IRC daemon.
 
 ## Build

+ 4 - 2
example/lead.rs

@@ -5,7 +5,10 @@ use url::Url;
 
 use darkfi::{
     consensus::ouroboros::{Epoch, EpochConsensus, Stakeholder},
-    crypto::{lead_proof, leadcoin::{LeadCoin, LEAD_PUBLIC_INPUT_LEN}},
+    crypto::{
+        lead_proof,
+        leadcoin::{LeadCoin, LEAD_PUBLIC_INPUT_LEN},
+    },
     net::Settings,
 };
 
@@ -15,7 +18,6 @@ fn main() {
     let k: u32 = 13;
     //
 
-
     let _value = 33223; //static stake value
 
     //

+ 5 - 3
src/consensus/ouroboros/epoch.rs

@@ -1,8 +1,8 @@
 use crate::{
     consensus::ouroboros::{
         consts::{LOTTERY_HEAD_START, RADIX_BITS},
-        utils::{fbig2ibig},
-        types::{Float10},
+        types::Float10,
+        utils::fbig2ibig,
         EpochConsensus,
     },
     crypto::{
@@ -299,7 +299,9 @@ impl Epoch {
         for (winning_idx, coin) in competing_coins.iter().enumerate() {
             let y_exp = [coin.root_sk.unwrap(), coin.nonce.unwrap()];
             let y_exp_hash: pallas::Base =
-                poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<2>, 3, 2>::init().hash(y_exp);
+                poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<2>, 3, 2>::init(
+                )
+                .hash(y_exp);
             let y_coordinates = pedersen_commitment_base(coin.y_mu.unwrap(), mod_r_p(y_exp_hash))
                 .to_affine()
                 .coordinates()

+ 2 - 2
src/consensus/ouroboros/stakeholder.rs

@@ -14,8 +14,8 @@ use crate::{
         address::Address,
         coin::OwnCoin,
         keypair::{PublicKey, SecretKey},
-        leadcoin::LeadCoin,
         lead_proof,
+        leadcoin::LeadCoin,
         proof::{Proof, ProvingKey, VerifyingKey},
         schnorr::SchnorrSecret,
     },
@@ -384,7 +384,7 @@ impl Stakeholder {
                 let p = self.epoch.get_proof(sl, i, &self.get_leadprovkingkey());
                 // Sanity check for proof validity)
                 info!("================= Leader proof generated successfully, veryfing... =================");
-                let coin = self.epoch.get_coin(sl as usize, i);                
+                let coin = self.epoch.get_coin(sl as usize, i);
                 match lead_proof::verify_lead_proof(&self.get_leadverifyingkey(), &p, &coin.public_inputs()) {
                     Ok(_) => info!("================= Proof veryfied succsessfully! ================="),
                     Err(e) => error!("================= Error during leader proof verification: {} =================", e),

+ 5 - 14
src/crypto/leadcoin.rs

@@ -64,10 +64,8 @@ impl LeadCoin {
         let po_y_y = *po_y_pt.to_affine().coordinates().unwrap().y();
         let y_coord_arr = [po_y_x, po_y_y];
         let po_y: pallas::Base =
-            poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<2>, 3, 2>::init(
-            )
-            .hash(y_coord_arr);
-
+            poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<2>, 3, 2>::init()
+                .hash(y_coord_arr);
 
         let cm_pos = self.idx;
         let cm_root = {
@@ -85,15 +83,8 @@ impl LeadCoin {
             }
             current
         };
-        let public_inputs: [pallas::Base; LEAD_PUBLIC_INPUT_LEN] = [
-            *po_cm.x(),
-            *po_cm.y(),
-            po_nonce,
-            cm_root.inner(),
-            *po_pk.x(),
-            *po_pk.y(),
-            po_y,
-        ];
+        let public_inputs: [pallas::Base; LEAD_PUBLIC_INPUT_LEN] =
+            [*po_cm.x(), *po_cm.y(), po_nonce, cm_root.inner(), *po_pk.x(), *po_pk.y(), po_y];
         public_inputs
     }
 
@@ -108,7 +99,7 @@ impl LeadCoin {
         let lottery_msg_input = [root_sk, nonce];
         let lottery_msg: pallas::Base =
             poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<2>, 3, 2>::init()
-            .hash(lottery_msg_input);
+                .hash(lottery_msg_input);
         //
         let rho_pt: pallas::Point = pedersen_commitment_base(lottery_msg, mod_r_p(rho_mu));
         LeadContract {

+ 7 - 16
src/zk/circuit/lead_contract.rs

@@ -9,7 +9,7 @@ use darkfi_sdk::crypto::{
 use halo2_gadgets::{
     ecc::{
         chip::{EccChip, EccConfig},
-        FixedPoint, FixedPointBaseField, ScalarFixed,NonIdentityPoint,
+        FixedPoint, FixedPointBaseField, NonIdentityPoint, ScalarFixed,
     },
     poseidon::{
         primitives as poseidon, Hash as PoseidonHash, Pow5Chip as PoseidonChip,
@@ -126,7 +126,7 @@ pub struct LeadContract {
     pub sigma1: Value<pallas::Base>,
     pub sigma2: Value<pallas::Base>,
     //pub eta : Option<u32>,
-    pub rho : Value<pallas::Point>,
+    pub rho: Value<pallas::Point>,
     //pub h : Option<u32>, // hash of this data
     //pub ptr: Option<u32>, //hash of the previous block
 }
@@ -616,7 +616,7 @@ impl Circuit<pallas::Base> for LeadContract {
             layouter.namespace(|| "witness rho"),
             self.rho.map(|x| x.to_affine()),
         )?;
-        rho_commit.constrain_equal(layouter.namespace(||""),&rho)?;
+        rho_commit.constrain_equal(layouter.namespace(|| ""), &rho)?;
         let term1 =
             ar_chip.mul(layouter.namespace(|| "calculate term1"), &sigma1, &coin_value.clone())?;
 
@@ -655,19 +655,13 @@ impl Circuit<pallas::Base> for LeadContract {
             LEAD_COIN_COMMIT_Y_OFFSET,
         )?;
 
-
         let ref_coin2_cm = NonIdentityPoint::new(
             ecc_chip.clone(),
             layouter.namespace(|| "witness coin2 cm"),
             self.coin2_commit.map(|x| x.to_affine()),
         )?;
 
-
-        coin2_commit.constrain_equal(
-            layouter.namespace(||""),
-            &ref_coin2_cm
-        )?;
-
+        coin2_commit.constrain_equal(layouter.namespace(|| ""), &ref_coin2_cm)?;
 
         /*
         layouter.constrain_instance(
@@ -694,11 +688,9 @@ impl Circuit<pallas::Base> for LeadContract {
         layouter.constrain_instance(coin_pk_x.cell(), config.primary, LEAD_COIN_PK_X_OFFSET)?;
         layouter.constrain_instance(coin_pk_y.cell(), config.primary, LEAD_COIN_PK_Y_OFFSET)?;
 
-        layouter.assign_region(||"",
-                               |mut region| {
-                                   region.constrain_equal(sn_commit.cell(),
-                                                          coin1_sn.cell())
-                               }
+        layouter.assign_region(
+            || "",
+            |mut region| region.constrain_equal(sn_commit.cell(), coin1_sn.cell()),
         );
 
         layouter.constrain_instance(
@@ -707,7 +699,6 @@ impl Circuit<pallas::Base> for LeadContract {
             LEAD_Y_COMMIT_BASE_OFFSET,
         )?;
 
-
         Ok(())
     }
 }