Skip to content

Commit

Permalink
feat!: ark to 0.5.0, co-noir witext works with 1.0.0-beta.2
Browse files Browse the repository at this point in the history
  • Loading branch information
florin5f authored and rw0x0 committed Feb 12, 2025
1 parent 88e09e7 commit 89a1fab
Show file tree
Hide file tree
Showing 84 changed files with 500 additions and 1,700 deletions.
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ publish = false
readme = "./README.md"

[workspace.dependencies]
acir = { version = "1.0.0-beta.1", git = "https://github.com/noir-lang/noir/", tag = "v1.0.0-beta.1", package = "acir" }
acvm = { version = "1.0.0-beta.1", git = "https://github.com/noir-lang/noir/", tag = "v1.0.0-beta.1", package = "acvm" }
ark-bls12-381 = "0.4.0"
ark-bn254 = "0.4.0"
ark-ec = { version = "0.4.2", default-features = false }
ark-ff = "0.4.2"
ark-poly = "0.4.2"
ark-serialize = { version = "0.4", features = ["derive", "std"] }
ark-std = { version = "0.4.0", features = ["std"] }
acir = { version = "1.0.0-beta.2", git = "https://github.com/noir-lang/noir/", tag = "v1.0.0-beta.2", package = "acir" }
acvm = { version = "1.0.0-beta.2", git = "https://github.com/noir-lang/noir/", tag = "v1.0.0-beta.2", package = "acvm" }
ark-bls12-381 = "^0.5.0"
ark-bn254 = "^0.5.0"
ark-ec = { version = "^0.5.0", default-features = false }
ark-ff = "^0.5.0"
ark-poly = "^0.5.0"
ark-serialize = { version = "^0.5.0", features = ["derive", "std"] }
ark-std = { version = "^0.5.0", features = ["std"] }
bincode = "1.3.3"
brillig = { version = "1.0.0-beta.1", git = "https://github.com/noir-lang/noir/", tag = "v1.0.0-beta.1", package = "brillig" }
brillig = { version = "1.0.0-beta.2", git = "https://github.com/noir-lang/noir/", tag = "v1.0.0-beta.2", package = "brillig" }
bytemuck = { version = "1.15", features = ["derive"] }
byteorder = "1.5.0"
bytes = "1.5.0"
Expand All @@ -53,8 +53,8 @@ futures = "0.3.30"
hex-literal = "0.4.1"
intmap = "2.0.0"
itertools = "0.13.0"
noirc-abi = { version = "1.0.0-beta.1", git = "https://github.com/noir-lang/noir/", tag = "v1.0.0-beta.1", package = "noirc_abi" }
noirc-artifacts = { version = "1.0.0-beta.1", git = "https://github.com/noir-lang/noir/", tag = "v1.0.0-beta.1", package = "noirc_artifacts" }
noirc-abi = { version = "1.0.0-beta.2", git = "https://github.com/noir-lang/noir/", tag = "v1.0.0-beta.2", package = "noirc_abi" }
noirc-artifacts = { version = "1.0.0-beta.2", git = "https://github.com/noir-lang/noir/", tag = "v1.0.0-beta.2", package = "noirc_artifacts" }
num-bigint = { version = "0.4.5" }
num-traits = { version = "0.2.18", default-features = false }
paste = "1.0.15"
Expand Down
2 changes: 1 addition & 1 deletion co-circom/co-groth16/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ark-bls12-381 = { workspace = true }
ark-bn254 = { workspace = true }
ark-ec = { workspace = true }
ark-ff = { workspace = true }
ark-groth16 = { version = "=0.4.0", default-features = false, features = [
ark-groth16 = { version = "=0.5.0", default-features = false, features = [
"parallel",
], optional = true }
ark-poly = { workspace = true }
Expand Down
5 changes: 2 additions & 3 deletions co-circom/co-plonk/src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
//! You will most likely need the plain PLONK implementation to verify a proof from co-PLONK. For that
//! see the [`Plonk::verify`] method.
use std::{marker::PhantomData, sync::Arc};

use crate::{mpc::plain::PlainPlonkDriver, plonk_utils, types::Domains, CoPlonk};
use ark_ec::{pairing::Pairing, Group};
use ark_ec::{pairing::Pairing, PrimeGroup};
use ark_ff::Field;
use circom_types::{
plonk::{JsonVerificationKey, PlonkProof, ZKey},
Expand All @@ -16,6 +14,7 @@ use circom_types::{
use co_circom_snarks::{SharedWitness, VerificationError};
use num_traits::One;
use num_traits::Zero;
use std::{marker::PhantomData, sync::Arc};

use crate::types::Keccak256Transcript;

Expand Down
27 changes: 17 additions & 10 deletions co-noir/co-brillig/src/blackbox.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ark_ff::PrimeField;
use brillig::{BlackBoxOp, HeapArray, IntegerBitSize, MemoryAddress};
use brillig::{BlackBoxOp, IntegerBitSize, MemoryAddress};
use eyre::Context;

use crate::{mpc::BrilligDriver, CoBrilligVM};
Expand All @@ -14,9 +14,10 @@ where
BlackBoxOp::ToRadix {
input,
radix,
output,
output_pointer,
num_limbs,
output_bits,
} => self.handle_to_radix(input, radix, output, output_bits)?,
} => self.handle_to_radix(input, radix, output_pointer, num_limbs, output_bits)?,
x => todo!("unimplemented blackbox {x:?}"),
}
self.increment_program_counter();
Expand All @@ -27,21 +28,27 @@ where
&mut self,
input: MemoryAddress,
radix: MemoryAddress,
output: HeapArray,
output_bits: bool,
output_pointer: MemoryAddress,
num_limbs: MemoryAddress,
output_bits: MemoryAddress,
) -> eyre::Result<()> {
let input = self
.memory
.try_read_field(input)
.context("while geting field for ToRadix")?;
.context("while getting field for ToRadix")?;
let radix = self
.memory
.try_read_int(radix, IntegerBitSize::U32)
.context("while getting radix for ToRadix")?;
let limbs = self
.driver
.to_radix(input, radix, output.size, output_bits)?;
let mem_offset = self.memory.read_ref(output.pointer)?;
let num_limbs = self.memory.try_read_usize(num_limbs)?;
let output_bits = self
.memory
.try_read_int(output_bits, IntegerBitSize::U1)
.context("while getting output_bits for ToRadix")?;
let output_bits = T::try_into_bool(output_bits).expect("output_bits must be a public");

let limbs = self.driver.to_radix(input, radix, num_limbs, output_bits)?;
let mem_offset = self.memory.read_ref(output_pointer)?;
self.memory.write_slice(mem_offset, &limbs)?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion co-noir/co-brillig/src/brillig_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use acir::{
use ark_ff::PrimeField;
use brillig::{BitSize, HeapVector, Label, MemoryAddress, Opcode as BrilligOpcode};

/// The coBrillig-VM. If executes unconstrained functions for coNoir.
/// The coBrillig-VM. It executes unconstrained functions for coNoir.
///
/// In contrast to Noir's Brillig-VM, we initiate one instance and reuse
/// it during the whole process. This is mostly because we need a network
Expand Down
5 changes: 2 additions & 3 deletions co-noir/co-builder/src/crs/parse.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// modified from barustenberg:

use super::{Crs, ProverCrs};
use ark_ec::pairing::Pairing;
use ark_ec::AffineRepr;
use ark_ec::CurveGroup;
use ark_ec::{pairing::Pairing, AffineRepr, CurveGroup};
use ark_serialize::CanonicalDeserialize;
use eyre::{anyhow, Result};
use std::fs::File;
Expand Down Expand Up @@ -145,6 +143,7 @@ mod tests {
use super::*;
use ark_bn254::{Bn254, Fq12, G1Affine, G2Affine};
use ark_ec::{pairing::Pairing, AffineRepr};
use ark_ff::AdditiveGroup;
use ark_ff::Field;

#[test]
Expand Down
6 changes: 4 additions & 2 deletions co-noir/co-builder/src/keys/proving_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
polynomial_types::{Polynomials, PrecomputedEntities},
},
types::types::{
AggregationObjectPubInputIndices, CyclicPermutation, Mapping, PermutationMapping,
TraceData, NUM_WIRES,
ActiveRegionData, AggregationObjectPubInputIndices, CyclicPermutation, Mapping,
PermutationMapping, TraceData, NUM_WIRES,
},
HonkProofResult,
};
Expand All @@ -30,6 +30,7 @@ pub struct ProvingKey<P: Pairing> {
pub memory_read_records: Vec<u32>,
pub memory_write_records: Vec<u32>,
pub final_active_wire_idx: usize,
pub active_region_data: ActiveRegionData,
}

impl<P: Pairing> ProvingKey<P> {
Expand Down Expand Up @@ -139,6 +140,7 @@ impl<P: Pairing> ProvingKey<P> {
contains_pairing_point_accumulator: false,
pairing_point_accumulator_public_input_indices: [0;
crate::types::types::AGGREGATION_OBJECT_SIZE],
active_region_data: ActiveRegionData::default(),
}
}

Expand Down
10 changes: 5 additions & 5 deletions co-noir/co-builder/src/polynomials/polynomial_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ impl<T: Default> PrecomputedEntities<T> {
/// column 5
const Q_4: usize = 5;
/// column 6
const Q_ARITH: usize = 6;
const Q_LOOKUP: usize = 6;
/// column 7
const Q_DELTA_RANGE: usize = 7;
const Q_ARITH: usize = 7;
/// column 8
const Q_ELLIPTIC: usize = 8;
const Q_DELTA_RANGE: usize = 8;
/// column 9
const Q_AUX: usize = 9;
const Q_ELLIPTIC: usize = 9;
/// column 10
const Q_LOOKUP: usize = 10;
const Q_AUX: usize = 10;
/// column 11
const Q_POSEIDON2_EXTERNAL: usize = 11;
/// column 12
Expand Down
38 changes: 38 additions & 0 deletions co-noir/co-builder/src/types/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2043,3 +2043,41 @@ impl<F: PrimeField> WitnessOrConstant<F> {
}
}
}

#[derive(Default)]
pub struct ActiveRegionData {
pub(crate) ranges: Vec<(usize, usize)>,
pub(crate) idx: Vec<usize>,
pub(crate) current_end: usize,
}

impl ActiveRegionData {
pub(crate) fn add_range(&mut self, start: usize, end: usize) {
assert!(start >= self.current_end);
self.ranges.push((start, end));
for i in start..end {
self.idx.push(i);
}
self.current_end = end;
}

pub(crate) fn get_ranges(&self) -> &[(usize, usize)] {
&self.ranges
}

pub fn get_idx(&self, idx: usize) -> usize {
self.idx[idx]
}

pub fn get_range(&self, idx: usize) -> (usize, usize) {
self.ranges[idx]
}

pub fn size(&self) -> usize {
self.idx.len()
}

pub fn num_ranges(&self) -> usize {
self.ranges.len()
}
}
6 changes: 3 additions & 3 deletions co-noir/co-noir/Readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# UltraHonk

This crate uses our rewrite of Atec's UltraHonk prover and verifier in Rust (see `co-snarks/co-noir/ultrahonk`). It is compatible with Barretenberg v0.66.0 To get Barretenberg with this version, use the following commands:
This crate uses our rewrite of Atec's UltraHonk prover and verifier in Rust (see `co-snarks/co-noir/ultrahonk`). It is compatible with Barretenberg v0.72.1 To get Barretenberg with this version, use the following commands:

```bash
git clone https://github.com/AztecProtocol/aztec-packages.git
cd aztec-packages
git checkout tags/aztec-package-v0.66.0
git checkout tags/aztec-package-v0.72.1
```

To compile Barretenberg, one can use:
Expand All @@ -31,7 +31,7 @@ First, one needs to create the circuit file from a Noir source code. Your Noir p
- `Nargo.toml`: Similar to Cargo.toml, just for Noir projects.
- `Prover.toml`: The inputs for the main function in `src/main.nr` used in proof generation.

To create the circuit file used in Co-Noir, one needs to install Nargo following the instructions in [https://noir-lang.org/docs/getting_started/installation/](https://noir-lang.org/docs/getting_started/installation/). Our prover is compatible with Nargo version v1.0.0-beta.1.
To create the circuit file used in Co-Noir, one needs to install Nargo following the instructions in [https://noir-lang.org/docs/getting_started/installation/](https://noir-lang.org/docs/getting_started/installation/). Our prover is compatible with Nargo version v1.0.0-beta.2.
Then you can just execute the following command:

```bash
Expand Down
4 changes: 2 additions & 2 deletions co-noir/co-noir/examples/compare.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export CARGO_TERM_QUIET=true
BARRETENBERG_BINARY=~/.bb/bb ##specify the $BARRETENBERG_BINARY path here

NARGO_VERSION=1.0.0-beta.1 ##specify the desired nargo version here
BARRETENBERG_VERSION=0.66.0 ##specify the desired barretenberg version here or use the corresponding one for this nargo version
NARGO_VERSION=1.0.0-beta.2 ##specify the desired nargo version here
BARRETENBERG_VERSION=0.72.1 ##specify the desired barretenberg version here or use the corresponding one for this nargo version
PLAINDRIVER="../../../target/release/plaindriver"
exit_code=0

Expand Down
4 changes: 2 additions & 2 deletions co-noir/co-noir/examples/compare_mpc.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export CARGO_TERM_QUIET=true
BARRETENBERG_BINARY=~/.bb/bb ##specify the $BARRETENBERG_BINARY path here

NARGO_VERSION=1.0.0-beta.1 ##specify the desired nargo version here
BARRETENBERG_VERSION=0.66.0 ##specify the desired barretenberg version here or use the corresponding one for this nargo version
NARGO_VERSION=1.0.0-beta.2 ##specify the desired nargo version here
BARRETENBERG_VERSION=0.72.1 ##specify the desired barretenberg version here or use the corresponding one for this nargo version
PLAINDRIVER="../../../target/release/plaindriver"
exit_code=0

Expand Down
6 changes: 3 additions & 3 deletions co-noir/co-noir/examples/compare_mpc_recursive.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export CARGO_TERM_QUIET=true
BARRETENBERG_BINARY=~/.bb/bb ##specify the $BARRETENBERG_BINARY path here

NARGO_VERSION=1.0.0-beta.1 ##specify the desired nargo version here
BARRETENBERG_VERSION=0.66.0 ##specify the desired barretenberg version here or use the corresponding one for this nargo version
NARGO_VERSION=1.0.0-beta.2 ##specify the desired nargo version here
BARRETENBERG_VERSION=0.72.1 ##specify the desired barretenberg version here or use the corresponding one for this nargo version
PLAINDRIVER="../../../target/release/plaindriver"
exit_code=0

Expand Down Expand Up @@ -127,7 +127,7 @@ for f in "${test_cases[@]}"; do
# exit_code=1
# echo "::error::" $f "failed"
# fi
run_proof_verification "$f"
run_proof_verification "$f"
bash cleanup.sh
echo ""
done
Expand Down
10 changes: 5 additions & 5 deletions co-noir/co-noir/examples/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

script_dir="$(dirname "$(realpath "$0")")"

NARGO_VERSION=1.0.0-beta.1 ##specify the desired nargo version here
NARGO_VERSION=1.0.0-beta.2 ##specify the desired nargo version here

## install noirup: curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
r=$(bash -c "nargo --version")
Expand All @@ -19,11 +19,11 @@ for folder in "$script_dir"/test_vectors/*; do

cd "$folder" || { echo "Failed to enter folder $folder"; continue; }


echo "Executing commands in $folder"

nargo execute

if [ -d "target" ]; then
echo "Moving files from target in $folder"
mv -f target/* . 2>/dev/null || echo "No files to move or failed to move files"
Expand All @@ -37,4 +37,4 @@ for folder in "$script_dir"/test_vectors/*; do

done

echo "All folders processed."
echo "All folders processed."
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main(x: Field) -> pub [u8; 32] {
///Safety: get_bytes is safe
unsafe {
//@safety: get_bytes is safe
get_bytes(x)
}
}
Expand Down
82 changes: 81 additions & 1 deletion co-noir/co-noir/examples/test_vectors/quantized/quantized.json

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions co-noir/co-noir/examples/test_vectors/quantized/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl Quantized {
fn mul(self: Self, other: Self) -> Self {
let mut temp: Field = self.x * other.x;
let mut bytes: [u8; 32] = [0; 32];
///Safety: get_bytes is safe
unsafe {
//@safety: get_bytes is safe
bytes = get_bytes(temp);
}

Expand All @@ -73,8 +73,8 @@ impl Quantized {
temp = 21888242871839275222246405745257275088548364400416034343698204186575808495616
- temp
+ 1;
///Safety: get_bytes is safe
unsafe {
//@safety: get_bytes is safe
bytes = get_bytes(temp);
}

Expand Down Expand Up @@ -120,14 +120,11 @@ impl Mul for Quantized {

impl Ord for Quantized { // TODO is it cheaper to create a function that returns a bool directly?
fn cmp(self: Self, other: Self) -> Ordering {
if self.x == other.x {
Ordering::equal()
}

let self_positive = is_positive(self.x);
let other_positive = is_positive(other.x);

if (self_positive & !other_positive) {
if self.x == other.x {
Ordering::equal()
} else if (self_positive & !other_positive) {
Ordering::greater()
} else if self_positive == other_positive {
let self_smallest = self.x.lt(other.x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ unconstrained fn add(x: u32, y: u32) -> u32 {

fn main(x: u32, y: u32, z: pub u32) {
assert(
unsafe {
//@safety: is safe
add(x, y)
}
///Safety: is safe
unsafe { add(x, y) }
== z,
);
}
Expand Down
Loading

0 comments on commit 89a1fab

Please sign in to comment.