-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: import core logic in cli from
nargo
crate (#1142)
- Loading branch information
1 parent
24adcc0
commit 753a272
Showing
20 changed files
with
167 additions
and
71 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
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
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::{checksum_acir, preprocess_circuit, PreprocessedData}; | ||
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,31 @@ | ||
use acvm::acir::circuit::Circuit; | ||
use acvm::{checksum_constraint_system, ProofSystemCompiler}; | ||
|
||
use crate::NargoError; | ||
|
||
pub fn checksum_acir(circuit: &Circuit) -> [u8; 4] { | ||
checksum_constraint_system(circuit).to_be_bytes() | ||
} | ||
|
||
/// The result of preprocessing the ACIR bytecode. | ||
/// The proving, verification key and circuit are backend specific. | ||
/// | ||
/// The circuit is backend specific because at the end of compilation | ||
/// an optimization pass is applied which will transform the bytecode into | ||
/// a format that the backend will accept; removing unsupported gates | ||
/// is one example of this. | ||
pub struct PreprocessedData { | ||
pub proving_key: Vec<u8>, | ||
pub verification_key: Vec<u8>, | ||
pub program_checksum: [u8; 4], | ||
} | ||
|
||
pub fn preprocess_circuit( | ||
backend: &impl ProofSystemCompiler, | ||
circuit: &Circuit, | ||
) -> Result<PreprocessedData, NargoError> { | ||
let (proving_key, verification_key) = backend.preprocess(circuit); | ||
let program_checksum = checksum_acir(circuit); | ||
|
||
Ok(PreprocessedData { proving_key, verification_key, program_checksum }) | ||
} |
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
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
Oops, something went wrong.