Skip to content

Commit

Permalink
roll back changes in circuit compression
Browse files Browse the repository at this point in the history
  • Loading branch information
moCello committed Dec 21, 2023
1 parent 51365eb commit 54d5731
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,18 @@ impl Compiler {

/// Generates a [Prover] and [Verifier] from a buffer created by
/// [Self::compress].
pub fn decompress_and_compile(
pub fn decompress(
pp: &PublicParameters,
label: &[u8],
compressed: &[u8],
) -> Result<(Prover, Verifier), Error> {
let composer = CompressedCircuit::from_bytes(compressed)?;

Self::compile_with_composer(pp, label, &composer)
CompressedCircuit::from_bytes(pp, label, compressed)
}

/// Create a new arguments set from a given circuit instance
///
/// Use the default implementation of the circuit
fn compile_with_composer(
pub(crate) fn compile_with_composer(
pp: &PublicParameters,
label: &[u8],
composer: &Composer,
Expand Down
9 changes: 7 additions & 2 deletions src/composer/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use alloc::vec::Vec;
use super::{
BlsScalar, Circuit, Composer, Constraint, Error, Gate, Selector, Witness,
};
use crate::prelude::{Compiler, Prover, PublicParameters, Verifier};

mod hades;

Expand Down Expand Up @@ -209,7 +210,11 @@ impl CompressedCircuit {
miniz_oxide::deflate::compress_to_vec(&buf, 10)
}

pub fn from_bytes(compressed: &[u8]) -> Result<Composer, Error> {
pub fn from_bytes(
pp: &PublicParameters,
label: &[u8],
compressed: &[u8],
) -> Result<(Prover, Verifier), Error> {
let compressed = miniz_oxide::inflate::decompress_to_vec(compressed)
.map_err(|_| Error::InvalidCompressedCircuit)?;
let (
Expand Down Expand Up @@ -353,6 +358,6 @@ impl CompressedCircuit {
composer.append_custom_gate(constraint);
}

Ok(composer)
Compiler::compile_with_composer(pp, label, &composer)
}
}
2 changes: 1 addition & 1 deletion tests/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn circuit_with_all_gates() {
.expect("failed to compress circuit");

let (decompressed_prover, decompressed_verifier) =
Compiler::decompress_and_compile(&pp, label, &compressed).unwrap();
Compiler::decompress(&pp, label, &compressed).unwrap();

let decoded_prover_bytes = decompressed_prover.to_bytes();
let len = prover.serialized_size();
Expand Down

0 comments on commit 54d5731

Please sign in to comment.