Răsfoiți Sursa

[ouroboros] even number array for hash

mohab metwally 3 ani în urmă
părinte
comite
b1ad2e6351

+ 1 - 1
src/consensus/ouroboros/consts.rs

@@ -3,4 +3,4 @@ pub(crate) const LOG_T: &str = "stakeholder";
 pub(crate) const TREE_LEN: usize = 100;
 pub(crate) const P: &str =
     "28948022309329048855892746252171976963363056481941560715954676764349967630337";
-pub(crate) const LOTTERY_HEAD_START : u64 = 0;
+pub(crate) const LOTTERY_HEAD_START : u64 = 1;

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

@@ -198,6 +198,7 @@ impl Epoch {
         let keypair: Keypair = Keypair::new(sk);
         //random commitment blinding values
         let mut rng = thread_rng();
+        let one = pallas::Base::one();
         let c_cm1_blind: DrkValueBlind = pallas::Scalar::random(&mut rng);
         let c_cm2_blind: DrkValueBlind = pallas::Scalar::random(&mut rng);
         let mut tree_cm = BridgeTree::<MerkleNode, MERKLE_DEPTH>::new(self.len());
@@ -223,9 +224,9 @@ impl Epoch {
                 .hash(sn_msg);
 
         let coin_commit_msg_input =
-            [pallas::Base::from(PRF_NULLIFIER_PREFIX), *c_pk_x, *c_pk_y, c_v, c_seed];
+            [pallas::Base::from(PRF_NULLIFIER_PREFIX), *c_pk_x, *c_pk_y, c_v, c_seed, one];
         let coin_commit_msg: pallas::Base =
-            poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<5>, 3, 2>::init()
+            poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<6>, 3, 2>::init()
                 .hash(coin_commit_msg_input);
         let c_cm: pallas::Point = pedersen_commitment_base(coin_commit_msg, c_cm1_blind);
         let c_cm_coordinates = c_cm.to_affine().coordinates().unwrap();
@@ -242,9 +243,9 @@ impl Epoch {
                 .hash(coin_nonce2_msg);
 
         let coin2_commit_msg_input =
-            [pallas::Base::from(PRF_NULLIFIER_PREFIX), *c_pk_x, *c_pk_y, c_v, c_seed2];
+            [pallas::Base::from(PRF_NULLIFIER_PREFIX), *c_pk_x, *c_pk_y, c_v, c_seed2, one];
         let coin2_commit_msg: pallas::Base =
-            poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<5>, 3, 2>::init()
+            poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<6>, 3, 2>::init()
                 .hash(coin2_commit_msg_input);
         let c_cm2 = pedersen_commitment_base(coin2_commit_msg, c_cm2_blind);
 

+ 11 - 4
src/zk/circuit/lead_contract.rs

@@ -36,6 +36,7 @@ use crate::zk::gadget::{
     less_than::{LessThanChip, LessThanConfig},
     native_range_check::NativeRangeCheckChip,
 };
+use log::info;
 
 const WINDOW_SIZE: usize = 3;
 const NUM_OF_BITS: usize = 254;
@@ -340,6 +341,12 @@ impl Circuit<pallas::Base> for LeadContract {
             Value::known(pallas::Base::one()), // note! this parameter to be tuned.
         )?;
 
+        let one = self.load_private(
+            layouter.namespace(|| "one"),
+            config.advices[0],
+            Value::known(pallas::Base::one()),
+        )?;
+
         // the original crypsinous pk is as follows.
         // coin public key pk=PRF_{root_sk}(tau)
         // coin public key is pseudo random hash of concatenation of the following:
@@ -391,7 +398,6 @@ impl Circuit<pallas::Base> for LeadContract {
             let poseidon_output: AssignedCell<Fp, Fp> = poseidon_output;
             poseidon_output
         };
-
         // commitment to the staking coin
         // coin commiment H=COMMIT(PRF(prefix||pk||V||nonce), r)
         let com = {
@@ -404,12 +410,13 @@ impl Circuit<pallas::Base> for LeadContract {
                     coin_pk_y.clone(),
                     coin_value.clone(),
                     coin_nonce.clone(),
+                    one.clone(),
                 ];
                 let poseidon_hasher = PoseidonHash::<
                     _,
                     _,
                     poseidon::P128Pow5T3,
-                    poseidon::ConstantLength<5>,
+                    poseidon::ConstantLength<6>,
                     3,
                     2,
                 >::init(
@@ -463,7 +470,6 @@ impl Circuit<pallas::Base> for LeadContract {
             let poseidon_output: AssignedCell<Fp, Fp> = poseidon_output;
             poseidon_output
         };
-
         // coin2 commiment H=COMMIT(PRF(pk||V||nonce2), r2)
         // poured coin's commitment is a nullifier
         let com2 = {
@@ -476,12 +482,13 @@ impl Circuit<pallas::Base> for LeadContract {
                     coin_pk_y.clone(),
                     coin_value.clone(),
                     coin2_nonce.clone(),
+                    one.clone()
                 ];
                 let poseidon_hasher = PoseidonHash::<
                     _,
                     _,
                     poseidon::P128Pow5T3,
-                    poseidon::ConstantLength<5>,
+                    poseidon::ConstantLength<6>,
                     3,
                     2,
                 >::init(