Skip to content

Commit

Permalink
feat: Sync from noir (AztecProtocol/aztec-packages#5794)
Browse files Browse the repository at this point in the history
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore: fix alerts on rust msrv
(#4817)
chore(ci): fix alerts on msrv issues
(#4816)
chore: run clippy (#4810)
chore: optimize poseidon2 implementation
(#4807)
fix: catch panics from EC point creation (e.g. the point is at infinity)
(#4790)
feat: Sync from aztec-packages
(#4792)
feat: lalrpop lexer prototype
(#4656)
feat(nargo): Handle call stacks for multiple Acir calls
(#4711)
fix: proper field inversion for bigints
(#4802)
feat: add `NARGO_FOREIGN_CALL_TIMEOUT` environment variable
(#4780)
chore(debugger): Docs (#4145)
feat: narrow ABI encoding errors down to target problem argument/field
(#4798)
chore: Rename 'global' to 'function' in the monomorphization pass
(#4774)
chore: Add Hir -> Ast conversion
(#4788)
fix: Fix panic when returning a zeroed unit value
(#4797)
END_COMMIT_OVERRIDE

---------

Co-authored-by: vezenovm <mvezenov@gmail.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 17, 2024
1 parent 5b352d6 commit 3d39823
Show file tree
Hide file tree
Showing 88 changed files with 2,617 additions and 1,628 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1dfbe7bc3bf3c455d8fb6c8b5fe6a96c1edf7af9
84c930a912ca9ed0d9c0ce2436309a4e9a840bcb
6 changes: 5 additions & 1 deletion .github/workflows/test-rust-workspace-msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ jobs:
# We treat any cancelled, skipped or failing jobs as a failure for the workflow as a whole.
FAIL: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }}

- name: Checkout
if: ${{ failure() }}
uses: actions/checkout@v4

# Raise an issue if the tests failed
- name: Alert on failed publish
uses: JasonEtco/create-an-issue@v2
Expand All @@ -122,4 +126,4 @@ jobs:
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
update_existing: true
filename: .github/JS_PUBLISH_FAILED.md
filename: .github/ACVM_NOT_PUBLISHABLE.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ examples/**/target/
examples/9
node_modules
pkg/
.idea

# Yarn
.pnp.*
Expand Down
15 changes: 14 additions & 1 deletion 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>,
}
Loading

0 comments on commit 3d39823

Please sign in to comment.