Skip to content

Commit

Permalink
drop pack and unpack commands, made obsolete by #942 (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino authored Dec 12, 2023
1 parent ede4098 commit 0721f20
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 242 deletions.
163 changes: 0 additions & 163 deletions src/cli/lurk_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -47,30 +46,6 @@ impl<F: LurkField> HasFieldModulus for LurkProofMeta<F> {
}
}

impl<F: LurkField> LurkProofMeta<F> {
fn without_envs(self) -> Result<Self> {
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<F: LurkField + Serialize> LurkProofMeta<F> {
#[inline]
pub(crate) fn persist(self, proof_key: &str) -> Result<()> {
Expand Down Expand Up @@ -185,59 +160,6 @@ where
}
}

impl<
'a,
F: CurveCycleEquipped,
C: Coprocessor<F> + Serialize + DeserializeOwned,
M: MultiFrameTrait<'a, F, C>,
> LurkProof<'a, F, C, M>
where
<<E1<F> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation,
<<E2<F> 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<F>) -> 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,
Expand Down Expand Up @@ -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<F> + Serialize + DeserializeOwned,
M: MultiFrameTrait<'a, F, C>,
> where
<<E1<F> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation,
<<E2<F> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation,
{
proof: LurkProof<'a, F, C, M>,
meta: Option<LurkProofMeta<F>>,
key: String,
}

impl<
'a,
F: CurveCycleEquipped,
C: Coprocessor<F> + 'a + Serialize + DeserializeOwned,
M: MultiFrameTrait<'a, F, C>,
> HasFieldModulus for PackedLurkProof<'a, F, C, M>
where
<<E1<F> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation,
<<E2<F> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation,
{
fn field_modulus() -> String {
F::MODULUS.to_owned()
}
}

impl<
F: CurveCycleEquipped + Serialize + DeserializeOwned,
C: Coprocessor<F> + 'static + Serialize + DeserializeOwned,
M: MultiFrameTrait<'static, F, C>
+ SuperStepCircuit<F>
+ NonUniformCircuit<E1<F>, E2<F>, M, C2<F>>
+ 'static,
> PackedLurkProof<'static, F, C, M>
where
<<E1<F> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation,
<<E2<F> 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<F> = 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::<Self>(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(())
}
}
79 changes: 1 addition & 78 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)]
Expand Down Expand Up @@ -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<Utf8PathBuf>,

/// Config file, containing the lowest precedence parameters
#[clap(long, value_parser)]
config: Option<Utf8PathBuf>,
}

#[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<Utf8PathBuf>,

/// Path to proofs directory
#[clap(long, value_parser)]
proofs_dir: Option<Utf8PathBuf>,

/// Config file, containing the lowest precedence parameters
#[clap(long, value_parser)]
config: Option<Utf8PathBuf>,
}

impl Cli {
fn run(self) -> Result<()> {
match self.command {
Expand Down Expand Up @@ -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<pallas::Scalar>>>::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<pallas::Scalar>>>::unpack(
&unpack_args.proof_path,
)
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/cli/zstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ impl<F: LurkField> ZDag<F> {
}

/// Populates a `ZDag` with data from self
fn populate_z_dag(
#[allow(dead_code)]
pub(crate) fn populate_z_dag(
&self,
z_ptr: &ZPtr<F>,
z_dag: &mut ZDag<F>,
Expand Down Expand Up @@ -195,6 +196,9 @@ impl<F: LurkField> ZDag<F> {
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<F>]) -> Result<Self> {
let mut z_dag_new = ZDag::default();
let mut cache = HashSet::default();
Expand Down

1 comment on commit 0721f20

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarks

Table of Contents

Overview

This benchmark report shows the Fibonacci GPU benchmark.
NVIDIA L4
Intel(R) Xeon(R) CPU @ 2.20GHz
125.78 GB RAM
Workflow run: https://github.com/lurk-lab/lurk-rs/actions/runs/7188570223

Benchmark Results

LEM Fibonacci Prove - rc = 100

fib-ref=ede4098c1392fc79ace065bc436728d64727cabf fib-ref=0721f20007e9faaecdded8dee460a7cbe0d7d280
num-100 3.88 s (✅ 1.00x) 3.88 s (✅ 1.00x faster)
num-200 7.73 s (✅ 1.00x) 7.74 s (✅ 1.00x slower)

LEM Fibonacci Prove - rc = 600

fib-ref=ede4098c1392fc79ace065bc436728d64727cabf fib-ref=0721f20007e9faaecdded8dee460a7cbe0d7d280
num-100 3.32 s (✅ 1.00x) 3.34 s (✅ 1.01x slower)
num-200 7.28 s (✅ 1.00x) 7.32 s (✅ 1.01x slower)

Made with criterion-table

Please sign in to comment.