Skip to content

Commit

Permalink
feat: Sync from aztec-packages (#4833)
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#5814)
feat: Sync from noir
(AztecProtocol/aztec-packages#5794)
feat!: contract interfaces and better function calls
(AztecProtocol/aztec-packages#5687)
fix: Don't reuse brillig with slice arguments
(AztecProtocol/aztec-packages#5800)
chore: Use BrilligCall for unconstrained main and update AVM transpiler
(AztecProtocol/aztec-packages#5797)
feat: Brillig pointer codegen and execution
(AztecProtocol/aztec-packages#5737)
feat!: change backend width to 4
(AztecProtocol/aztec-packages#5374)
feat!: Use fixed size arrays in black box functions where sizes are
known (AztecProtocol/aztec-packages#5620)
feat!: trap with revert data
(AztecProtocol/aztec-packages#5732)
feat: impl of missing functionality in new key store
(AztecProtocol/aztec-packages#5750)
feat(acir)!: BrilligCall opcode
(AztecProtocol/aztec-packages#5709)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <tom@tomfren.ch>
Co-authored-by: Maxim Vezenov <mvezenov@gmail.com>
  • Loading branch information
3 people committed Apr 17, 2024
1 parent 6cefe16 commit 0f9ae0a
Show file tree
Hide file tree
Showing 81 changed files with 2,068 additions and 667 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1dfbe7bc3bf3c455d8fb6c8b5fe6a96c1edf7af9
beab8c93857536e07fa37994213fc664a5864013
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions acvm-repo/acir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ thiserror.workspace = true
flate2.workspace = true
bincode.workspace = true
base64.workspace = true
serde-big-array = "0.5.1"

[dev-dependencies]
serde_json = "1.0"
Expand Down
159 changes: 140 additions & 19 deletions acvm-repo/acir/codegen/acir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace Program {

struct SHA256 {
std::vector<Program::FunctionInput> inputs;
std::vector<Program::Witness> outputs;
std::array<Program::Witness, 32> outputs;

friend bool operator==(const SHA256&, const SHA256&);
std::vector<uint8_t> bincodeSerialize() const;
Expand All @@ -63,7 +63,7 @@ namespace Program {

struct Blake2s {
std::vector<Program::FunctionInput> inputs;
std::vector<Program::Witness> outputs;
std::array<Program::Witness, 32> outputs;

friend bool operator==(const Blake2s&, const Blake2s&);
std::vector<uint8_t> bincodeSerialize() const;
Expand All @@ -72,7 +72,7 @@ namespace Program {

struct Blake3 {
std::vector<Program::FunctionInput> inputs;
std::vector<Program::Witness> outputs;
std::array<Program::Witness, 32> outputs;

friend bool operator==(const Blake3&, const Blake3&);
std::vector<uint8_t> bincodeSerialize() const;
Expand All @@ -82,7 +82,7 @@ namespace Program {
struct SchnorrVerify {
Program::FunctionInput public_key_x;
Program::FunctionInput public_key_y;
std::vector<Program::FunctionInput> signature;
std::array<Program::FunctionInput, 64> signature;
std::vector<Program::FunctionInput> message;
Program::Witness output;

Expand Down Expand Up @@ -112,10 +112,10 @@ namespace Program {
};

struct EcdsaSecp256k1 {
std::vector<Program::FunctionInput> public_key_x;
std::vector<Program::FunctionInput> public_key_y;
std::vector<Program::FunctionInput> signature;
std::vector<Program::FunctionInput> hashed_message;
std::array<Program::FunctionInput, 32> public_key_x;
std::array<Program::FunctionInput, 32> public_key_y;
std::array<Program::FunctionInput, 64> signature;
std::array<Program::FunctionInput, 32> hashed_message;
Program::Witness output;

friend bool operator==(const EcdsaSecp256k1&, const EcdsaSecp256k1&);
Expand All @@ -124,10 +124,10 @@ namespace Program {
};

struct EcdsaSecp256r1 {
std::vector<Program::FunctionInput> public_key_x;
std::vector<Program::FunctionInput> public_key_y;
std::vector<Program::FunctionInput> signature;
std::vector<Program::FunctionInput> hashed_message;
std::array<Program::FunctionInput, 32> public_key_x;
std::array<Program::FunctionInput, 32> public_key_y;
std::array<Program::FunctionInput, 64> signature;
std::array<Program::FunctionInput, 32> hashed_message;
Program::Witness output;

friend bool operator==(const EcdsaSecp256r1&, const EcdsaSecp256r1&);
Expand Down Expand Up @@ -160,16 +160,16 @@ namespace Program {
struct Keccak256 {
std::vector<Program::FunctionInput> inputs;
Program::FunctionInput var_message_size;
std::vector<Program::Witness> outputs;
std::array<Program::Witness, 32> outputs;

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

struct Keccakf1600 {
std::vector<Program::FunctionInput> inputs;
std::vector<Program::Witness> outputs;
std::array<Program::FunctionInput, 25> inputs;
std::array<Program::Witness, 25> outputs;

friend bool operator==(const Keccakf1600&, const Keccakf1600&);
std::vector<uint8_t> bincodeSerialize() const;
Expand Down Expand Up @@ -257,9 +257,9 @@ namespace Program {
};

struct Sha256Compression {
std::vector<Program::FunctionInput> inputs;
std::vector<Program::FunctionInput> hash_values;
std::vector<Program::Witness> outputs;
std::array<Program::FunctionInput, 16> inputs;
std::array<Program::FunctionInput, 8> hash_values;
std::array<Program::Witness, 8> outputs;

friend bool operator==(const Sha256Compression&, const Sha256Compression&);
std::vector<uint8_t> bincodeSerialize() const;
Expand Down Expand Up @@ -922,6 +922,9 @@ namespace Program {
};

struct Trap {
uint64_t revert_data_offset;
uint64_t revert_data_size;

friend bool operator==(const Trap&, const Trap&);
std::vector<uint8_t> bincodeSerialize() const;
static Trap bincodeDeserialize(std::vector<uint8_t>);
Expand Down Expand Up @@ -1061,6 +1064,17 @@ namespace Program {
static MemoryInit bincodeDeserialize(std::vector<uint8_t>);
};

struct BrilligCall {
uint32_t id;
std::vector<Program::BrilligInputs> inputs;
std::vector<Program::BrilligOutputs> outputs;
std::optional<Program::Expression> predicate;

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

struct Call {
uint32_t id;
std::vector<Program::Witness> inputs;
Expand All @@ -1072,7 +1086,7 @@ namespace Program {
static Call bincodeDeserialize(std::vector<uint8_t>);
};

std::variant<AssertZero, BlackBoxFuncCall, Directive, Brillig, MemoryOp, MemoryInit, Call> value;
std::variant<AssertZero, BlackBoxFuncCall, Directive, Brillig, MemoryOp, MemoryInit, BrilligCall, Call> value;

friend bool operator==(const Opcode&, const Opcode&);
std::vector<uint8_t> bincodeSerialize() const;
Expand Down Expand Up @@ -1151,8 +1165,17 @@ namespace Program {
static Circuit bincodeDeserialize(std::vector<uint8_t>);
};

struct BrilligBytecode {
std::vector<Program::BrilligOpcode> bytecode;

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

struct Program {
std::vector<Program::Circuit> functions;
std::vector<Program::BrilligBytecode> unconstrained_functions;

friend bool operator==(const Program&, const Program&);
std::vector<uint8_t> bincodeSerialize() const;
Expand Down Expand Up @@ -4071,6 +4094,48 @@ Program::Brillig serde::Deserializable<Program::Brillig>::deserialize(Deserializ
return obj;
}

namespace Program {

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

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

inline BrilligBytecode BrilligBytecode::bincodeDeserialize(std::vector<uint8_t> input) {
auto deserializer = serde::BincodeDeserializer(input);
auto value = serde::Deserializable<BrilligBytecode>::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::BrilligBytecode>::serialize(const Program::BrilligBytecode &obj, Serializer &serializer) {
serializer.increase_container_depth();
serde::Serializable<decltype(obj.bytecode)>::serialize(obj.bytecode, serializer);
serializer.decrease_container_depth();
}

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

namespace Program {

inline bool operator==(const BrilligInputs &lhs, const BrilligInputs &rhs) {
Expand Down Expand Up @@ -4952,6 +5017,8 @@ Program::BrilligOpcode::BlackBox serde::Deserializable<Program::BrilligOpcode::B
namespace Program {

inline bool operator==(const BrilligOpcode::Trap &lhs, const BrilligOpcode::Trap &rhs) {
if (!(lhs.revert_data_offset == rhs.revert_data_offset)) { return false; }
if (!(lhs.revert_data_size == rhs.revert_data_size)) { return false; }
return true;
}

Expand All @@ -4975,12 +5042,16 @@ namespace Program {
template <>
template <typename Serializer>
void serde::Serializable<Program::BrilligOpcode::Trap>::serialize(const Program::BrilligOpcode::Trap &obj, Serializer &serializer) {
serde::Serializable<decltype(obj.revert_data_offset)>::serialize(obj.revert_data_offset, serializer);
serde::Serializable<decltype(obj.revert_data_size)>::serialize(obj.revert_data_size, serializer);
}

template <>
template <typename Deserializer>
Program::BrilligOpcode::Trap serde::Deserializable<Program::BrilligOpcode::Trap>::deserialize(Deserializer &deserializer) {
Program::BrilligOpcode::Trap obj;
obj.revert_data_offset = serde::Deserializable<decltype(obj.revert_data_offset)>::deserialize(deserializer);
obj.revert_data_size = serde::Deserializable<decltype(obj.revert_data_size)>::deserialize(deserializer);
return obj;
}

Expand Down Expand Up @@ -6118,6 +6189,53 @@ Program::Opcode::MemoryInit serde::Deserializable<Program::Opcode::MemoryInit>::
return obj;
}

namespace Program {

inline bool operator==(const Opcode::BrilligCall &lhs, const Opcode::BrilligCall &rhs) {
if (!(lhs.id == rhs.id)) { return false; }
if (!(lhs.inputs == rhs.inputs)) { return false; }
if (!(lhs.outputs == rhs.outputs)) { return false; }
if (!(lhs.predicate == rhs.predicate)) { return false; }
return true;
}

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

inline Opcode::BrilligCall Opcode::BrilligCall::bincodeDeserialize(std::vector<uint8_t> input) {
auto deserializer = serde::BincodeDeserializer(input);
auto value = serde::Deserializable<Opcode::BrilligCall>::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::Opcode::BrilligCall>::serialize(const Program::Opcode::BrilligCall &obj, Serializer &serializer) {
serde::Serializable<decltype(obj.id)>::serialize(obj.id, serializer);
serde::Serializable<decltype(obj.inputs)>::serialize(obj.inputs, serializer);
serde::Serializable<decltype(obj.outputs)>::serialize(obj.outputs, serializer);
serde::Serializable<decltype(obj.predicate)>::serialize(obj.predicate, serializer);
}

template <>
template <typename Deserializer>
Program::Opcode::BrilligCall serde::Deserializable<Program::Opcode::BrilligCall>::deserialize(Deserializer &deserializer) {
Program::Opcode::BrilligCall obj;
obj.id = serde::Deserializable<decltype(obj.id)>::deserialize(deserializer);
obj.inputs = serde::Deserializable<decltype(obj.inputs)>::deserialize(deserializer);
obj.outputs = serde::Deserializable<decltype(obj.outputs)>::deserialize(deserializer);
obj.predicate = serde::Deserializable<decltype(obj.predicate)>::deserialize(deserializer);
return obj;
}

namespace Program {

inline bool operator==(const Opcode::Call &lhs, const Opcode::Call &rhs) {
Expand Down Expand Up @@ -6290,6 +6408,7 @@ namespace Program {

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

Expand All @@ -6315,6 +6434,7 @@ template <typename Serializer>
void serde::Serializable<Program::Program>::serialize(const Program::Program &obj, Serializer &serializer) {
serializer.increase_container_depth();
serde::Serializable<decltype(obj.functions)>::serialize(obj.functions, serializer);
serde::Serializable<decltype(obj.unconstrained_functions)>::serialize(obj.unconstrained_functions, serializer);
serializer.decrease_container_depth();
}

Expand All @@ -6324,6 +6444,7 @@ Program::Program serde::Deserializable<Program::Program>::deserialize(Deserializ
deserializer.increase_container_depth();
Program::Program obj;
obj.functions = serde::Deserializable<decltype(obj.functions)>::deserialize(deserializer);
obj.unconstrained_functions = serde::Deserializable<decltype(obj.unconstrained_functions)>::deserialize(deserializer);
deserializer.decrease_container_depth();
return obj;
}
Expand Down
8 changes: 8 additions & 0 deletions acvm-repo/acir/src/circuit/brillig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ pub struct Brillig {
/// Predicate of the Brillig execution - indicates if it should be skipped
pub predicate: Option<Expression>,
}

/// This is purely a wrapper struct around a list of Brillig opcode's which represents
/// a full Brillig function to be executed by the Brillig VM.
/// This is stored separately on a program and accessed through a [BrilligPointer].
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct BrilligBytecode {
pub bytecode: Vec<BrilligOpcode>,
}

0 comments on commit 0f9ae0a

Please sign in to comment.