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

halo2: Move generic function to lib.rs

parazyd 5 лет назад
Родитель
Сommit
1e6ed3d959
4 измененных файлов с 27 добавлено и 16 удалено
  1. 1 0
      examples/halo2/Cargo.lock
  2. 5 0
      examples/halo2/Cargo.toml
  3. 3 16
      examples/halo2/src/bin/mint.rs
  4. 18 0
      examples/halo2/src/lib.rs

+ 1 - 0
examples/halo2/Cargo.lock

@@ -331,6 +331,7 @@ dependencies = [
  "orchard",
  "pasta_curves",
  "rand",
+ "sinsemilla",
  "subtle",
 ]
 

+ 5 - 0
examples/halo2/Cargo.toml

@@ -35,6 +35,11 @@ rev = "f9cc01c21010b31988129f9cbc2ca8c0bdbf2ee9"
 [dependencies.halo2_ecc]
 git = "https://github.com/parazyd/orchard.git"
 #rev = "0d14f2390734e4710fc24a976f037dae3a6e7ac8"
+rev = "f9cc01c21010b31988129f9cbc2ca8c0bdbf2ee9"
+
+[dependencies.sinsemilla]
+git = "https://github.com/parazyd/orchard.git"
+#rev = "0d14f2390734e4710fc24a976f037dae3a6e7ac8"
 rev = "f9cc01c21010b31988129f9cbc2ca8c0bdbf2ee9"
 
  [dependencies.orchard]

+ 3 - 16
examples/halo2/src/bin/mint.rs

@@ -2,7 +2,7 @@ use std::{convert::TryInto, time::Instant};
 
 use group::{ff::Field, Curve, Group};
 use halo2::{
-    arithmetic::{CurveAffine, CurveExt, FieldExt},
+    arithmetic::CurveAffine,
     circuit::{floor_planner, Layouter},
     dev::MockProver,
     pasta::{vesta, Ep, Fp, Fq},
@@ -20,13 +20,10 @@ use halo2_poseidon::{
 use halo2_utilities::{
     lookup_range_check::LookupRangeCheckConfig, CellValue, UtilitiesInstructions, Var,
 };
-use orchard::constants::fixed_bases::{
-    OrchardFixedBases, VALUE_COMMITMENT_PERSONALIZATION, VALUE_COMMITMENT_R_BYTES,
-    VALUE_COMMITMENT_V_BYTES,
-};
+use orchard::constants::fixed_bases::OrchardFixedBases;
 use rand::rngs::OsRng;
 
-use halo2_examples::circuit::Config;
+use halo2_examples::{circuit::Config, pedersen_commitment};
 
 const K: u32 = 9;
 
@@ -361,16 +358,6 @@ impl Proof {
     // }
 }
 
-#[allow(non_snake_case)]
-fn pedersen_commitment(value: u64, blind: Fq) -> Ep {
-    let hasher = Ep::hash_to_curve(VALUE_COMMITMENT_PERSONALIZATION);
-    let V = hasher(&VALUE_COMMITMENT_V_BYTES);
-    let R = hasher(&VALUE_COMMITMENT_R_BYTES);
-    let value = Fq::from_u64(value);
-
-    V * value + R * blind
-}
-
 fn main() {
     let pubkey = Ep::random(&mut OsRng);
     let coords = pubkey.to_affine().coordinates().unwrap();

+ 18 - 0
examples/halo2/src/lib.rs

@@ -1 +1,19 @@
 pub mod circuit;
+
+use halo2::{
+    arithmetic::{CurveExt, FieldExt},
+    pasta::{Ep, Fq},
+};
+use orchard::constants::fixed_bases::{
+    VALUE_COMMITMENT_PERSONALIZATION, VALUE_COMMITMENT_R_BYTES, VALUE_COMMITMENT_V_BYTES,
+};
+
+#[allow(non_snake_case)]
+pub fn pedersen_commitment(value: u64, blind: Fq) -> Ep {
+    let hasher = Ep::hash_to_curve(VALUE_COMMITMENT_PERSONALIZATION);
+    let V = hasher(&VALUE_COMMITMENT_V_BYTES);
+    let R = hasher(&VALUE_COMMITMENT_R_BYTES);
+    let value = Fq::from_u64(value);
+
+    V * value + R * blind
+}