From 12e1cab7ba6feee6040aeebf600a5a435d0ade2f Mon Sep 17 00:00:00 2001 From: Paul Cadman Date: Tue, 27 Jun 2023 14:59:14 +0100 Subject: [PATCH 1/2] Update vamp-ir version --- taiga_halo2/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taiga_halo2/Cargo.toml b/taiga_halo2/Cargo.toml index d1c87f29..f1133e97 100644 --- a/taiga_halo2/Cargo.toml +++ b/taiga_halo2/Cargo.toml @@ -16,7 +16,7 @@ bitvec = "1" subtle = { version = "2.3", default-features = false } dyn-clone = "1.0" reddsa = "0.5" -vamp-ir = { git = "https://github.com/anoma/vamp-ir.git", rev = "778d5b53548cae5a2776c3bfd01fa9afa4543470"} +vamp-ir = { git = "https://github.com/anoma/vamp-ir.git", rev = "6d401f8a479951727586ef0c44c42edab3139090"} bincode = "2.0.0-rc.1" borsh = {version = "0.9", features = ["const-generics"]} byteorder = "1" From 384078c459d78becf18aeb5edfe71f975d6ce368 Mon Sep 17 00:00:00 2001 From: Paul Cadman Date: Tue, 27 Jun 2023 16:35:31 +0100 Subject: [PATCH 2/2] Construct VampIRValidityPredicateCircuit using a vamp-ir file Previously VampIRValidityPredicateCircuit was constucted from a Halo2 circuit file that was precompiled by vamp-ir. We can use the vamp-ir `compile` API to perform this step in directly in taiga instead. This change only affects the POC `test_create_vp_from_vamp_ir_file` test. --- .../src/circuit/vamp_ir_circuits/pyth.halo2 | Bin 1307 -> 0 bytes taiga_halo2/src/circuit/vp_circuit.rs | 61 +++++++----------- 2 files changed, 22 insertions(+), 39 deletions(-) delete mode 100644 taiga_halo2/src/circuit/vamp_ir_circuits/pyth.halo2 diff --git a/taiga_halo2/src/circuit/vamp_ir_circuits/pyth.halo2 b/taiga_halo2/src/circuit/vamp_ir_circuits/pyth.halo2 deleted file mode 100644 index 95b43b3082530afc9739b7010dbbb94665339ac5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1307 zcmZQ!U|?`%i@Q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+zByEtL!tTe>12PwC`6l zH~DVTv)$m=KbhCR^*yamE%_(QaHb;RTZ8=ZfE0%47OhQs-Khty9RnU-lUseRcAe^b{dJ`ZH}mac zu81d?6$U1BhcrnvALQ|#<^O5lI;HCOQ}(PjpL^ua-~EYaj$d7{dwS%WZ-SZrDi;no zeDd6NnX7r@is|fz4Ezj648{xw44e#n42+D7L7Xhi3jI7M8U^VDwGBSW9u$T*xKsOsAip6}W Ma*!i{vWyHY0D=u4T>t<8 diff --git a/taiga_halo2/src/circuit/vp_circuit.rs b/taiga_halo2/src/circuit/vp_circuit.rs index 0022a506..05a5df91 100644 --- a/taiga_halo2/src/circuit/vp_circuit.rs +++ b/taiga_halo2/src/circuit/vp_circuit.rs @@ -23,7 +23,6 @@ use crate::{ proof::Proof, vp_vk::ValidityPredicateVerifyingKey, }; -use bincode::error::DecodeError; use borsh::{BorshDeserialize, BorshSerialize}; use byteorder::{ReadBytesExt, WriteBytesExt}; use dyn_clone::{clone_trait_object, DynClone}; @@ -37,14 +36,17 @@ use halo2_proofs::{ }, poly::commitment::Params, }; -use pasta_curves::{pallas, vesta}; +use pasta_curves::{pallas, vesta, EqAffine, Fp}; use rand::rngs::OsRng; use std::collections::HashMap; -use std::fs::File; +use std::fs; use std::io; use std::path::PathBuf; -use vamp_ir::halo2::synth::{make_constant, Halo2Module}; -use vamp_ir::util::read_inputs_from_file; +use std::rc::Rc; +use vamp_ir::ast::Module; +use vamp_ir::halo2::synth::{make_constant, Halo2Module, PrimeFieldOps}; +use vamp_ir::transform::compile; +use vamp_ir::util::{read_inputs_from_file, Config}; #[derive(Debug, Clone)] pub struct VPVerifyingInfo { @@ -698,16 +700,18 @@ pub struct VampIRValidityPredicateCircuit { } impl VampIRValidityPredicateCircuit { - pub fn from_vamp_ir_circuit(vamp_ir_circuit_file: &PathBuf, inputs_file: &PathBuf) -> Self { - let mut circuit_file = - File::open(vamp_ir_circuit_file).expect("unable to load circuit file"); - // let mut circuit: Halo2Module = - // bincode::decode_from_std_read(&mut circuit_file, bincode::config::standard()) - // .expect("unable to load circuit file"); - let HaloCircuitData { - params, - mut circuit, - } = HaloCircuitData::read(&mut circuit_file).unwrap(); + pub fn from_vamp_ir_file(vamp_ir_file: &PathBuf, inputs_file: &PathBuf) -> Self { + let config = Config { quiet: true }; + let vamp_ir_source = fs::read_to_string(vamp_ir_file).expect("cannot read vamp-ir file"); + let parsed_vamp_ir_module = Module::parse(&vamp_ir_source).unwrap(); + let vamp_ir_module = compile( + parsed_vamp_ir_module, + &PrimeFieldOps::::default(), + &config, + ); + let mut circuit = Halo2Module::::new(Rc::new(vamp_ir_module)); + let params: Params = Params::new(circuit.k); + let var_assignments_ints = read_inputs_from_file(&circuit.module, inputs_file); let mut var_assignments = HashMap::new(); for (k, v) in var_assignments_ints { @@ -736,7 +740,6 @@ impl VampIRValidityPredicateCircuit { impl ValidityPredicateVerifyingInfo for VampIRValidityPredicateCircuit { fn get_verifying_info(&self) -> VPVerifyingInfo { let mut rng = OsRng; - // let params = SETUP_PARAMS_MAP.get(&VP_CIRCUIT_PARAMS_SIZE).unwrap(); let vk = keygen_vk(&self.params, &self.circuit).expect("keygen_vk should not fail"); let pk = keygen_pk(&self.params, vk.clone(), &self.circuit).expect("keygen_pk should not fail"); @@ -756,37 +759,17 @@ impl ValidityPredicateVerifyingInfo for VampIRValidityPredicateCircuit { } fn get_vp_vk(&self) -> ValidityPredicateVerifyingKey { - // let params = SETUP_PARAMS_MAP.get(&VP_CIRCUIT_PARAMS_SIZE).unwrap(); let vk = keygen_vk(&self.params, &self.circuit).expect("keygen_vk should not fail"); ValidityPredicateVerifyingKey::from_vk(vk) } } -// TODO: We won't need the HaloCircuitData when we can import the circuit from vamp_ir. -struct HaloCircuitData { - params: Params, - circuit: Halo2Module, -} - -impl HaloCircuitData { - fn read(mut reader: R) -> Result - where - R: std::io::Read, - { - let params = Params::::read(&mut reader) - .map_err(|x| DecodeError::OtherString(x.to_string()))?; - let circuit: Halo2Module = - bincode::decode_from_std_read(&mut reader, bincode::config::standard())?; - Ok(Self { params, circuit }) - } -} - #[test] -fn test_create_vp_from_vamp_ir_circuit() { - let vamp_ir_circuit_file = PathBuf::from("./src/circuit/vamp_ir_circuits/pyth.halo2"); +fn test_create_vp_from_vamp_ir_file() { + let vamp_ir_circuit_file = PathBuf::from("./src/circuit/vamp_ir_circuits/pyth.pir"); let inputs_file = PathBuf::from("./src/circuit/vamp_ir_circuits/pyth.inputs"); let vp_circuit = - VampIRValidityPredicateCircuit::from_vamp_ir_circuit(&vamp_ir_circuit_file, &inputs_file); + VampIRValidityPredicateCircuit::from_vamp_ir_file(&vamp_ir_circuit_file, &inputs_file); // generate proof and instance let vp_info = vp_circuit.get_verifying_info();