Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

feat(ci)!: add spellchecker #73

Merged
merged 3 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ jobs:
run: cargo clippy --verbose
- name: Run tests
run: cargo test --verbose

spellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: streetsidesoftware/cspell-action@v2
with:
files: |
**/*.{md,rs}
incremental_files_only : true # Run this action on files which have changed in PR
strict: false # Do not fail, if a spelling mistake is found (This can be annoying for contributors)
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- XOR, Range and AND gates are no longer special case. They are now another opcode in the GadgetCall
- Move fallback module to `stdlib`
- optimiser code and any other passes will live in acvm. acir is solely for defining the IR now.
- Optimizer code and any other passes will live in acvm. acir is solely for defining the IR now.
- ACIR passes now live under the compiler parent module
- Moved opcode module in acir crate to circuit/opcode
- Rename GadgetCall to BlackBoxFuncCall
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ACIR - Abstract Circuit Intermediate Representation

ACIR is an NP complete language that generalises R1CS and arithmetic circuits while not losing proving system specific optimisations through the use of black box functions.
ACIR is an NP complete language that generalizes R1CS and arithmetic circuits while not losing proving system specific optimizations through the use of black box functions.

# ACVM - Abstract Circuit Virtual Machine

This can be seen as the ACIR compiler. It will take an ACIR instance and convert it to the format required
by a particular proving system to create a proof.
by a particular proving system to create a proof.
4 changes: 2 additions & 2 deletions acir/src/circuit/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::{Read, Write};

use crate::{
native_types::{Expression, Witness},
serialisation::{read_n, read_u16, read_u32, write_bytes, write_u16, write_u32},
serialization::{read_n, read_u16, read_u32, write_bytes, write_u16, write_u32},
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -185,7 +185,7 @@ impl Directive {
}

#[test]
fn serialisation_roundtrip() {
fn serialization_roundtrip() {
fn read_write(directive: Directive) -> (Directive, Directive) {
let mut bytes = Vec::new();
directive.write(&mut bytes).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod opcodes;
pub use opcodes::Opcode;

use crate::native_types::Witness;
use crate::serialisation::{read_u32, write_u32};
use crate::serialization::{read_u32, write_u32};
use rmp_serde;
use serde::{Deserialize, Serialize};

Expand All @@ -27,7 +27,7 @@ impl Circuit {
}

#[deprecated(
note = "we want to use a serialisation strategy that is easy to implement in many languages (without ffi). use `read` instead"
note = "we want to use a serialization strategy that is easy to implement in many languages (without ffi). use `read` instead"
)]
pub fn from_bytes(bytes: &[u8]) -> Circuit {
let mut deflater = DeflateDecoder::new(bytes);
Expand All @@ -37,7 +37,7 @@ impl Circuit {
}

#[deprecated(
note = "we want to use a serialisation strategy that is easy to implement in many languages (without ffi).use `write` instead"
note = "we want to use a serialization strategy that is easy to implement in many languages (without ffi).use `write` instead"
)]
pub fn to_bytes(&self) -> Vec<u8> {
let buf = rmp_serde::to_vec(&self).unwrap();
Expand Down Expand Up @@ -69,7 +69,7 @@ impl Circuit {
// TODO (Note): we could use semver versioning from the Cargo.toml
// here and then reject anything that has a major bump
//
// We may also not want to do that if we do not want to couple serialisation
// We may also not want to do that if we do not want to couple serialization
// with other breaking changes
if version_number != VERSION_NUMBER {
return Err(std::io::ErrorKind::InvalidData.into());
Expand Down Expand Up @@ -178,7 +178,7 @@ mod test {
}

#[test]
fn serialisation_roundtrip() {
fn serialization_roundtrip() {
let circuit = Circuit {
current_witness_index: 5,
opcodes: vec![and_opcode(), range_opcode()],
Expand Down
6 changes: 3 additions & 3 deletions acir/src/circuit/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::{Read, Write};

use super::directives::Directive;
use crate::native_types::{Expression, Witness};
use crate::serialisation::{read_n, read_u16, read_u32, write_bytes, write_u16, write_u32};
use crate::serialization::{read_n, read_u16, read_u32, write_bytes, write_u16, write_u32};
use crate::BlackBoxFunc;
use serde::{Deserialize, Serialize};

Expand All @@ -25,7 +25,7 @@ impl Opcode {
}
// We have three types of opcodes allowed in the IR
// Expression, BlackBoxFuncCall and Directives
// When we serialise these opcodes, we use the index
// When we serialize these opcodes, we use the index
// to uniquely identify which category of opcode we are dealing with.
pub(crate) fn to_index(&self) -> u8 {
match self {
Expand Down Expand Up @@ -326,7 +326,7 @@ impl std::fmt::Debug for BlackBoxFuncCall {
}

#[test]
fn serialisation_roundtrip() {
fn serialization_roundtrip() {
fn read_write(opcode: Opcode) -> (Opcode, Opcode) {
let mut bytes = Vec::new();
opcode.write(&mut bytes).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion acir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pub mod circuit;
pub mod native_types;
mod serialisation;
mod serialization;

pub use acir_field::FieldElement;
pub use circuit::blackbox_functions::BlackBoxFunc;
8 changes: 4 additions & 4 deletions acir/src/native_types/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::native_types::{Linear, Witness};
use crate::serialisation::{read_field_element, read_u32, write_bytes, write_u32};
use crate::serialization::{read_field_element, read_u32, write_bytes, write_u32};
use acir_field::FieldElement;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
Expand All @@ -17,7 +17,7 @@ use super::witness::UnknownWitness;
// XXX: If we allow the degree of the quotient polynomial to be arbitrary, then we will need a vector of wire values
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Expression {
// To avoid having to create intermediate variables pre-optimisation
// To avoid having to create intermediate variables pre-optimization
// We collect all of the multiplication terms in the arithmetic gate
// A multiplication term if of the form q_M * wL * wR
// Hence this vector represents the following sum: q_M1 * wL1 * wR1 + q_M2 * wL2 * wR2 + .. +
Expand Down Expand Up @@ -448,7 +448,7 @@ impl Expression {
// A polynomial whose mul terms are non zero which do not match up with two terms in the fan-in cannot fit into one gate
// An example of this is: Axy + Bx + Cy + ...
// Notice how the bivariate monomial xy has two univariate monomials with their respective coefficients
// XXX: note that if x or y is zero, then we could apply a further optimisation, but this would be done in another algorithm.
// XXX: note that if x or y is zero, then we could apply a further optimization, but this would be done in another algorithm.
// It would be the same as when we have zero coefficients - Can only work if wire is constrained to be zero publicly
let mul_term = &self.mul_terms[0];

Expand Down Expand Up @@ -478,7 +478,7 @@ impl Expression {
}

#[test]
fn serialisation_roundtrip() {
fn serialization_roundtrip() {
// Empty expression
//
let expr = Expression::default();
Expand Down
2 changes: 1 addition & 1 deletion acir/src/native_types/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Witness {
// We use this, so that they are pushed to the beginning of the array
//
// When they are pushed to the beginning of the array, they are less likely to be used in an intermediate gate
// by the optimiser, which would mean two unknowns in an equation.
// by the optimizer, which would mean two unknowns in an equation.
// See Issue #20
// TODO: can we find a better solution to this?
pub struct UnknownWitness(pub u32);
Expand Down
2 changes: 1 addition & 1 deletion acir/src/serialisation.rs → acir/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn read_field_element<const NUM_BYTES: usize, R: Read>(

let bytes = read_n::<FIELD_ELEMENT_NUM_BYTES, _>(&mut r)?;

// TODO: We should not reduce here, we want the serialisation to be
// TODO: We should not reduce here, we want the serialization to be
// TODO canonical
let field_element = FieldElement::from_be_bytes_reduce(&bytes);

Expand Down
6 changes: 3 additions & 3 deletions acir_field/src/generic_ark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<F: PrimeField> std::fmt::Display for FieldElement<F> {
// we usually have numbers in the form 2^t * q + r
// We focus on 2^64, 2^32, 2^16, 2^8, 2^4 because
// they are common. We could extend this to a more
// general factorisation strategy, but we pay in terms of CPU time
// general factorization strategy, but we pay in terms of CPU time
let mul_sign = "×";
for power in [64, 32, 16, 8, 4] {
let power_of_two = BigUint::from(2_u128).pow(power);
Expand Down Expand Up @@ -226,7 +226,7 @@ impl<F: PrimeField> FieldElement<F> {
}

/// Computes the inverse or returns zero if the inverse does not exist
/// Before using this FieldElement, please ensure that this behaviour is necessary
/// Before using this FieldElement, please ensure that this behavior is necessary
pub fn inverse(&self) -> FieldElement<F> {
let inv = self.0.inverse().unwrap_or_else(F::zero);
FieldElement(inv)
Expand Down Expand Up @@ -297,7 +297,7 @@ impl<F: PrimeField> FieldElement<F> {
let num_elements = num_bytes / 8;

let mut bytes = self.to_be_bytes();
bytes.reverse(); // put it in big endian format. XXX(next refactor): we should be explicit about endianess.
bytes.reverse(); // put it in big endian format. XXX(next refactor): we should be explicit about endianness.

bytes[0..num_elements].to_vec()
}
Expand Down
36 changes: 18 additions & 18 deletions acvm/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The various passes that we can use over ACIR
pub mod fallback;
pub mod optimiser;
pub mod optimizer;

use crate::Language;
use acir::{
Expand All @@ -9,10 +9,10 @@ use acir::{
BlackBoxFunc,
};
use indexmap::IndexMap;
use optimiser::{CSatOptimiser, GeneralOptimiser};
use optimizer::{CSatOptimizer, GeneralOptimizer};
use thiserror::Error;

use self::{fallback::IsBlackBoxSupported, optimiser::R1CSOptimiser};
use self::{fallback::IsBlackBoxSupported, optimizer::R1CSOptimizer};

#[derive(PartialEq, Eq, Debug, Error)]
pub enum CompileError {
Expand All @@ -25,28 +25,28 @@ pub fn compile(
np_language: Language,
is_blackbox_supported: IsBlackBoxSupported,
) -> Result<Circuit, CompileError> {
// Instantiate the optimiser.
// Currently the optimiser and reducer are one in the same
// Instantiate the optimizer.
// Currently the optimizer and reducer are one in the same
// for CSAT

// Fallback pass
let fallback = fallback::fallback(acir, is_blackbox_supported)?;

let optimiser = match &np_language {
let optimizer = match &np_language {
crate::Language::R1CS => {
let optimiser = R1CSOptimiser::new(fallback);
return Ok(optimiser.optimise());
let optimizer = R1CSOptimizer::new(fallback);
return Ok(optimizer.optimize());
}
crate::Language::PLONKCSat { width } => CSatOptimiser::new(*width),
crate::Language::PLONKCSat { width } => CSatOptimizer::new(*width),
};

// TODO: the code below is only for CSAT optimiser
// TODO: the code below is only for CSAT optimizer
// 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 CSATOptimiser pass
// TODO or at the very least, we could put all of it inside of CSatOptimizer pass

// Optimise the arithmetic gates by reducing them into the correct width and
// Optimize the arithmetic gates by reducing them into the correct width and
// creating intermediate variables when necessary
let mut optimised_gates = Vec::new();
let mut optimized_gates = Vec::new();

let mut next_witness_index = fallback.current_witness_index + 1;
for opcode in fallback.opcodes {
Expand All @@ -55,7 +55,7 @@ pub fn compile(
let mut intermediate_variables: IndexMap<Witness, Expression> = IndexMap::new();

let arith_expr =
optimiser.optimise(arith_expr, &mut intermediate_variables, next_witness_index);
optimizer.optimize(arith_expr, &mut intermediate_variables, next_witness_index);

// Update next_witness counter
next_witness_index += intermediate_variables.len() as u32;
Expand All @@ -67,18 +67,18 @@ pub fn compile(
new_gates.push(arith_expr);
new_gates.sort();
for gate in new_gates {
optimised_gates.push(Opcode::Arithmetic(gate));
optimized_gates.push(Opcode::Arithmetic(gate));
}
}
other_gate => optimised_gates.push(other_gate),
other_gate => optimized_gates.push(other_gate),
}
}

let current_witness_index = next_witness_index - 1;

Ok(Circuit {
current_witness_index,
opcodes: optimised_gates,
public_inputs: fallback.public_inputs, // The optimiser does not add public inputs
opcodes: optimized_gates,
public_inputs: fallback.public_inputs, // The optimizer does not add public inputs
})
}
7 changes: 0 additions & 7 deletions acvm/src/compiler/optimiser/mod.rs

This file was deleted.

Loading