Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
chore!: update to ACVM 0.7.0 (#90)
Browse files Browse the repository at this point in the history
* chore!: update to ACVM 0.7.0

* chore(serializer): explicit that oracle lays no
constraints

---------

Co-authored-by: Joss <joss@aztecprotocol.com>
  • Loading branch information
TomAFrench and joss-aztec committed Mar 27, 2023
1 parent a2cf864 commit 6c03687
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 99 deletions.
17 changes: 9 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 0 additions & 36 deletions barretenberg_static_lib/src/acvm_interop/proof_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,6 @@ use common::serializer::serialize_circuit;
use std::collections::BTreeMap;

impl ProofSystemCompiler for Plonk {
fn prove_with_meta(
&self,
circuit: Circuit,
witness_values: BTreeMap<Witness, FieldElement>,
) -> Vec<u8> {
let constraint_system = serialize_circuit(&circuit);

let mut composer = StandardComposer::new(constraint_system);

let proving_key = composer.compute_proving_key();

let assignments = proof::flatten_witness_map(&circuit, witness_values);

composer.create_proof_with_pk(assignments, &proving_key)
}

fn verify_from_cs(
&self,
proof: &[u8],
public_inputs: Vec<FieldElement>,
circuit: Circuit,
) -> bool {
let constraint_system = serialize_circuit(&circuit);

let mut composer = StandardComposer::new(constraint_system);

let proving_key = composer.compute_proving_key();
let verification_key = composer.compute_verification_key(&proving_key);

composer.verify_with_vk(
proof,
Assignments::from_vec(public_inputs),
&verification_key,
)
}

fn np_language(&self) -> Language {
Language::PLONKCSat { width: 3 }
}
Expand Down
6 changes: 3 additions & 3 deletions barretenberg_static_lib/src/acvm_interop/pwg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use common::acvm::acir::{circuit::opcodes::BlackBoxFuncCall, native_types::Witness};
use common::acvm::FieldElement;
use common::acvm::PartialWitnessGenerator;
use common::acvm::{FieldElement, OpcodeResolution};
use common::acvm::{OpcodeResolutionError, PartialWitnessGenerator};
use std::collections::BTreeMap;

mod black_box_functions;
Expand All @@ -13,7 +13,7 @@ impl PartialWitnessGenerator for Plonk {
fn solve_black_box_function_call(
initial_witness: &mut BTreeMap<Witness, FieldElement>,
func_call: &BlackBoxFuncCall,
) -> Result<(), common::acvm::OpcodeResolutionError> {
) -> Result<OpcodeResolution, OpcodeResolutionError> {
BlackBoxFuncCaller::solve_black_box_func_call(initial_witness, func_call)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Barretenberg;

use common::acvm::acir::{circuit::opcodes::BlackBoxFuncCall, native_types::Witness};
use common::acvm::{FieldElement, OpcodeResolutionError};
use common::acvm::{FieldElement, OpcodeResolution, OpcodeResolutionError};
use common::black_box_functions::BarretenbergShared;
use std::collections::BTreeMap;

Expand Down Expand Up @@ -37,7 +37,7 @@ impl BlackBoxFuncCaller {
pub(super) fn solve_black_box_func_call(
initial_witness: &mut BTreeMap<Witness, FieldElement>,
gadget_call: &BlackBoxFuncCall,
) -> Result<(), OpcodeResolutionError> {
) -> Result<OpcodeResolution, OpcodeResolutionError> {
common::black_box_functions::solve_black_box_func_call::<Barretenberg>(
initial_witness,
gadget_call,
Expand Down
36 changes: 0 additions & 36 deletions barretenberg_wasm/src/acvm_interop/proof_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,6 @@ use common::serializer::serialize_circuit;
use std::collections::BTreeMap;

impl ProofSystemCompiler for Plonk {
fn prove_with_meta(
&self,
circuit: Circuit,
witness_values: BTreeMap<Witness, FieldElement>,
) -> Vec<u8> {
let constraint_system = serialize_circuit(&circuit);

let mut composer = StandardComposer::new(constraint_system);

let proving_key = composer.compute_proving_key();

let assignments = proof::flatten_witness_map(&circuit, witness_values);

composer.create_proof_with_pk(assignments, &proving_key)
}

fn verify_from_cs(
&self,
proof: &[u8],
public_inputs: Vec<FieldElement>,
circuit: Circuit,
) -> bool {
let constraint_system = serialize_circuit(&circuit);

let mut composer = StandardComposer::new(constraint_system);

let proving_key = composer.compute_proving_key();
let verification_key = composer.compute_verification_key(&proving_key);

composer.verify_with_vk(
proof,
Assignments::from_vec(public_inputs),
&verification_key,
)
}

fn np_language(&self) -> Language {
Language::PLONKCSat { width: 3 }
}
Expand Down
6 changes: 3 additions & 3 deletions barretenberg_wasm/src/acvm_interop/pwg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use common::acvm::acir::{circuit::opcodes::BlackBoxFuncCall, native_types::Witness};
use common::acvm::FieldElement;
use common::acvm::PartialWitnessGenerator;
use common::acvm::{FieldElement, OpcodeResolution};
use common::acvm::{OpcodeResolutionError, PartialWitnessGenerator};
use std::collections::BTreeMap;

mod black_box_functions;
Expand All @@ -13,7 +13,7 @@ impl PartialWitnessGenerator for Plonk {
fn solve_black_box_function_call(
initial_witness: &mut BTreeMap<Witness, FieldElement>,
func_call: &BlackBoxFuncCall,
) -> Result<(), common::acvm::OpcodeResolutionError> {
) -> Result<OpcodeResolution, OpcodeResolutionError> {
BlackBoxFuncCaller::solve_black_box_func_call(initial_witness, func_call)
}
}
4 changes: 2 additions & 2 deletions barretenberg_wasm/src/acvm_interop/pwg/black_box_functions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Barretenberg;

use common::acvm::acir::{circuit::opcodes::BlackBoxFuncCall, native_types::Witness};
use common::acvm::{FieldElement, OpcodeResolutionError};
use common::acvm::{FieldElement, OpcodeResolution, OpcodeResolutionError};
use common::black_box_functions::BarretenbergShared;
use std::collections::BTreeMap;

Expand Down Expand Up @@ -37,7 +37,7 @@ impl BlackBoxFuncCaller {
pub(super) fn solve_black_box_func_call(
initial_witness: &mut BTreeMap<Witness, FieldElement>,
gadget_call: &BlackBoxFuncCall,
) -> Result<(), OpcodeResolutionError> {
) -> Result<OpcodeResolution, OpcodeResolutionError> {
common::black_box_functions::solve_black_box_func_call::<Barretenberg>(
initial_witness,
gadget_call,
Expand Down
2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
acvm = { version = "0.6.0", features = ["bn254"] }
acvm = { version = "0.7.0", features = ["bn254"] }

sled = "0.34.6"
blake2 = "0.9.1"
Expand Down
7 changes: 4 additions & 3 deletions common/src/black_box_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::BTreeMap;
use acvm::{
acir::{circuit::opcodes::BlackBoxFuncCall, native_types::Witness, BlackBoxFunc},
pwg::{self, witness_to_value},
FieldElement, OpcodeResolutionError,
FieldElement, OpcodeResolution, OpcodeResolutionError,
};
use blake2::{Blake2s, Digest};

Expand All @@ -27,7 +27,7 @@ pub trait BarretenbergShared: PathHasher {
pub fn solve_black_box_func_call<B: BarretenbergShared>(
initial_witness: &mut BTreeMap<Witness, FieldElement>,
gadget_call: &BlackBoxFuncCall,
) -> Result<(), OpcodeResolutionError> {
) -> Result<OpcodeResolution, OpcodeResolutionError> {
match gadget_call.name {
BlackBoxFunc::SHA256 => pwg::hash::sha256(initial_witness, gadget_call),
BlackBoxFunc::Blake2s => pwg::hash::blake2s(initial_witness, gadget_call),
Expand Down Expand Up @@ -157,5 +157,6 @@ pub fn solve_black_box_func_call<B: BarretenbergShared>(
}
BlackBoxFunc::RANGE => acvm::pwg::range::solve_range_opcode(initial_witness, gadget_call)?,
}
Ok(())

Ok(OpcodeResolution::Solved)
}
10 changes: 5 additions & 5 deletions common/src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,19 @@ pub fn serialize_circuit(circuit: &Circuit) -> ConstraintSystem {
BlackBoxFunc::AES => panic!("AES has not yet been implemented"),
};
}
Opcode::Directive(_) => {
// Directives are only needed by the pwg
Opcode::Directive(_) | Opcode::Oracle(_) => {
// Directives & Oracles are only needed by the pwg
}
Opcode::Block(_, _) => {
// TODO: implement serialization of blocks to match BB's interface
Opcode::Block(_) | Opcode::RAM(_) | Opcode::ROM(_) => {
// TODO: implement serialization to match BB's interface
}
}
}

// Create constraint system
ConstraintSystem {
var_num: circuit.current_witness_index + 1, // number of witnesses is the witness index + 1;
public_inputs: circuit.public_inputs.indices(),
public_inputs: circuit.public_inputs().indices(),
logic_constraints,
range_constraints,
sha256_constraints,
Expand Down

0 comments on commit 6c03687

Please sign in to comment.