-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into program-artifact
* master: feat: import core logic in cli from `nargo` crate (#1142) chore: enforce `clippy::semicolon_if_nothing_returned` linting rule (#1139) chore: borrow instead of cloning witness vectors in IR gen (#1127)
- Loading branch information
Showing
56 changed files
with
324 additions
and
153 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#![forbid(unsafe_code)] | ||
#![warn(unused_crate_dependencies, unused_extern_crates)] | ||
#![warn(unreachable_pub)] | ||
#![warn(clippy::semicolon_if_nothing_returned)] | ||
|
||
// For now we use a wrapper around generational-arena | ||
pub use generational_arena::{Arena, Index}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use acvm::OpcodeResolutionError; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum NargoError { | ||
/// Error while compiling Noir into ACIR. | ||
#[error("Failed to compile circuit")] | ||
CompilationError, | ||
|
||
/// ACIR circuit solving error | ||
#[error(transparent)] | ||
SolvingError(#[from] OpcodeResolutionError), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
#![forbid(unsafe_code)] | ||
#![warn(unused_crate_dependencies, unused_extern_crates)] | ||
#![warn(unreachable_pub)] | ||
#![warn(clippy::semicolon_if_nothing_returned)] | ||
|
||
//! Nargo is the package manager for Noir | ||
//! This name was used because it sounds like `cargo` and | ||
//! Noir Package Manager abbreviated is npm, which is already taken. | ||
|
||
pub mod artifacts; | ||
mod errors; | ||
pub mod manifest; | ||
pub mod ops; | ||
|
||
pub use self::errors::NargoError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use acvm::SmartContract; | ||
|
||
use crate::NargoError; | ||
|
||
pub fn codegen_verifier( | ||
backend: &impl SmartContract, | ||
verification_key: &[u8], | ||
) -> Result<String, NargoError> { | ||
Ok(backend.eth_contract_from_vk(verification_key)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use acvm::PartialWitnessGenerator; | ||
use acvm::{acir::circuit::Circuit, pwg::block::Blocks}; | ||
use noirc_abi::WitnessMap; | ||
|
||
use crate::NargoError; | ||
|
||
pub fn execute_circuit( | ||
backend: &impl PartialWitnessGenerator, | ||
circuit: Circuit, | ||
mut initial_witness: WitnessMap, | ||
) -> Result<WitnessMap, NargoError> { | ||
let mut blocks = Blocks::default(); | ||
let (unresolved_opcodes, oracles) = | ||
backend.solve(&mut initial_witness, &mut blocks, circuit.opcodes)?; | ||
if !unresolved_opcodes.is_empty() || !oracles.is_empty() { | ||
todo!("Add oracle support to nargo execute") | ||
} | ||
|
||
Ok(initial_witness) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pub use self::codegen_verifier::codegen_verifier; | ||
pub use self::execute::execute_circuit; | ||
pub use self::preprocess::{preprocess_contract, preprocess_program}; | ||
pub use self::prove::prove; | ||
pub use self::verify::verify_proof; | ||
|
||
mod codegen_verifier; | ||
mod execute; | ||
mod preprocess; | ||
mod prove; | ||
mod verify; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use acvm::ProofSystemCompiler; | ||
use iter_extended::vecmap; | ||
use noirc_driver::{CompiledContract, CompiledProgram}; | ||
|
||
use crate::artifacts::{ | ||
contract::{PreprocessedContract, PreprocessedContractFunction}, | ||
program::PreprocessedProgram, | ||
}; | ||
|
||
// TODO: pull this from backend. | ||
const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg"; | ||
|
||
pub fn preprocess_program( | ||
backend: &impl ProofSystemCompiler, | ||
compiled_program: CompiledProgram, | ||
) -> PreprocessedProgram { | ||
// TODO: currently `compiled_program`'s bytecode is already optimized for the backend. | ||
// In future we'll need to apply those optimizations here. | ||
let optimized_bytecode = compiled_program.circuit; | ||
let (proving_key, verification_key) = backend.preprocess(&optimized_bytecode); | ||
|
||
PreprocessedProgram { | ||
backend: String::from(BACKEND_IDENTIFIER), | ||
abi: compiled_program.abi, | ||
bytecode: optimized_bytecode, | ||
proving_key, | ||
verification_key, | ||
} | ||
} | ||
|
||
pub fn preprocess_contract( | ||
backend: &impl ProofSystemCompiler, | ||
compiled_contract: CompiledContract, | ||
) -> PreprocessedContract { | ||
let preprocessed_contract_functions = vecmap(compiled_contract.functions, |func| { | ||
// TODO: currently `func`'s bytecode is already optimized for the backend. | ||
// In future we'll need to apply those optimizations here. | ||
let optimized_bytecode = func.bytecode; | ||
let (proving_key, verification_key) = backend.preprocess(&optimized_bytecode); | ||
|
||
PreprocessedContractFunction { | ||
name: func.name, | ||
function_type: func.function_type, | ||
abi: func.abi, | ||
|
||
bytecode: optimized_bytecode, | ||
proving_key, | ||
verification_key, | ||
} | ||
}); | ||
|
||
PreprocessedContract { | ||
name: compiled_contract.name, | ||
backend: String::from(BACKEND_IDENTIFIER), | ||
functions: preprocessed_contract_functions, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use acvm::acir::circuit::Circuit; | ||
use acvm::ProofSystemCompiler; | ||
use noirc_abi::WitnessMap; | ||
|
||
use crate::NargoError; | ||
|
||
pub fn prove( | ||
backend: &impl ProofSystemCompiler, | ||
circuit: &Circuit, | ||
solved_witness: WitnessMap, | ||
proving_key: &[u8], | ||
) -> Result<Vec<u8>, NargoError> { | ||
let proof = backend.prove_with_pk(circuit, solved_witness, proving_key); | ||
|
||
Ok(proof) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use acvm::acir::circuit::Circuit; | ||
use acvm::ProofSystemCompiler; | ||
use noirc_abi::WitnessMap; | ||
|
||
use crate::NargoError; | ||
|
||
pub fn verify_proof( | ||
backend: &impl ProofSystemCompiler, | ||
circuit: &Circuit, | ||
proof: &[u8], | ||
public_inputs: WitnessMap, | ||
verification_key: &[u8], | ||
) -> Result<bool, NargoError> { | ||
let valid_proof = backend.verify_with_vk(proof, public_inputs, circuit, verification_key); | ||
|
||
Ok(valid_proof) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.