Skip to content

Commit

Permalink
Merge branch 'master' into tf/fuzz-sqrt
Browse files Browse the repository at this point in the history
* master: (62 commits)
  chore: keccak256 in Noir (#5316)
  chore: unbundle `check_array_is_initialized` (#5451)
  feat: Sync from aztec-packages (#5467)
  chore: bump bb to 0.45.1 (#5469)
  feat: prefix operator overload trait dispatch (#5423)
  feat: add CLI argument for debugging comptime blocks (#5192)
  chore: document EmbeddedCurvePoint (#5468)
  feat: lsp rename/find-all-references for struct members (#5443)
  feat(optimization): Deduplicate more instructions (#5457)
  fix: remove compile-time error for invalid indices (#5466)
  feat: lsp rename/find-all-references for local variables (#5439)
  feat: remove duplicated array reads at constant indices (#5445)
  fix: Account for the expected kind when resolving turbofish generics (#5448)
  fix: Fix issue with unresolved results (#5453)
  feat: apply `no_predicates` in stdlib (#5454)
  fix: prevent `no_predicates` from removing predicates in calling function (#5452)
  feat: lsp rename/find-all-references for globals (#5415)
  feat: remove redundant `EnableSideEffects` instructions (#5440)
  fix: Change panic to error in interpreter (#5446)
  feat: Add more slice methods to the stdlib (#5424)
  ...
  • Loading branch information
TomAFrench committed Jul 11, 2024
2 parents a194b22 + f7c4bdb commit 30854db
Show file tree
Hide file tree
Showing 318 changed files with 7,739 additions and 2,312 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ed815a3713fc311056a8bd0a616945f12d9be2a8
e44ef7042c87d3c78a14413ad7d54e4ed642ad89
8 changes: 8 additions & 0 deletions .github/workflows/mirror-external_libs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Mirror Repositories
on:
workflow_dispatch: {}
jobs:
lint:
runs-on: ubuntu-latest
steps:
- run: echo Dummy workflow TODO
2 changes: 1 addition & 1 deletion .github/workflows/publish-nargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl]
target: [x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl, aarch64-unknown-linux-gnu]
timeout-minutes: 30

steps:
Expand Down
12 changes: 8 additions & 4 deletions Cargo.lock

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

151 changes: 147 additions & 4 deletions acvm-repo/acir/codegen/acir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,33 @@ namespace Program {
static Witness bincodeDeserialize(std::vector<uint8_t>);
};

struct ConstantOrWitnessEnum {

struct Constant {
std::string value;

friend bool operator==(const Constant&, const Constant&);
std::vector<uint8_t> bincodeSerialize() const;
static Constant bincodeDeserialize(std::vector<uint8_t>);
};

struct Witness {
Program::Witness value;

friend bool operator==(const Witness&, const Witness&);
std::vector<uint8_t> bincodeSerialize() const;
static Witness bincodeDeserialize(std::vector<uint8_t>);
};

std::variant<Constant, Witness> value;

friend bool operator==(const ConstantOrWitnessEnum&, const ConstantOrWitnessEnum&);
std::vector<uint8_t> bincodeSerialize() const;
static ConstantOrWitnessEnum bincodeDeserialize(std::vector<uint8_t>);
};

struct FunctionInput {
Program::Witness witness;
Program::ConstantOrWitnessEnum input;
uint32_t num_bits;

friend bool operator==(const FunctionInput&, const FunctionInput&);
Expand Down Expand Up @@ -5716,6 +5741,124 @@ Program::Circuit serde::Deserializable<Program::Circuit>::deserialize(Deserializ
return obj;
}

namespace Program {

inline bool operator==(const ConstantOrWitnessEnum &lhs, const ConstantOrWitnessEnum &rhs) {
if (!(lhs.value == rhs.value)) { return false; }
return true;
}

inline std::vector<uint8_t> ConstantOrWitnessEnum::bincodeSerialize() const {
auto serializer = serde::BincodeSerializer();
serde::Serializable<ConstantOrWitnessEnum>::serialize(*this, serializer);
return std::move(serializer).bytes();
}

inline ConstantOrWitnessEnum ConstantOrWitnessEnum::bincodeDeserialize(std::vector<uint8_t> input) {
auto deserializer = serde::BincodeDeserializer(input);
auto value = serde::Deserializable<ConstantOrWitnessEnum>::deserialize(deserializer);
if (deserializer.get_buffer_offset() < input.size()) {
throw serde::deserialization_error("Some input bytes were not read");
}
return value;
}

} // end of namespace Program

template <>
template <typename Serializer>
void serde::Serializable<Program::ConstantOrWitnessEnum>::serialize(const Program::ConstantOrWitnessEnum &obj, Serializer &serializer) {
serializer.increase_container_depth();
serde::Serializable<decltype(obj.value)>::serialize(obj.value, serializer);
serializer.decrease_container_depth();
}

template <>
template <typename Deserializer>
Program::ConstantOrWitnessEnum serde::Deserializable<Program::ConstantOrWitnessEnum>::deserialize(Deserializer &deserializer) {
deserializer.increase_container_depth();
Program::ConstantOrWitnessEnum obj;
obj.value = serde::Deserializable<decltype(obj.value)>::deserialize(deserializer);
deserializer.decrease_container_depth();
return obj;
}

namespace Program {

inline bool operator==(const ConstantOrWitnessEnum::Constant &lhs, const ConstantOrWitnessEnum::Constant &rhs) {
if (!(lhs.value == rhs.value)) { return false; }
return true;
}

inline std::vector<uint8_t> ConstantOrWitnessEnum::Constant::bincodeSerialize() const {
auto serializer = serde::BincodeSerializer();
serde::Serializable<ConstantOrWitnessEnum::Constant>::serialize(*this, serializer);
return std::move(serializer).bytes();
}

inline ConstantOrWitnessEnum::Constant ConstantOrWitnessEnum::Constant::bincodeDeserialize(std::vector<uint8_t> input) {
auto deserializer = serde::BincodeDeserializer(input);
auto value = serde::Deserializable<ConstantOrWitnessEnum::Constant>::deserialize(deserializer);
if (deserializer.get_buffer_offset() < input.size()) {
throw serde::deserialization_error("Some input bytes were not read");
}
return value;
}

} // end of namespace Program

template <>
template <typename Serializer>
void serde::Serializable<Program::ConstantOrWitnessEnum::Constant>::serialize(const Program::ConstantOrWitnessEnum::Constant &obj, Serializer &serializer) {
serde::Serializable<decltype(obj.value)>::serialize(obj.value, serializer);
}

template <>
template <typename Deserializer>
Program::ConstantOrWitnessEnum::Constant serde::Deserializable<Program::ConstantOrWitnessEnum::Constant>::deserialize(Deserializer &deserializer) {
Program::ConstantOrWitnessEnum::Constant obj;
obj.value = serde::Deserializable<decltype(obj.value)>::deserialize(deserializer);
return obj;
}

namespace Program {

inline bool operator==(const ConstantOrWitnessEnum::Witness &lhs, const ConstantOrWitnessEnum::Witness &rhs) {
if (!(lhs.value == rhs.value)) { return false; }
return true;
}

inline std::vector<uint8_t> ConstantOrWitnessEnum::Witness::bincodeSerialize() const {
auto serializer = serde::BincodeSerializer();
serde::Serializable<ConstantOrWitnessEnum::Witness>::serialize(*this, serializer);
return std::move(serializer).bytes();
}

inline ConstantOrWitnessEnum::Witness ConstantOrWitnessEnum::Witness::bincodeDeserialize(std::vector<uint8_t> input) {
auto deserializer = serde::BincodeDeserializer(input);
auto value = serde::Deserializable<ConstantOrWitnessEnum::Witness>::deserialize(deserializer);
if (deserializer.get_buffer_offset() < input.size()) {
throw serde::deserialization_error("Some input bytes were not read");
}
return value;
}

} // end of namespace Program

template <>
template <typename Serializer>
void serde::Serializable<Program::ConstantOrWitnessEnum::Witness>::serialize(const Program::ConstantOrWitnessEnum::Witness &obj, Serializer &serializer) {
serde::Serializable<decltype(obj.value)>::serialize(obj.value, serializer);
}

template <>
template <typename Deserializer>
Program::ConstantOrWitnessEnum::Witness serde::Deserializable<Program::ConstantOrWitnessEnum::Witness>::deserialize(Deserializer &deserializer) {
Program::ConstantOrWitnessEnum::Witness obj;
obj.value = serde::Deserializable<decltype(obj.value)>::deserialize(deserializer);
return obj;
}

namespace Program {

inline bool operator==(const Directive &lhs, const Directive &rhs) {
Expand Down Expand Up @@ -6086,7 +6229,7 @@ Program::ExpressionWidth::Bounded serde::Deserializable<Program::ExpressionWidth
namespace Program {

inline bool operator==(const FunctionInput &lhs, const FunctionInput &rhs) {
if (!(lhs.witness == rhs.witness)) { return false; }
if (!(lhs.input == rhs.input)) { return false; }
if (!(lhs.num_bits == rhs.num_bits)) { return false; }
return true;
}
Expand All @@ -6112,7 +6255,7 @@ template <>
template <typename Serializer>
void serde::Serializable<Program::FunctionInput>::serialize(const Program::FunctionInput &obj, Serializer &serializer) {
serializer.increase_container_depth();
serde::Serializable<decltype(obj.witness)>::serialize(obj.witness, serializer);
serde::Serializable<decltype(obj.input)>::serialize(obj.input, serializer);
serde::Serializable<decltype(obj.num_bits)>::serialize(obj.num_bits, serializer);
serializer.decrease_container_depth();
}
Expand All @@ -6122,7 +6265,7 @@ template <typename Deserializer>
Program::FunctionInput serde::Deserializable<Program::FunctionInput>::deserialize(Deserializer &deserializer) {
deserializer.increase_container_depth();
Program::FunctionInput obj;
obj.witness = serde::Deserializable<decltype(obj.witness)>::deserialize(deserializer);
obj.input = serde::Deserializable<decltype(obj.input)>::deserialize(deserializer);
obj.num_bits = serde::Deserializable<decltype(obj.num_bits)>::deserialize(deserializer);
deserializer.decrease_container_depth();
return obj;
Expand Down
27 changes: 11 additions & 16 deletions acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,34 +372,29 @@ mod tests {

fn and_opcode<F: AcirField>() -> Opcode<F> {
Opcode::BlackBoxFuncCall(BlackBoxFuncCall::AND {
lhs: FunctionInput { witness: Witness(1), num_bits: 4 },
rhs: FunctionInput { witness: Witness(2), num_bits: 4 },
lhs: FunctionInput::witness(Witness(1), 4),
rhs: FunctionInput::witness(Witness(2), 4),
output: Witness(3),
})
}
fn range_opcode<F: AcirField>() -> Opcode<F> {
Opcode::BlackBoxFuncCall(BlackBoxFuncCall::RANGE {
input: FunctionInput { witness: Witness(1), num_bits: 8 },
input: FunctionInput::witness(Witness(1), 8),
})
}
fn keccakf1600_opcode<F: AcirField>() -> Opcode<F> {
let inputs: Box<[FunctionInput; 25]> = Box::new(std::array::from_fn(|i| FunctionInput {
witness: Witness(i as u32 + 1),
num_bits: 8,
}));
let inputs: Box<[FunctionInput<F>; 25]> =
Box::new(std::array::from_fn(|i| FunctionInput::witness(Witness(i as u32 + 1), 8)));
let outputs: Box<[Witness; 25]> = Box::new(std::array::from_fn(|i| Witness(i as u32 + 26)));

Opcode::BlackBoxFuncCall(BlackBoxFuncCall::Keccakf1600 { inputs, outputs })
}
fn schnorr_verify_opcode<F: AcirField>() -> Opcode<F> {
let public_key_x =
FunctionInput { witness: Witness(1), num_bits: FieldElement::max_num_bits() };
let public_key_y =
FunctionInput { witness: Witness(2), num_bits: FieldElement::max_num_bits() };
let signature: Box<[FunctionInput; 64]> = Box::new(std::array::from_fn(|i| {
FunctionInput { witness: Witness(i as u32 + 3), num_bits: 8 }
}));
let message: Vec<FunctionInput> = vec![FunctionInput { witness: Witness(67), num_bits: 8 }];
let public_key_x = FunctionInput::witness(Witness(1), FieldElement::max_num_bits());
let public_key_y = FunctionInput::witness(Witness(2), FieldElement::max_num_bits());
let signature: Box<[FunctionInput<F>; 64]> =
Box::new(std::array::from_fn(|i| FunctionInput::witness(Witness(i as u32 + 3), 8)));
let message: Vec<FunctionInput<F>> = vec![FunctionInput::witness(Witness(67), 8)];
let output = Witness(68);

Opcode::BlackBoxFuncCall(BlackBoxFuncCall::SchnorrVerify {
Expand All @@ -425,7 +420,7 @@ mod tests {
};
let program = Program { functions: vec![circuit], unconstrained_functions: Vec::new() };

fn read_write<F: Serialize + for<'a> Deserialize<'a>>(
fn read_write<F: Serialize + for<'a> Deserialize<'a> + AcirField>(
program: Program<F>,
) -> (Program<F>, Program<F>) {
let bytes = Program::serialize_program(&program);
Expand Down
4 changes: 2 additions & 2 deletions acvm-repo/acir/src/circuit/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
mod black_box_function_call;
mod memory_operation;

pub use black_box_function_call::{BlackBoxFuncCall, FunctionInput};
pub use black_box_function_call::{BlackBoxFuncCall, ConstantOrWitnessEnum, FunctionInput};
pub use memory_operation::{BlockId, MemOp};

#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -67,7 +67,7 @@ pub enum Opcode<F> {
///
/// Aztec's Barretenberg uses BN254 as the main curve and Grumpkin as the
/// embedded curve.
BlackBoxFuncCall(BlackBoxFuncCall),
BlackBoxFuncCall(BlackBoxFuncCall<F>),

/// This opcode is a specialization of a Brillig opcode. Instead of having
/// some generic assembly code like Brillig, a directive has a hardcoded
Expand Down
Loading

0 comments on commit 30854db

Please sign in to comment.