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

Commit

Permalink
feat(acvm)!: Introduce Error type for fallible Backend traits (#248)
Browse files Browse the repository at this point in the history
* feat(acvm)!: Introduce Fallible trait for Backends & make functions fallible

* require error type on each trait
  • Loading branch information
phated authored Apr 28, 2023
1 parent 1d9adef commit 45c45f7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions acvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub enum OpcodeResolutionError {
pub enum OpcodeResolution {
/// The opcode is resolved
Solved,
/// The opcode is not solvable
/// The opcode is not solvable
Stalled(OpcodeNotSolvable),
/// The opcode is not solvable but could resolved some witness
InProgress,
Expand Down Expand Up @@ -195,13 +195,19 @@ pub trait PartialWitnessGenerator {
}

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

// 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]) -> String;
fn eth_contract_from_vk(&self, verification_key: &[u8]) -> Result<String, Self::Error>;
}

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

/// The NPC language that this proof system directly accepts.
/// It is possible for ACVM to transpile to different languages, however it is advised to create a new backend
/// as this in most cases will be inefficient. For this reason, we want to throw a hard error
Expand All @@ -212,11 +218,11 @@ pub trait ProofSystemCompiler {
fn black_box_function_supported(&self, opcode: &BlackBoxFunc) -> bool;

/// Returns the number of gates in a circuit
fn get_exact_circuit_size(&self, circuit: &Circuit) -> u32;
fn get_exact_circuit_size(&self, circuit: &Circuit) -> Result<u32, Self::Error>;

/// 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) -> (Vec<u8>, Vec<u8>);
fn preprocess(&self, 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
Expand All @@ -226,7 +232,7 @@ pub trait ProofSystemCompiler {
circuit: &Circuit,
witness_values: BTreeMap<Witness, FieldElement>,
proving_key: &[u8],
) -> Vec<u8>;
) -> Result<Vec<u8>, Self::Error>;

/// Verifies a Proof, given the circuit description, the circuit's public inputs, and the verification key
fn verify_with_vk(
Expand All @@ -235,7 +241,7 @@ pub trait ProofSystemCompiler {
public_inputs: BTreeMap<Witness, FieldElement>,
circuit: &Circuit,
verification_key: &[u8],
) -> bool;
) -> Result<bool, Self::Error>;
}

/// Supported NP complete languages
Expand Down

0 comments on commit 45c45f7

Please sign in to comment.