Skip to content

Commit

Permalink
feat: Sync from aztec-packages (#5467)
Browse files Browse the repository at this point in the history
Automated pull of Noir development from
[aztec-packages](https://github.com/AztecProtocol/aztec-packages).
BEGIN_COMMIT_OVERRIDE
feat: Sync from noir
(AztecProtocol/aztec-packages#7400)
refactor: replace usage of `GrumpkinPrivateKey` with
`EmbeddedCurveScalar`
(AztecProtocol/aztec-packages#7384)
refactor: replace usage of `GrumpkinPoint` with `EmbeddedCurvePoint`
(AztecProtocol/aztec-packages#7382)
feat: Sync from noir
(AztecProtocol/aztec-packages#7392)
feat!: constant inputs for blackbox
(AztecProtocol/aztec-packages#7222)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: Tom French <tom@tomfren.ch>
  • Loading branch information
3 people authored Jul 10, 2024
1 parent 41d2ac8 commit fb97bb9
Show file tree
Hide file tree
Showing 30 changed files with 505 additions and 287 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c7b1ae40593c24530723f344111459a51ad5f0e5
e44ef7042c87d3c78a14413ad7d54e4ed642ad89
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 fb97bb9

Please sign in to comment.