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

[consensus/coins] fix leaf position, used api over ++local state, as internal working of incmerkletree isn't simple ++

mohab metwally 3 лет назад
Родитель
Сommit
a9036f4f7c
2 измененных файлов с 22 добавлено и 7 удалено
  1. 6 4
      src/consensus/coins.rs
  2. 16 3
      src/zk/circuit/lead_contract.rs

+ 6 - 4
src/consensus/coins.rs

@@ -260,12 +260,14 @@ fn create_leadcoin(
     let c_cm_msg = [*c_cm_coordinates.x(), *c_cm_coordinates.y()];
     let c_cm_base: pallas::Base =
         poseidon::Hash::<_, poseidon::P128Pow5T3, poseidon::ConstantLength<2>, 3, 2>::init()
-            .hash(c_cm_msg);
+        .hash(c_cm_msg);
     let c_cm_node = MerkleNode::from(c_cm_base);
     tree_cm.append(&c_cm_node.clone());
-    let leaf_position = tree_cm.witness();
+    let leaf_position = tree_cm.witness().unwrap();
+    let leaf_position_usize : usize = leaf_position.into();
+    //info!("leaf position odd parity: {:?}", leaf_position.is_odd());
     let c_root_cm = tree_cm.root(0).unwrap();
-    let c_cm_path = tree_cm.authentication_path(leaf_position.unwrap(), &c_root_cm).unwrap();
+    let c_cm_path = tree_cm.authentication_path(leaf_position, &c_root_cm).unwrap();
 
     /*
     let c_root_cm = {
@@ -301,7 +303,7 @@ fn create_leadcoin(
         value: Some(value),
         cm: Some(c_cm),
         cm2: Some(c_cm2),
-        idx: u32::try_from(i).unwrap(), //TODO should be abs slot
+        idx: u32::try_from(leaf_position_usize).unwrap(), //TODO should be abs slot
         sl: Some(c_sl),
         tau: Some(c_tau),
         nonce: Some(c_seed),

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

@@ -59,6 +59,7 @@ use crate::zk::{
         native_range_check::NativeRangeCheckChip,
     },
 };
+use log::info;
 
 /// Public input offset for the lead coin C2 nonce
 const LEADCOIN_C2_NONCE_OFFSET: usize = 0;
@@ -672,6 +673,8 @@ impl Circuit<pallas::Base> for LeadContract {
         let T: Value<pallas::Base> = target.value().cloned();
         let y: Value<pallas::Base> = y_commit_base.value().cloned();
 
+        info!("y: {:?}", y);
+        info!("T: {:?}", T);
         // Constrain y < target
         lessthan_chip.copy_less_than(
             layouter.namespace(|| "y < target"),
@@ -680,23 +683,33 @@ impl Circuit<pallas::Base> for LeadContract {
             0,
             true,
         )?;
-
         // Constrain derived `sn_commit` to be equal to witnessed `coin1_serial`.
-
+        info!("coin1 cm root LHS: {:?}", coin1_cm_root.value());
+        info!("coin1 cm root RHS: {:?}", coin1_commit_root.value());
         layouter.assign_region(
             || "coin1_cm_root equality",
             |mut region| region.constrain_equal(coin1_cm_root.cell(), coin1_commit_root.cell()),
         )?;
-
+        info!("coin1 serial commit LHS: {:?}", sn_commit.value());
+        info!("coin1 serial commit RHS: {:?}", coin1_serial.value());
         layouter.assign_region(
             || "sn_commit equality",
             |mut region| region.constrain_equal(sn_commit.cell(), coin1_serial.cell()),
         )?;
 
+
+        info!("coin2_commit LHS: x {:?}", coin2_commitment.inner().x());
+        info!("coin2_commit LHS: y {:?}", coin2_commitment.inner().y());
+        info!("coin2_commit RHS: x {:?}", coin2_commit.inner().x());
+        info!("coin2_commit RHS: y {:?}", coin2_commit.inner().y());
         // Constrain equality between witnessed and derived commitment
         coin2_commitment
             .constrain_equal(layouter.namespace(|| "coin2_commit equality"), &coin2_commit)?;
 
+        info!("rho commit LHS: x {:?}", rho_commit.inner().x());
+        info!("rho commit LHS: y {:?}", rho_commit.inner().y());
+        info!("rho commit RHS: x {:?}", rho.inner().x());
+        info!("rho commit RHS: y {:?}", rho.inner().y());
         // Constrain derived rho_commit to witnessed rho
         rho_commit.constrain_equal(layouter.namespace(|| "rho equality"), &rho)?;