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

chore!: Remove partial backend feature #3805

Merged
merged 11 commits into from
Dec 15, 2023
6 changes: 0 additions & 6 deletions .github/workflows/publish-acvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ jobs:
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.ACVM_CRATES_IO_TOKEN }}

- name: Publish acvm_stdlib
run: |
cargo publish --package acvm_stdlib
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.ACVM_CRATES_IO_TOKEN }}

- name: Publish brillig_vm
run: |
cargo publish --package brillig_vm
Expand Down
8 changes: 0 additions & 8 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ members = [
"acvm-repo/acir",
"acvm-repo/acvm",
"acvm-repo/acvm_js",
"acvm-repo/stdlib",
"acvm-repo/brillig",
"acvm-repo/brillig_vm",
"acvm-repo/blackbox_solver",
Expand All @@ -53,7 +52,6 @@ repository = "https://github.com/noir-lang/noir/"
acir_field = { version = "0.37.0", path = "acvm-repo/acir_field", default-features = false }
acir = { version = "0.37.0", path = "acvm-repo/acir", default-features = false }
acvm = { version = "0.37.0", path = "acvm-repo/acvm" }
stdlib = { version = "0.37.0", package = "acvm_stdlib", path = "acvm-repo/stdlib", default-features = false }
brillig = { version = "0.37.0", path = "acvm-repo/brillig", default-features = false }
brillig_vm = { version = "0.37.0", path = "acvm-repo/brillig_vm", default-features = false }
acvm_blackbox_solver = { version = "0.37.0", path = "acvm-repo/blackbox_solver", default-features = false }
Expand Down
3 changes: 0 additions & 3 deletions acvm-repo/acir/src/circuit/black_box_functions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! Black box functions are ACIR opcodes which rely on backends implementing support for specialized constraints.
//! This makes certain zk-snark unfriendly computations cheaper than if they were implemented in more basic constraints.
//!
//! It is possible to fallback to less efficient implementations written in ACIR in some cases.
//! These are implemented inside the ACVM stdlib.

use serde::{Deserialize, Serialize};
#[cfg(test)]
Expand Down
26 changes: 0 additions & 26 deletions acvm-repo/acir/src/circuit/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@
},
}

#[derive(Clone, PartialEq, Eq, Debug)]
pub enum UnsupportedMemoryOpcode {
MemoryOp,
MemoryInit,
}

impl std::fmt::Display for UnsupportedMemoryOpcode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
UnsupportedMemoryOpcode::MemoryOp => write!(f, "MemoryOp"),
UnsupportedMemoryOpcode::MemoryInit => write!(f, "MemoryInit"),
}
}
}

impl Opcode {
// TODO We can add a domain separator by doing something like:
// TODO concat!("directive:", directive.name)
Expand All @@ -62,17 +47,6 @@
}
}

pub fn unsupported_opcode(&self) -> UnsupportedMemoryOpcode {
match self {
Opcode::MemoryOp { .. } => UnsupportedMemoryOpcode::MemoryOp,
Opcode::MemoryInit { .. } => UnsupportedMemoryOpcode::MemoryInit,
Opcode::BlackBoxFuncCall(_) => {
unreachable!("Unsupported Blackbox function should not be reported here")
}
_ => unreachable!("Opcode is supported"),
}
}

pub fn is_arithmetic(&self) -> bool {
matches!(self, Opcode::Arithmetic(_))
}
Expand Down Expand Up @@ -117,7 +91,7 @@
}
Opcode::BlackBoxFuncCall(g) => write!(f, "{g}"),
Opcode::Directive(Directive::ToLeRadix { a, b, radix: _ }) => {
write!(f, "DIR::TORADIX ")?;

Check warning on line 94 in acvm-repo/acir/src/circuit/opcodes.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (TORADIX)
write!(
f,
// TODO (Note): this assumes that the decomposed bits have contiguous witness indices
Expand All @@ -129,7 +103,7 @@
)
}
Opcode::Directive(Directive::PermutationSort { inputs: a, tuple, bits, sort_by }) => {
write!(f, "DIR::PERMUTATIONSORT ")?;

Check warning on line 106 in acvm-repo/acir/src/circuit/opcodes.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (PERMUTATIONSORT)
write!(
f,
"(permutation size: {} {}-tuples, sort_by: {:#?}, bits: [_{}..._{}]))",
Expand Down
7 changes: 1 addition & 6 deletions acvm-repo/acvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,23 @@ num-traits.workspace = true
thiserror.workspace = true

acir.workspace = true
stdlib.workspace = true
brillig_vm.workspace = true
acvm_blackbox_solver.workspace = true

indexmap = "1.7.0"

[features]
default = ["bn254", "testing"]
default = ["bn254"]
bn254 = [
"acir/bn254",
"stdlib/bn254",
"brillig_vm/bn254",
"acvm_blackbox_solver/bn254",
]
bls12_381 = [
"acir/bls12_381",
"stdlib/bls12_381",
"brillig_vm/bls12_381",
"acvm_blackbox_solver/bls12_381",
]
testing = ["stdlib/testing", "unstable-fallbacks"]
unstable-fallbacks = []

[dev-dependencies]
rand = "0.8.5"
Expand Down
24 changes: 4 additions & 20 deletions acvm-repo/acvm/src/compiler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use acir::{
circuit::{opcodes::UnsupportedMemoryOpcode, Circuit, Opcode, OpcodeLocation},
BlackBoxFunc,
};
use thiserror::Error;
use acir::circuit::{Circuit, OpcodeLocation};

use crate::Language;

Expand All @@ -15,14 +11,6 @@ use optimizers::optimize_internal;
pub use transformers::transform;
use transformers::transform_internal;

#[derive(PartialEq, Eq, Debug, Error)]
pub enum CompileError {
#[error("The blackbox function {0} is not supported by the backend and acvm does not have a fallback implementation")]
UnsupportedBlackBox(BlackBoxFunc),
#[error("The opcode {0} is not supported by the backend and acvm does not have a fallback implementation")]
UnsupportedMemoryOpcode(UnsupportedMemoryOpcode),
}

/// This module moves and decomposes acir opcodes. The transformation map allows consumers of this module to map
/// metadata they had about the opcodes to the new opcode structure generated after the transformation.
#[derive(Debug)]
Expand Down Expand Up @@ -69,17 +57,13 @@ fn transform_assert_messages(
}

/// Applies [`ProofSystemCompiler`][crate::ProofSystemCompiler] specific optimizations to a [`Circuit`].
pub fn compile(
acir: Circuit,
np_language: Language,
is_opcode_supported: impl Fn(&Opcode) -> bool,
) -> Result<(Circuit, AcirTransformationMap), CompileError> {
pub fn compile(acir: Circuit, np_language: Language) -> (Circuit, AcirTransformationMap) {
let (acir, AcirTransformationMap { acir_opcode_positions }) = optimize_internal(acir);

let (mut acir, transformation_map) =
transform_internal(acir, np_language, is_opcode_supported, acir_opcode_positions)?;
transform_internal(acir, np_language, acir_opcode_positions);

acir.assert_messages = transform_assert_messages(acir.assert_messages, &transformation_map);

Ok((acir, transformation_map))
(acir, transformation_map)
}
158 changes: 0 additions & 158 deletions acvm-repo/acvm/src/compiler/transformers/fallback.rs

This file was deleted.

25 changes: 7 additions & 18 deletions acvm-repo/acvm/src/compiler/transformers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,30 @@
native_types::{Expression, Witness},
FieldElement,
};
use indexmap::IndexMap;

Check warning on line 6 in acvm-repo/acvm/src/compiler/transformers/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (indexmap)

use crate::Language;

mod csat;

Check warning on line 10 in acvm-repo/acvm/src/compiler/transformers/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (csat)
mod fallback;
mod r1cs;

pub(crate) use csat::CSatTransformer;

Check warning on line 13 in acvm-repo/acvm/src/compiler/transformers/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (csat)
pub(crate) use fallback::FallbackTransformer;
pub(crate) use r1cs::R1CSTransformer;

use super::{transform_assert_messages, AcirTransformationMap, CompileError};
use super::{transform_assert_messages, AcirTransformationMap};

/// Applies [`ProofSystemCompiler`][crate::ProofSystemCompiler] specific optimizations to a [`Circuit`].
pub fn transform(
acir: Circuit,
np_language: Language,
is_opcode_supported: impl Fn(&Opcode) -> bool,
) -> Result<(Circuit, AcirTransformationMap), CompileError> {
pub fn transform(acir: Circuit, np_language: Language) -> (Circuit, AcirTransformationMap) {
// Track original acir opcode positions throughout the transformation passes of the compilation
// by applying the modifications done to the circuit opcodes and also to the opcode_positions (delete and insert)
let acir_opcode_positions = acir.opcodes.iter().enumerate().map(|(i, _)| i).collect();

let (mut acir, transformation_map) =
transform_internal(acir, np_language, is_opcode_supported, acir_opcode_positions)?;
transform_internal(acir, np_language, acir_opcode_positions);

acir.assert_messages = transform_assert_messages(acir.assert_messages, &transformation_map);

Ok((acir, transformation_map))
(acir, transformation_map)
}

/// Applies [`ProofSystemCompiler`][crate::ProofSystemCompiler] specific optimizations to a [`Circuit`].
Expand All @@ -41,29 +35,24 @@
pub(super) fn transform_internal(
acir: Circuit,
np_language: Language,
is_opcode_supported: impl Fn(&Opcode) -> bool,
acir_opcode_positions: Vec<usize>,
) -> Result<(Circuit, AcirTransformationMap), CompileError> {
// Fallback transformer pass
let (acir, acir_opcode_positions) =
FallbackTransformer::transform(acir, is_opcode_supported, acir_opcode_positions)?;

) -> (Circuit, AcirTransformationMap) {
let mut transformer = match &np_language {
crate::Language::R1CS => {
let transformation_map = AcirTransformationMap { acir_opcode_positions };
let transformer = R1CSTransformer::new(acir);
return Ok((transformer.transform(), transformation_map));
return (transformer.transform(), transformation_map);
}
crate::Language::PLONKCSat { width } => {
let mut csat = CSatTransformer::new(*width);

Check warning on line 47 in acvm-repo/acvm/src/compiler/transformers/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (csat)
for value in acir.circuit_arguments() {
csat.mark_solvable(value);

Check warning on line 49 in acvm-repo/acvm/src/compiler/transformers/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (csat)
}
csat

Check warning on line 51 in acvm-repo/acvm/src/compiler/transformers/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (csat)
}
};

// TODO: the code below is only for CSAT transformer

Check warning on line 55 in acvm-repo/acvm/src/compiler/transformers/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (CSAT)
// TODO it may be possible to refactor it in a way that we do not need to return early from the r1cs
// TODO or at the very least, we could put all of it inside of CSatOptimizer pass

Expand Down Expand Up @@ -217,5 +206,5 @@
let transformation_map =
AcirTransformationMap { acir_opcode_positions: new_acir_opcode_positions };

Ok((acir, transformation_map))
(acir, transformation_map)
}
Loading
Loading