Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace to_radix directive with brillig #9970

Merged
merged 6 commits into from
Nov 15, 2024
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
1 change: 0 additions & 1 deletion avm-transpiler/Cargo.lock

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

181 changes: 1 addition & 180 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,25 +1144,6 @@ struct BrilligOutputs {
static BrilligOutputs bincodeDeserialize(std::vector<uint8_t>);
};

struct Directive {

struct ToLeRadix {
Program::Expression a;
std::vector<Program::Witness> b;
uint32_t radix;

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

std::variant<ToLeRadix> value;

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

struct MemOp {
Program::Expression operation;
Program::Expression index;
Expand Down Expand Up @@ -1191,14 +1172,6 @@ struct Opcode {
static BlackBoxFuncCall bincodeDeserialize(std::vector<uint8_t>);
};

struct Directive {
Program::Directive value;

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

struct MemoryOp {
Program::BlockId block_id;
Program::MemOp op;
Expand Down Expand Up @@ -1241,7 +1214,7 @@ struct Opcode {
static Call bincodeDeserialize(std::vector<uint8_t>);
};

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

friend bool operator==(const Opcode&, const Opcode&);
std::vector<uint8_t> bincodeSerialize() const;
Expand Down Expand Up @@ -6812,112 +6785,6 @@ Program::ConstantOrWitnessEnum::Witness serde::Deserializable<Program::ConstantO

namespace Program {

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

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

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

} // end of namespace Program

template <>
template <typename Serializer>
void serde::Serializable<Program::Directive>::serialize(const Program::Directive& 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::Directive serde::Deserializable<Program::Directive>::deserialize(Deserializer& deserializer)
{
deserializer.increase_container_depth();
Program::Directive obj;
obj.value = serde::Deserializable<decltype(obj.value)>::deserialize(deserializer);
deserializer.decrease_container_depth();
return obj;
}

namespace Program {

inline bool operator==(const Directive::ToLeRadix& lhs, const Directive::ToLeRadix& rhs)
{
if (!(lhs.a == rhs.a)) {
return false;
}
if (!(lhs.b == rhs.b)) {
return false;
}
if (!(lhs.radix == rhs.radix)) {
return false;
}
return true;
}

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

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

} // end of namespace Program

template <>
template <typename Serializer>
void serde::Serializable<Program::Directive::ToLeRadix>::serialize(const Program::Directive::ToLeRadix& obj,
Serializer& serializer)
{
serde::Serializable<decltype(obj.a)>::serialize(obj.a, serializer);
serde::Serializable<decltype(obj.b)>::serialize(obj.b, serializer);
serde::Serializable<decltype(obj.radix)>::serialize(obj.radix, serializer);
}

template <>
template <typename Deserializer>
Program::Directive::ToLeRadix serde::Deserializable<Program::Directive::ToLeRadix>::deserialize(
Deserializer& deserializer)
{
Program::Directive::ToLeRadix obj;
obj.a = serde::Deserializable<decltype(obj.a)>::deserialize(deserializer);
obj.b = serde::Deserializable<decltype(obj.b)>::deserialize(deserializer);
obj.radix = serde::Deserializable<decltype(obj.radix)>::deserialize(deserializer);
return obj;
}

namespace Program {

inline bool operator==(const Expression& lhs, const Expression& rhs)
{
if (!(lhs.mul_terms == rhs.mul_terms)) {
Expand Down Expand Up @@ -8253,52 +8120,6 @@ Program::Opcode::BlackBoxFuncCall serde::Deserializable<Program::Opcode::BlackBo

namespace Program {

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

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

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

} // end of namespace Program

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

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

namespace Program {

inline bool operator==(const Opcode::MemoryOp& lhs, const Opcode::MemoryOp& rhs)
{
if (!(lhs.block_id == rhs.block_id)) {
Expand Down
14 changes: 2 additions & 12 deletions noir/noir-repo/acvm-repo/acir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ In summary, the workflow is the following:
1. user program -> (compilation) ACIR, a list of opcodes which constrain
(partial) witnesses
2. user inputs + ACIR -> (execution/solving) assign values to all the
(partial) witnesses
(partial) witnesses
3. witness assignment + ACIR -> (proving system) proof

Although the ordering of opcode does not matter in theory, since a system of
Expand Down Expand Up @@ -121,7 +121,7 @@ proving system and are only used by the solver.
Finally, some opcodes will have a predicate, whose value is `0` or `1`. Its
purpose is to nullify the opcode when the value is `0`, so that it has no
effect. Note that removing the opcode is not a solution because this modifies
the circuit (the circuit being mainly the list of the opcodes).
the circuit (the circuit being mainly the list of the opcodes).

*Remark*: Opcodes operate on witnesses, but we will see that some opcode work on
expressions of witnesses. We call an expression a linear combination of
Expand Down Expand Up @@ -265,16 +265,6 @@ without adding any constraint.
NOTE: see the [circuit/opcodes.rs](src/circuit/opcodes.rs) file for the most
up-to-date documentation on these opcodes.

#### Directive

This opcode is a specialization of Brillig opcode. Instead of having some generic
assembly code like Brillig, a directive has a hardcoded name which tells the
solver which computation to do: with Brillig, the computation refers to the
compiled bytecode of an unconstrained Noir function, but with a directive, the
computation is hardcoded inside the compiler.

Directives will be replaced by Brillig opcodes in the future.

#### MemoryOp: memory abstraction for ACIR

ACIR is able to address any array of witnesses. Each array is assigned an ID
Expand Down
Loading
Loading