Skip to content

Commit

Permalink
chore!: Remove partial backend feature (#3805)
Browse files Browse the repository at this point in the history
# Description

Related to #3772 

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*



## Additional Context



## Documentation\*

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [ ] I have tested the changes locally.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: Tom French <[email protected]>
Co-authored-by: TomAFrench <[email protected]>
  • Loading branch information
3 people authored Dec 15, 2023
1 parent eaf13bc commit 0383100
Show file tree
Hide file tree
Showing 44 changed files with 72 additions and 3,556 deletions.
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.

1 change: 0 additions & 1 deletion 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 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 @@ pub enum Opcode {
},
}

#[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 @@ impl Opcode {
}
}

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
7 changes: 1 addition & 6 deletions acvm-repo/acvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,23 @@ thiserror.workspace = true
log.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,10 +1,6 @@
use std::collections::HashMap;

use acir::{
circuit::{opcodes::UnsupportedMemoryOpcode, Circuit, Opcode, OpcodeLocation},
BlackBoxFunc,
};
use thiserror::Error;
use acir::circuit::{Circuit, OpcodeLocation};

use crate::Language;

Expand All @@ -17,14 +13,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 @@ -81,19 +69,15 @@ 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, acir_opcode_positions) = optimize_internal(acir);

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

let transformation_map = AcirTransformationMap::new(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 @@ -8,33 +8,27 @@ use indexmap::IndexMap;
use crate::Language;

mod csat;
mod fallback;
mod r1cs;

pub(crate) use csat::CSatTransformer;
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, acir_opcode_positions) =
transform_internal(acir, np_language, is_opcode_supported, acir_opcode_positions)?;
transform_internal(acir, np_language, acir_opcode_positions);

let transformation_map = AcirTransformationMap::new(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 @@ -43,19 +37,14 @@ pub fn transform(
pub(super) fn transform_internal(
acir: Circuit,
np_language: Language,
is_opcode_supported: impl Fn(&Opcode) -> bool,
acir_opcode_positions: Vec<usize>,
) -> Result<(Circuit, Vec<usize>), CompileError> {
) -> (Circuit, Vec<usize>) {
log::trace!("Start circuit transformation");

// Fallback transformer pass
let (acir, acir_opcode_positions) =
FallbackTransformer::transform(acir, is_opcode_supported, acir_opcode_positions)?;

let mut transformer = match &np_language {
crate::Language::R1CS => {
let transformer = R1CSTransformer::new(acir);
return Ok((transformer.transform(), acir_opcode_positions));
return (transformer.transform(), acir_opcode_positions);
}
crate::Language::PLONKCSat { width } => {
let mut csat = CSatTransformer::new(*width);
Expand Down Expand Up @@ -219,5 +208,5 @@ pub(super) fn transform_internal(

log::trace!("Finish circuit transformation");

Ok((acir, new_acir_opcode_positions))
(acir, new_acir_opcode_positions)
}
Loading

0 comments on commit 0383100

Please sign in to comment.