From 0721f20007e9faaecdded8dee460a7cbe0d7d280 Mon Sep 17 00:00:00 2001 From: Arthur Paulino Date: Tue, 12 Dec 2023 20:32:56 -0300 Subject: [PATCH] drop pack and unpack commands, made obsolete by #942 (#952) --- src/cli/lurk_proof.rs | 163 ------------------------------------------ src/cli/mod.rs | 79 +------------------- src/cli/zstore.rs | 6 +- 3 files changed, 6 insertions(+), 242 deletions(-) diff --git a/src/cli/lurk_proof.rs b/src/cli/lurk_proof.rs index bd6fb5c4cf..4690b7b134 100644 --- a/src/cli/lurk_proof.rs +++ b/src/cli/lurk_proof.rs @@ -4,7 +4,6 @@ use ::nova::{ }; use abomonation::Abomonation; use anyhow::{bail, Result}; -use camino::Utf8PathBuf; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::{collections::HashMap, sync::Arc}; @@ -47,30 +46,6 @@ impl HasFieldModulus for LurkProofMeta { } } -impl LurkProofMeta { - fn without_envs(self) -> Result { - if self.env_io.is_none() { - return Ok(self); - } - let Self { - iterations, - expr_io: (expr, expr_out), - env_io: _, - cont_io: (cont, cont_out), - z_dag, - } = self; - // creating a new `ZDag` without data from envs - let z_dag = z_dag.filtered(&[&expr, &expr_out, &cont, &cont_out])?; - Ok(Self { - iterations, - expr_io: (expr, expr_out), - env_io: None, - cont_io: (cont, cont_out), - z_dag, - }) - } -} - impl LurkProofMeta { #[inline] pub(crate) fn persist(self, proof_key: &str) -> Result<()> { @@ -185,59 +160,6 @@ where } } -impl< - 'a, - F: CurveCycleEquipped, - C: Coprocessor + Serialize + DeserializeOwned, - M: MultiFrameTrait<'a, F, C>, - > LurkProof<'a, F, C, M> -where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, -{ - #[inline] - fn public_io(&self) -> (&[F], &[F]) { - match self { - Self::Nova { - proof: _, - public_inputs, - public_outputs, - .. - } => (public_inputs, public_outputs), - } - } - - fn matches_meta(&self, meta: &LurkProofMeta) -> bool { - let (public_input, public_output) = self.public_io(); - let matches_exprs = { - let (expr, expr_out) = &meta.expr_io; - public_input[0] == expr.tag_field() - && &public_input[1] == expr.value() - && public_output[0] == expr_out.tag_field() - && &public_output[1] == expr_out.value() - }; - let matches_envs = { - if let Some((env, env_out)) = &meta.env_io { - public_input[2] == env.tag_field() - && &public_input[3] == env.value() - && public_output[2] == env_out.tag_field() - && &public_output[3] == env_out.value() - } else { - // no data to trigger inconsistency - true - } - }; - let matches_conts = { - let (cont, cont_out) = &meta.cont_io; - public_input[4] == cont.tag_field() - && &public_input[5] == cont.value() - && public_output[4] == cont_out.tag_field() - && &public_output[5] == cont_out.value() - }; - matches_exprs && matches_envs && matches_conts - } -} - impl< 'a, F: CurveCycleEquipped + Serialize, @@ -300,88 +222,3 @@ where } } } - -#[derive(Serialize, Deserialize)] -#[serde(bound(serialize = "F: Serialize", deserialize = "F: DeserializeOwned"))] -pub(crate) struct PackedLurkProof< - 'a, - F: CurveCycleEquipped, - C: Coprocessor + Serialize + DeserializeOwned, - M: MultiFrameTrait<'a, F, C>, -> where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, -{ - proof: LurkProof<'a, F, C, M>, - meta: Option>, - key: String, -} - -impl< - 'a, - F: CurveCycleEquipped, - C: Coprocessor + 'a + Serialize + DeserializeOwned, - M: MultiFrameTrait<'a, F, C>, - > HasFieldModulus for PackedLurkProof<'a, F, C, M> -where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, -{ - fn field_modulus() -> String { - F::MODULUS.to_owned() - } -} - -impl< - F: CurveCycleEquipped + Serialize + DeserializeOwned, - C: Coprocessor + 'static + Serialize + DeserializeOwned, - M: MultiFrameTrait<'static, F, C> - + SuperStepCircuit - + NonUniformCircuit, E2, M, C2> - + 'static, - > PackedLurkProof<'static, F, C, M> -where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, -{ - pub(crate) fn pack( - proof_key: String, - path: &Utf8PathBuf, - exclude_meta: bool, - include_envs: bool, - ) -> Result<()> { - let proof: LurkProof<'_, F, C, M> = load(&proof_path(&proof_key))?; - let meta = if exclude_meta { - None - } else { - let meta: LurkProofMeta = load(&proof_meta_path(&proof_key))?; - if include_envs { - Some(meta) - } else { - Some(meta.without_envs()?) - } - }; - let packed_proof = PackedLurkProof { - proof, - meta, - key: proof_key, - }; - dump(packed_proof, path) - } - - pub(crate) fn unpack(path: &Utf8PathBuf) -> Result<()> { - let PackedLurkProof { proof, meta, key } = load::(path)?; - if !proof.verify()? { - bail!("Proof verification failed") - } - if let Some(meta) = meta { - if !proof.matches_meta(&meta) { - bail!("Meta data is incompatible with the proof") - } - meta.persist(&key)?; - } - proof.persist(&key)?; - println!("Proof {key} unpacked"); - Ok(()) - } -} diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 946f0fc020..bec951a1dc 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -36,7 +36,7 @@ use crate::cli::{ zstore::ZStore, }; -use self::{field_data::load, lurk_proof::PackedLurkProof}; +use self::field_data::load; #[derive(Parser, Debug)] #[clap(version)] @@ -61,10 +61,6 @@ enum Command { #[command(verbatim_doc_comment)] Circom(CircomArgs), PublicParams(PublicParamArgs), - /// Packs a proof on a file to be shared - Pack(PackArgs), - /// Unpacks a proof into Lurk's internal data storage - Unpack(UnpackArgs), } #[derive(Args, Debug)] @@ -581,52 +577,6 @@ impl PublicParamArgs { } } -#[derive(Args, Debug)] -struct PackArgs { - /// Key of the proof to be packed - #[clap(value_parser)] - proof_key: String, - - /// Path to the packed proof output - #[clap(long, short = 'o', value_parser)] - output: Utf8PathBuf, - - /// Flag to exclude meta data - #[arg(long)] - exclude_meta: bool, - - /// Flag to include envs in the meta data. Irrelevant if exclude_meta is true - #[arg(long)] - include_envs: bool, - - /// Path to proofs directory - #[clap(long, value_parser)] - proofs_dir: Option, - - /// Config file, containing the lowest precedence parameters - #[clap(long, value_parser)] - config: Option, -} - -#[derive(Args, Debug)] -struct UnpackArgs { - /// Packed proof path - #[clap(value_parser)] - proof_path: Utf8PathBuf, - - /// Path to public parameters directory - #[clap(long, value_parser)] - public_params_dir: Option, - - /// Path to proofs directory - #[clap(long, value_parser)] - proofs_dir: Option, - - /// Config file, containing the lowest precedence parameters - #[clap(long, value_parser)] - config: Option, -} - impl Cli { fn run(self) -> Result<()> { match self.command { @@ -687,33 +637,6 @@ impl Cli { create_lurk_dirs()?; public_params_args.run() } - Command::Pack(pack_args) => { - let mut cli_settings = HashMap::new(); - if let Some(dir) = pack_args.proofs_dir { - cli_settings.insert("proofs_dir", dir.to_string()); - } - cli_config(pack_args.config.as_ref(), Some(&cli_settings)); - PackedLurkProof::<_, _, MultiFrame<'_, _, Coproc>>::pack( - pack_args.proof_key, - &pack_args.output, - pack_args.exclude_meta, - pack_args.include_envs, - ) - } - Command::Unpack(unpack_args) => { - let mut cli_settings = HashMap::new(); - if let Some(dir) = unpack_args.public_params_dir { - cli_settings.insert("public_params_dir", dir.to_string()); - } - if let Some(dir) = unpack_args.proofs_dir { - cli_settings.insert("proofs_dir", dir.to_string()); - } - cli_config(unpack_args.config.as_ref(), Some(&cli_settings)); - create_lurk_dirs()?; - PackedLurkProof::<_, _, MultiFrame<'_, _, Coproc>>::unpack( - &unpack_args.proof_path, - ) - } } } } diff --git a/src/cli/zstore.rs b/src/cli/zstore.rs index c098105bf8..c295a837d7 100644 --- a/src/cli/zstore.rs +++ b/src/cli/zstore.rs @@ -156,7 +156,8 @@ impl ZDag { } /// Populates a `ZDag` with data from self - fn populate_z_dag( + #[allow(dead_code)] + pub(crate) fn populate_z_dag( &self, z_ptr: &ZPtr, z_dag: &mut ZDag, @@ -195,6 +196,9 @@ impl ZDag { recurse(z_ptr) } + /// Returns a `ZDag` containing only enough data to represent the `z_ptrs`, + /// which must be recoverable from `self` + #[allow(dead_code)] pub(crate) fn filtered(&self, z_ptrs: &[&ZPtr]) -> Result { let mut z_dag_new = ZDag::default(); let mut cache = HashSet::default();