Przeglądaj źródła

various (unfinished) updates for vm2

narodnik 4 lat temu
rodzic
commit
cd68506b74
4 zmienionych plików z 86 dodań i 56 usunięć
  1. 14 29
      example/vm/Cargo.toml
  2. 1 1
      example/vm/doit.sh
  3. 38 7
      example/vm/src/arith_chip.rs
  4. 33 19
      example/vm/src/vm2.rs

+ 14 - 29
example/vm/Cargo.toml

@@ -2,46 +2,31 @@
 name = "halo2_examples"
 version = "0.1.0"
 authors = ["narodnik <x@x.org>"]
-edition = "2018"
+edition = "2021"
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
 ff = "0.10"
 group = "0.10"
-pasta_curves = "0.1.2"
-bitvec = "0.22"
+pasta_curves = "0.2.1"
+
 rand = "0.8.4"
+hex = "0.4.3"
+
+# Can we delete these?
+bitvec = "0.22"
 arrayvec = "0.7.0"
 lazy_static = "1"
 bigint = "4"
 subtle = "2.3"
-halo2 = "0.0"
-
-[patch.crates-io]
-halo2 = { git = "https://github.com/zcash/halo2.git", rev = "27c4187673a9c6ade13fbdbd4f20955530c22d7f" }
-
-[dependencies.halo2_poseidon]
-git = "https://github.com/parazyd/orchard.git"
-#rev = "0d14f2390734e4710fc24a976f037dae3a6e7ac8"
-rev = "f9cc01c21010b31988129f9cbc2ca8c0bdbf2ee9"
-features = ["halo2"]
-
-[dependencies.halo2_utilities]
-git = "https://github.com/parazyd/orchard.git"
-#rev = "0d14f2390734e4710fc24a976f037dae3a6e7ac8"
-rev = "f9cc01c21010b31988129f9cbc2ca8c0bdbf2ee9"
 
-[dependencies.halo2_ecc]
-git = "https://github.com/parazyd/orchard.git"
-#rev = "0d14f2390734e4710fc24a976f037dae3a6e7ac8"
-rev = "f9cc01c21010b31988129f9cbc2ca8c0bdbf2ee9"
+[dependencies.halo2]
+version = "=0.1.0-beta.1"
+features = ["dev-graph", "gadget-traces", "sanity-checks"]
 
-[dependencies.sinsemilla]
-git = "https://github.com/parazyd/orchard.git"
-#rev = "0d14f2390734e4710fc24a976f037dae3a6e7ac8"
-rev = "f9cc01c21010b31988129f9cbc2ca8c0bdbf2ee9"
+[dependencies.halo2_gadgets]
+git = "https://github.com/parazyd/halo2_gadgets.git"
+rev = "8238cb3471b798c76dd53b278524fc80685c7d4f"
+features = ["dev-graph", "test-dependencies"]
 
- [dependencies.orchard]
-git = "https://github.com/parazyd/orchard.git"
-rev = "f9cc01c21010b31988129f9cbc2ca8c0bdbf2ee9"

+ 1 - 1
example/vm/doit.sh

@@ -4,6 +4,6 @@ python script/zkas.py proof/mint.zk --bincode
 du -sh proof/mint.zk.bin
 python script/zkas.py proof/mint.zk
 #python script/zkas.py proof/mint.zk
-cd examples/vm/
+cd example/vm/
 cargo run --release --bin vm2
 

+ 38 - 7
example/vm/src/arith_chip.rs

@@ -1,16 +1,47 @@
 use halo2::{
-    circuit::{SimpleFloorPlanner, Cell, Chip, Layouter},
-    pasta::{EqAffine, Fp, pallas},
-    plonk::{Advice, Any, Circuit, Column, ConstraintSystem, Error, Expression, Selector, create_proof, verify_proof, keygen_vk, keygen_pk/*, Permutation*/},
-    poly::{commitment::{Blind, Params}, Rotation},
-    transcript::{Blake2bRead, Blake2bWrite, Challenge255},
+    circuit::{Layouter, Chip, SimpleFloorPlanner},
+    dev::MockProver,
+    plonk::{
+        Advice, Circuit, Column, ConstraintSystem, Error, Instance as InstanceColumn, Selector,
+    },
+    poly::Rotation,
+};
+use halo2_gadgets::{
+    ecc::{
+        chip::{EccChip, EccConfig},
+        FixedPoint, FixedPoints,
+    },
+    poseidon::{
+        Hash as PoseidonHash, Pow5T3Chip as PoseidonChip, Pow5T3Config as PoseidonConfig,
+        StateWord, Word,
+    },
+    primitives,
+    primitives::{
+        poseidon::{ConstantLength, P128Pow5T3},
+        sinsemilla::S_PERSONALIZATION,
+    },
+    sinsemilla::{
+        chip::{SinsemillaChip, SinsemillaConfig},
+        merkle::chip::{MerkleChip, MerkleConfig},
+        merkle::MerklePath,
+    },
+    utilities::{
+        lookup_range_check::LookupRangeCheckConfig, CellValue, UtilitiesInstructions, Var,
+    },
+};
+use pasta_curves::{
+    arithmetic::{CurveAffine, Field},
+    group::{ff::PrimeFieldBits, Curve},
+    pallas,
 };
-use halo2_utilities::{CellValue, Var};
-use group::Curve;
 use std::time::Instant;
 
 type Variable = CellValue<pallas::Base>;
 
+// Replace with use pasta::Fp and pasta::Fq
+type Fp = pallas::Base;
+type Fq = pallas::Scalar;
+
 #[derive(Clone, Debug)]
 pub struct ArithmeticChipConfig {
     a_col: Column<Advice>,

+ 33 - 19
example/vm/src/vm2.rs

@@ -1,29 +1,43 @@
+use std::collections::HashMap;
+use std::{convert::TryInto, time::Instant};
+
 use halo2::{
     circuit::{Layouter, SimpleFloorPlanner},
-    pasta::pallas,
+    dev::MockProver,
     plonk,
     plonk::{
-        Advice, Circuit, Column, ConstraintSystem, Error as PlonkError, Instance as InstanceColumn,
-        Selector,
+        Advice, Circuit, Column, ConstraintSystem, Instance as InstanceColumn, Selector,
     },
+    poly::Rotation,
 };
-use std::collections::HashMap;
-use std::{convert::TryInto, time::Instant};
-
-use halo2_ecc::{
-    chip::{EccChip, EccConfig},
-    gadget::FixedPoint,
-};
-use halo2_poseidon::{
-    gadget::{Hash as PoseidonHash, Word},
-    pow5t3::{Pow5T3Chip as PoseidonChip, Pow5T3Config as PoseidonConfig, StateWord},
-    primitive::{ConstantLength, Hash, P128Pow5T3 as OrchardNullifier},
+use halo2_gadgets::{
+    ecc::{
+        chip::{EccChip, EccConfig},
+        FixedPoint, FixedPoints,
+    },
+    poseidon::{
+        Hash as PoseidonHash, Pow5T3Chip as PoseidonChip, Pow5T3Config as PoseidonConfig,
+        StateWord, Word,
+    },
+    primitives,
+    primitives::{
+        poseidon::{ConstantLength, P128Pow5T3},
+        sinsemilla::S_PERSONALIZATION,
+    },
+    sinsemilla::{
+        chip::{SinsemillaChip, SinsemillaConfig},
+        merkle::chip::{MerkleChip, MerkleConfig},
+        merkle::MerklePath,
+    },
+    utilities::{
+        lookup_range_check::LookupRangeCheckConfig, CellValue, UtilitiesInstructions, Var,
+    },
 };
-use halo2_utilities::{
-    lookup_range_check::LookupRangeCheckConfig, CellValue, UtilitiesInstructions, Var,
+use pasta_curves::{
+    arithmetic::{CurveAffine, Field},
+    group::{ff::PrimeFieldBits, Curve},
+    pallas,
 };
-use orchard::constants::{OrchardCommitDomains, OrchardFixedBases, OrchardHashDomains};
-use sinsemilla::chip::{SinsemillaChip, SinsemillaConfig};
 
 use crate::arith_chip::{ArithmeticChipConfig, ArithmeticChip};
 use crate::error::{Error, Result};
@@ -260,7 +274,7 @@ impl<'a> Circuit<pallas::Base> for ZkCircuit<'a> {
         &self,
         config: Self::Config,
         mut layouter: impl Layouter<pallas::Base>,
-    ) -> std::result::Result<(), PlonkError> {
+    ) -> std::result::Result<(), plonk::Error> {
         let ecc_chip = config.ecc_chip();
         let arith_chip = config.arithmetic_chip();