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

[ouroboros] discrepancy is due to float/int conversion, debug info remove

mohab metwally 3 лет назад
Родитель
Сommit
f659c34d58
2 измененных файлов с 18 добавлено и 20 удалено
  1. 2 11
      src/consensus/ouroboros/epoch.rs
  2. 16 9
      src/consensus/ouroboros/utils.rs

+ 2 - 11
src/consensus/ouroboros/epoch.rs

@@ -11,9 +11,8 @@ use pasta_curves::{
 use rand::{thread_rng, Rng};
 use crate::{
     consensus::ouroboros::{
-        consts::{RADIX_BITS, LOTTERY_HEAD_START},
-        utils::{base2ibig, fbig2ibig},
-        EpochConsensus, Float10,
+        consts::{LOTTERY_HEAD_START},
+        EpochConsensus,
     },
     crypto::{
         coin::OwnCoin,
@@ -25,7 +24,6 @@ use crate::{
         util::{mod_r_p, pedersen_commitment_base, pedersen_commitment_u64},
     },
 };
-use dashu::base::Abs;
 
 const PRF_NULLIFIER_PREFIX: u64 = 0;
 const MERKLE_DEPTH: u8 = MERKLE_DEPTH_ORCHARD as u8;
@@ -313,13 +311,6 @@ impl Epoch {
             let val_base = pallas::Base::from(coin.value.unwrap());
             let target_base = coin.sigma1.unwrap() * val_base +
                 coin.sigma2.unwrap() * val_base * val_base;
-            let val_2ibig =
-                Float10::try_from(coin.value.unwrap()).unwrap().with_precision(RADIX_BITS).value();
-            let target_fbig = base2ibig(coin.sigma1.unwrap()) * val_2ibig.clone() + base2ibig(coin.sigma2.unwrap()) * val_2ibig.clone() * val_2ibig;
-            let target_ibig = fbig2ibig(target_fbig);
-            let target_ibig_ref = base2ibig(target_base);
-            // TODO (res) there is small discrepancy between base, and dashu
-            debug_assert!((target_ibig_ref - target_ibig).abs() < 100);
             info!("y: {:?}", y);
             info!("T: {:?}", target_base);
             let iam_leader = y < target_base;

+ 16 - 9
src/consensus/ouroboros/utils.rs

@@ -1,19 +1,24 @@
-use dashu::integer::{IBig, Sign, UBig};
-use log::info;
-use pasta_curves::{group::ff::PrimeField, pallas};
-
+use dashu::integer::{IBig, Sign};
+use log::{info,debug};
+use pasta_curves::{pallas};
 use crate::consensus::ouroboros::types::Float10;
+//use pasta_curves::{group::ff::PrimeField};
+//use dashu::integer::{UBig};
 
 pub(crate) fn fbig2ibig(f: Float10) -> IBig {
-    info!("fbig -> ibig (f): {}", f);
     let rad = IBig::try_from(10).unwrap();
     let sig = f.repr().significand();
     let exp = f.repr().exponent();
-    let val: IBig = if exp >= 0 { sig.clone() * rad.pow(exp as usize) } else { sig.clone() };
-    info!("fbig -> ibig (i): {}", val);
+    let val: IBig = if exp >= 0 {
+        sig.clone() * rad.pow(exp as usize)
+    } else {
+        sig.clone()
+    };
+    debug!("fbig2ibig (f): {}", f);
+    debug!("fbig2ibig (i): {}", val);
     val
 }
-
+/*
 pub(crate) fn base2ibig(base: pallas::Base) -> IBig {
     //
     let byts: [u8; 32] = base.to_repr();
@@ -28,7 +33,7 @@ pub(crate) fn base2ibig(base: pallas::Base) -> IBig {
     let ibig = IBig::from_parts(Sign::Positive, uparts);
     ibig
 }
-
+*/
 pub(crate) fn fbig2base(f: Float10) -> pallas::Base {
     info!("fbig -> base (f): {}", f);
     let val: IBig = fbig2ibig(f);
@@ -65,6 +70,7 @@ mod tests {
         assert_eq!(i, sig);
     }
 
+    /*
     #[test]
     fn dashu_test_base2ibig() {
         //
@@ -79,4 +85,5 @@ mod tests {
         let res_ibig: IBig = base2ibig(res_base);
         assert_eq!(res_ibig, ibig);
     }
+    */
 }