Эх сурвалжийг харах

fix fullrange check failed verfication in less than gadget

mohab metwally 3 жил өмнө
parent
commit
3d6a9e727c

+ 3 - 3
example/crypsinous.rs

@@ -172,9 +172,9 @@ async fn start(args: NetCli, ex: Arc<Executor<'_>>) -> Result<()> {
     p2p.clone().start(ex.clone()).await?;
     ex2.spawn(p2p.clone().run(ex.clone())).detach();
 
-    let slots = 10;
-    let epochs = 6;
-    let ticks = 30;
+    let slots = 3;
+    let epochs = 3;
+    let ticks = 3;
     let reward = 1;
     let epoch_consensus = EpochConsensus::new(Some(slots), Some(epochs), Some(ticks), Some(reward));
 

+ 13 - 16
example/less_than.rs

@@ -29,7 +29,7 @@ use log::{error, info};
 use rand::rngs::OsRng;
 
 use darkfi::{
-    consensus::{types::Float10, utils::fbig2base},
+    consensus::{types::Float10, utils::fbig2base, RADIX_BITS},
     crypto::{
         proof::{ProvingKey, VerifyingKey},
         Proof,
@@ -141,12 +141,12 @@ fn simple_lessthan(k: u32) -> Result<(), halo2_proofs::plonk::Error> {
 }
 
 fn fullrange_lessthan(k: u32) -> Result<(), halo2_proofs::plonk::Error> {
-    let y_str: &'static str = "0x057eaec1c805d808f70c4e2d2f173c72d091e9c9f78b11dddf52d072c30951ad";
-    let t_str: &'static str = "0x2cb8d8aec6766dc83595602e3050b0b908191bbe59dcc3d1e2b7020a37339a14";
+    let y_str: &'static str = "2485393101277319054866673974886504690592360759087472860138246047042221199789";
+    let t_str: &'static str = "20228360686725123198855333388287068776098384779255635716769234906173337213460";
     let y: pallas::Base =
-        fbig2base(Float10::from_str_native(y_str).unwrap().with_precision(74).value());
+        fbig2base(Float10::from_str_native(y_str).unwrap().with_precision(*RADIX_BITS).value());
     let t: pallas::Base =
-        fbig2base(Float10::from_str_native(t_str).unwrap().with_precision(74).value());
+        fbig2base(Float10::from_str_native(t_str).unwrap().with_precision(*RADIX_BITS).value());
 
     let circuit = LessThanCircuit { a: Value::known(y), b: Value::known(t) };
 
@@ -157,17 +157,14 @@ fn fullrange_lessthan(k: u32) -> Result<(), halo2_proofs::plonk::Error> {
     let public_inputs: Vec<pallas::Base> = vec![];
     let pk = ProvingKey::build(k, &LessThanCircuit::default());
     let vk = VerifyingKey::build(k, &LessThanCircuit::default());
-    let proof = Proof::create(&pk, &[circuit], &public_inputs, &mut OsRng)?;
-    match proof.verify(&vk, &public_inputs) {
-        Ok(()) => {
-            info!("proof verified");
-            Ok(())
-        }
-        Err(e) => {
-            error!("verification failed: {}", e);
-            Err(e)
-        }
-    }
+    let mut transcript = Blake2bWrite::<_, vesta::Affine, _>::init(vec![]);
+    plonk::create_proof(&pk.params, &pk.pk, &[circuit], &[&[]], &mut OsRng, &mut transcript)?;
+    let proof = transcript.finalize();
+    let strategy = SingleVerifier::new(&vk.params);
+    let mut transcript = Blake2bRead::init(&proof[..]);
+    plonk::verify_proof(&vk.params, &vk.vk, strategy, &[&[]], &mut transcript)?;
+
+    Ok(())
 }
 
 fn main() {

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

@@ -731,7 +731,7 @@ impl Circuit<pallas::Base> for LeadContract {
             y_commit_base,
             target,
             0,
-            true,
+            false,
         )?;
 
         Ok(())