Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
feat(acvm)!: Add ReferenceString backend trait
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed May 2, 2023
1 parent 45c45f7 commit 4dead53
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions acvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ k256 = { version = "0.7.2", features = [
] }
indexmap = "1.7.0"
thiserror = "1.0.21"
async-trait = "0.1"

[features]
default = ["bn254"]
Expand Down
38 changes: 35 additions & 3 deletions acvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use pwg::{block::Blocks, directives::solve_directives};
use std::collections::BTreeMap;
use thiserror::Error;

// We re-export async-trait so consumers can attach it to their impl
pub use async_trait::async_trait;

// re-export acir
pub use acir;
pub use acir::FieldElement;
Expand Down Expand Up @@ -92,7 +95,26 @@ fn first_missing_assignment(
})
}

pub trait Backend: SmartContract + ProofSystemCompiler + PartialWitnessGenerator + Default {}
pub trait Backend:
SmartContract + ProofSystemCompiler + PartialWitnessGenerator + ReferenceString + Default
{
}

#[async_trait]
pub trait ReferenceString {
/// The Error type returned by failed function calls in the ReferenceString trait.
type Error: std::error::Error; // fully-qualified named because thiserror is `use`d at the top of the crate

/// Provides the reference string that is needed by other traits
async fn get_reference_string(&self, circuit: &Circuit) -> Result<Vec<u8>, Self::Error>;

/// Validates a (likely cached) reference string against a circuit
fn is_reference_string_valid(
&self,
reference_string: &[u8],
circuit: &Circuit,
) -> Result<bool, Self::Error>;
}

/// This component will generate the backend specific output for
/// each OPCODE.
Expand Down Expand Up @@ -201,7 +223,11 @@ pub trait SmartContract {
// TODO: Allow a backend to support multiple smart contract platforms

/// Returns an Ethereum smart contract to verify proofs against a given verification key.
fn eth_contract_from_vk(&self, verification_key: &[u8]) -> Result<String, Self::Error>;
fn eth_contract_from_vk(
&self,
reference_string: &[u8],
verification_key: &[u8],
) -> Result<String, Self::Error>;
}

pub trait ProofSystemCompiler {
Expand All @@ -222,13 +248,18 @@ pub trait ProofSystemCompiler {

/// Generates a proving and verification key given the circuit description
/// These keys can then be used to construct a proof and for its verification
fn preprocess(&self, circuit: &Circuit) -> Result<(Vec<u8>, Vec<u8>), Self::Error>;
fn preprocess(
&self,
reference_string: &[u8],
circuit: &Circuit,
) -> Result<(Vec<u8>, Vec<u8>), Self::Error>;

/// Creates a Proof given the circuit description, the initial witness values, and the proving key
/// It is important to note that the intermediate witnesses for black box functions will not generated
/// This is the responsibility of the proof system.
fn prove_with_pk(
&self,
reference_string: &[u8],
circuit: &Circuit,
witness_values: BTreeMap<Witness, FieldElement>,
proving_key: &[u8],
Expand All @@ -237,6 +268,7 @@ pub trait ProofSystemCompiler {
/// Verifies a Proof, given the circuit description, the circuit's public inputs, and the verification key
fn verify_with_vk(
&self,
reference_string: &[u8],
proof: &[u8],
public_inputs: BTreeMap<Witness, FieldElement>,
circuit: &Circuit,
Expand Down

0 comments on commit 4dead53

Please sign in to comment.