Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pse evm tests #48

Merged
merged 25 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,8 @@ jobs:
- name: Install latest nextest release
uses: taiki-e/install-action@nextest

- name: Install solc
run: (hash svm 2>/dev/null || cargo install --version 0.2.23 svm-rs) && svm install 0.8.19 && solc --version

- name: run pse test
run: cargo nextest run --package noir_halo2_backend_pse --test-threads=1
100 changes: 82 additions & 18 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"

[workspace.dependencies]
acvm = "0.15.0"
acvm = "0.18.1"
rand = "0.8"
reqwest = { version = "0.11.16", default-features = false, features = [
"stream",
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This is a [halo2](https://zcash.github.io/halo2/) backend for the [Noir Programming Language](https://noir-lang.org/)

Get [detailed documentation on this repository!](https://mach-34.github.io/halo2_backend_docs)

**WARNING: This crate is experimental and under development. Expect bugs and unoptimized circuits.**

## Acknowledgement
Expand All @@ -17,7 +19,7 @@ This crate will not be possible without
## Installtion

```text
git clone https://github.com/Ethan-000/noir --branch demo-0.1.2
git clone https://github.com/Mach-34/noir --branch demo-0.1.3
```

```text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ impl ProofSystemCompiler for AxiomHalo2 {
fn supports_opcode(&self, opcode: &acvm::acir::circuit::Opcode) -> bool {
match opcode {
Opcode::Arithmetic(_) => true,
Opcode::Directive(_) => false,
Opcode::Block(_) => false,
Opcode::ROM(_) => false,
Opcode::RAM(_) => false,
Opcode::Oracle(_) => false,
Opcode::Directive(_) | Opcode::Brillig(_) => true,
Opcode::BlackBoxFuncCall(func) => match func.get_black_box_func() {
BlackBoxFunc::AND | BlackBoxFunc::RANGE => true,

Expand All @@ -115,12 +111,13 @@ impl ProofSystemCompiler for AxiomHalo2 {
| BlackBoxFunc::Pedersen
| BlackBoxFunc::HashToField128Security
| BlackBoxFunc::EcdsaSecp256k1
| BlackBoxFunc::EcdsaSecp256r1
| BlackBoxFunc::Keccak256
| BlackBoxFunc::FixedBaseScalarMul
| BlackBoxFunc::RecursiveAggregation
| BlackBoxFunc::SchnorrVerify => false,
},
Opcode::Brillig(_) => todo!(),
Opcode::Block(_) | Opcode::ROM(_) | Opcode::RAM(_) => false,
}
}

Expand Down
35 changes: 15 additions & 20 deletions crates/noir_halo2_backend_axiom/src/acvm_interop/pwg.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
use acvm::{acir::FieldElement, BlackBoxFunctionSolver, BlackBoxResolutionError};

use crate::AxiomHalo2;
use acvm::{acir::native_types::Witness, pwg::OpcodeResolutionError, PartialWitnessGenerator};

impl PartialWitnessGenerator for AxiomHalo2 {
impl BlackBoxFunctionSolver for AxiomHalo2 {
fn schnorr_verify(
&self,
_initial_witness: &mut acvm::acir::native_types::WitnessMap,
_public_key_x: &acvm::acir::circuit::opcodes::FunctionInput,
_public_key_y: &acvm::acir::circuit::opcodes::FunctionInput,
_signature: &[acvm::acir::circuit::opcodes::FunctionInput],
_message: &[acvm::acir::circuit::opcodes::FunctionInput],
_output: &Witness,
) -> Result<acvm::pwg::OpcodeResolution, OpcodeResolutionError> {
todo!()
_public_key_x: &FieldElement,
_public_key_y: &FieldElement,
_signature: &[u8],
_message: &[u8],
) -> Result<bool, BlackBoxResolutionError> {
Err(BlackBoxResolutionError::Unsupported(acvm::acir::BlackBoxFunc::SchnorrVerify))
}

fn pedersen(
&self,
_initial_witness: &mut acvm::acir::native_types::WitnessMap,
_inputs: &[acvm::acir::circuit::opcodes::FunctionInput],
_inputs: &[FieldElement],
_domain_separator: u32,
_outputs: &[Witness],
) -> Result<acvm::pwg::OpcodeResolution, OpcodeResolutionError> {
todo!()
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
Err(BlackBoxResolutionError::Unsupported(acvm::acir::BlackBoxFunc::Pedersen))
}

fn fixed_base_scalar_mul(
&self,
_initial_witness: &mut acvm::acir::native_types::WitnessMap,
_input: &acvm::acir::circuit::opcodes::FunctionInput,
_outputs: &[Witness],
) -> Result<acvm::pwg::OpcodeResolution, OpcodeResolutionError> {
todo!()
_input: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
Err(BlackBoxResolutionError::Unsupported(acvm::acir::BlackBoxFunc::FixedBaseScalarMul))
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{circuit_translator::NoirHalo2Translator, AxiomHalo2};
use acvm::SmartContract;
use acvm::{acir::circuit::Circuit, SmartContract};
use halo2_base::halo2_proofs::{
halo2curves::bn256::{Bn256, Fq, Fr, G1Affine},
plonk::VerifyingKey,
Expand Down Expand Up @@ -40,6 +40,7 @@ impl SmartContract for AxiomHalo2 {
fn eth_contract_from_vk(
&self,
common_reference_string: &[u8],
circuit: &Circuit,
verification_key: &[u8],
) -> Result<String, Self::Error> {
let params = ParamsKZG::<Bn256>::read_custom(
Expand All @@ -54,6 +55,9 @@ impl SmartContract for AxiomHalo2 {
)
.unwrap();

Ok(gen_evm_verifier(&params, &vk, vec![0]))
// get number of public inputs used in circuit
let num_instance = circuit.public_inputs().0.len();

Ok(gen_evm_verifier(&params, &vk, vec![num_instance]))
}
}
11 changes: 5 additions & 6 deletions crates/noir_halo2_backend_axiom/src/circuit_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ impl Halo2PlonkCircuit<Fr> for NoirHalo2Translator<Fr> {
&config,
);
}
BlackBoxFuncCall::EcdsaSecp256r1 { .. } => {
todo!()
}
BlackBoxFuncCall::FixedBaseScalarMul { .. } => {
todo!()
}
Expand All @@ -173,16 +176,12 @@ impl Halo2PlonkCircuit<Fr> for NoirHalo2Translator<Fr> {
} => todo!(),
};
}
Opcode::Directive(_) | Opcode::Oracle(_) => {
Opcode::Directive(_) | Opcode::Brillig(_) => {
// Directives are only needed by the pwg
}
Opcode::Block(_) => {
// Block is managed by ACVM
}
Opcode::RAM(_) | Opcode::ROM(_) => {
Opcode::Block(_) | Opcode::ROM(_) | Opcode::RAM(_) => {
todo!()
}
Opcode::Brillig(_) => todo!(),
}
}
Ok(())
Expand Down
Loading
Loading