Răsfoiți Sursa

[ouroboros] change y to hash of y coordinates instead of single coordinate x/y

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

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

@@ -306,6 +306,10 @@ impl Epoch {
             //
             //
             let y_x: pallas::Base = *y_coordinates.x();
             let y_x: pallas::Base = *y_coordinates.x();
             let y_y: pallas::Base = *y_coordinates.y();
             let y_y: pallas::Base = *y_coordinates.y();
+            let y_coord_arr = [y_x, y_y];
+            let y: pallas::Base =
+                poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<2>, 3, 2>::init()
+                .hash(y_coord_arr);
             //
             //
             let val_2ibig =
             let val_2ibig =
                 Float10::try_from(coin.value.unwrap()).unwrap().with_precision(RADIX_BITS).value();
                 Float10::try_from(coin.value.unwrap()).unwrap().with_precision(RADIX_BITS).value();
@@ -317,7 +321,7 @@ impl Epoch {
             let y_ibig = base2ibig(y_x);
             let y_ibig = base2ibig(y_x);
             info!("y_x: {}, target ibig: {}", y_ibig, target_ibig);
             info!("y_x: {}, target ibig: {}", y_ibig, target_ibig);
             info!("target base: {:?}", target_base);
             info!("target base: {:?}", target_base);
-            let iam_leader = y_x < target_base;
+            let iam_leader = y < target_base;
             if iam_leader {
             if iam_leader {
                 if coin.value.unwrap() > highest_stake {
                 if coin.value.unwrap() > highest_stake {
                     highest_stake = coin.value.unwrap();
                     highest_stake = coin.value.unwrap();

+ 1 - 7
src/consensus/ouroboros/mod.rs

@@ -2,17 +2,11 @@ use std::{fmt, thread, time::Duration};
 use async_std::sync::Arc;
 use async_std::sync::Arc;
 use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode};
 use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode};
 use halo2_proofs::arithmetic::Field;
 use halo2_proofs::arithmetic::Field;
-use log::{error, info};
 use smol::Executor;
 use smol::Executor;
-use std::fmt;
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
-use std::{thread, time::Duration};
-use crate::zk::circuit::{BurnContract, LeadContract, MintContract};
 use incrementalmerkletree::bridgetree::BridgeTree;
 use incrementalmerkletree::bridgetree::BridgeTree;
-use log::{debug, error, info};
+use log::{error, info};
 use pasta_curves::{group::ff::PrimeField, pallas};
 use pasta_curves::{group::ff::PrimeField, pallas};
-use rand::rngs::OsRng;
-use smol::Executor;
 use url::Url;
 use url::Url;
 use crate::{
 use crate::{
     blockchain::Blockchain,
     blockchain::Blockchain,

+ 19 - 1
src/zk/circuit/lead_contract.rs

@@ -576,8 +576,26 @@ impl Circuit<pallas::Base> for LeadContract {
             y_commit_r.mul(layouter.namespace(|| "coin serial number commit R"), mau_y)?
             y_commit_r.mul(layouter.namespace(|| "coin serial number commit R"), mau_y)?
         };
         };
         let y_commit = com.add(layouter.namespace(|| "nonce commit"), &blind)?;
         let y_commit = com.add(layouter.namespace(|| "nonce commit"), &blind)?;
-        let y_commit_base = y_commit.inner().x();
+        let y_commit_base_y = y_commit.inner().x();
+        let y_commit_base_x = y_commit.inner().x();
+        let y_commit_base : AssignedCell<Fp, Fp> = {
+            let y_coord = [y_commit_base_y, y_commit_base_x];
+            let poseidon_hasher = PoseidonHash::<
+                    _,
+                _,
+                poseidon::P128Pow5T3,
+                poseidon::ConstantLength<2>,
+                3,
+                2,
+                >::init(
+                config.poseidon_chip(), layouter.namespace(|| "Poseidon init")
+            )?;
 
 
+            let poseidon_output =
+                poseidon_hasher.hash(layouter.namespace(|| "Poseidon hash"), y_coord)?;
+            let poseidon_output: AssignedCell<Fp, Fp> = poseidon_output;
+            poseidon_output
+        };
         // constraint rho as COMIT(PRF(root_sk||nonce), rho_mu)
         // constraint rho as COMIT(PRF(root_sk||nonce), rho_mu)
         // r*G_2
         // r*G_2
         let (blind, _) = {
         let (blind, _) = {