Skip to content

Commit

Permalink
chore!: Remove Directive::Quotient (#4019)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Jan 15, 2024
1 parent e28a6bf commit 824d76f
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 353 deletions.
139 changes: 1 addition & 138 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,28 +813,8 @@ struct Brillig {
static Brillig bincodeDeserialize(std::vector<uint8_t>);
};

struct QuotientDirective {
Circuit::Expression a;
Circuit::Expression b;
Circuit::Witness q;
Circuit::Witness r;
std::optional<Circuit::Expression> predicate;

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

struct Directive {

struct Quotient {
Circuit::QuotientDirective value;

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

struct ToLeRadix {
Circuit::Expression a;
std::vector<Circuit::Witness> b;
Expand All @@ -856,7 +836,7 @@ struct Directive {
static PermutationSort bincodeDeserialize(std::vector<uint8_t>);
};

std::variant<Quotient, ToLeRadix, PermutationSort> value;
std::variant<ToLeRadix, PermutationSort> value;

friend bool operator==(const Directive&, const Directive&);
std::vector<uint8_t> bincodeSerialize() const;
Expand Down Expand Up @@ -5038,53 +5018,6 @@ Circuit::Directive serde::Deserializable<Circuit::Directive>::deserialize(Deseri

namespace Circuit {

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

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

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

} // end of namespace Circuit

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

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

namespace Circuit {

inline bool operator==(const Directive::ToLeRadix& lhs, const Directive::ToLeRadix& rhs)
{
if (!(lhs.a == rhs.a)) {
Expand Down Expand Up @@ -6022,76 +5955,6 @@ Circuit::PublicInputs serde::Deserializable<Circuit::PublicInputs>::deserialize(

namespace Circuit {

inline bool operator==(const QuotientDirective& lhs, const QuotientDirective& rhs)
{
if (!(lhs.a == rhs.a)) {
return false;
}
if (!(lhs.b == rhs.b)) {
return false;
}
if (!(lhs.q == rhs.q)) {
return false;
}
if (!(lhs.r == rhs.r)) {
return false;
}
if (!(lhs.predicate == rhs.predicate)) {
return false;
}
return true;
}

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

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

} // end of namespace Circuit

template <>
template <typename Serializer>
void serde::Serializable<Circuit::QuotientDirective>::serialize(const Circuit::QuotientDirective& obj,
Serializer& serializer)
{
serializer.increase_container_depth();
serde::Serializable<decltype(obj.a)>::serialize(obj.a, serializer);
serde::Serializable<decltype(obj.b)>::serialize(obj.b, serializer);
serde::Serializable<decltype(obj.q)>::serialize(obj.q, serializer);
serde::Serializable<decltype(obj.r)>::serialize(obj.r, serializer);
serde::Serializable<decltype(obj.predicate)>::serialize(obj.predicate, serializer);
serializer.decrease_container_depth();
}

template <>
template <typename Deserializer>
Circuit::QuotientDirective serde::Deserializable<Circuit::QuotientDirective>::deserialize(Deserializer& deserializer)
{
deserializer.increase_container_depth();
Circuit::QuotientDirective obj;
obj.a = serde::Deserializable<decltype(obj.a)>::deserialize(deserializer);
obj.b = serde::Deserializable<decltype(obj.b)>::deserialize(deserializer);
obj.q = serde::Deserializable<decltype(obj.q)>::deserialize(deserializer);
obj.r = serde::Deserializable<decltype(obj.r)>::deserialize(deserializer);
obj.predicate = serde::Deserializable<decltype(obj.predicate)>::deserialize(deserializer);
deserializer.decrease_container_depth();
return obj;
}

namespace Circuit {

inline bool operator==(const RegisterIndex& lhs, const RegisterIndex& rhs)
{
if (!(lhs.value == rhs.value)) {
Expand Down
1 change: 0 additions & 1 deletion noir/Cargo.lock

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

114 changes: 1 addition & 113 deletions noir/acvm-repo/acir/codegen/acir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,28 +765,8 @@ namespace Circuit {
static Brillig bincodeDeserialize(std::vector<uint8_t>);
};

struct QuotientDirective {
Circuit::Expression a;
Circuit::Expression b;
Circuit::Witness q;
Circuit::Witness r;
std::optional<Circuit::Expression> predicate;

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

struct Directive {

struct Quotient {
Circuit::QuotientDirective value;

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

struct ToLeRadix {
Circuit::Expression a;
std::vector<Circuit::Witness> b;
Expand All @@ -808,7 +788,7 @@ namespace Circuit {
static PermutationSort bincodeDeserialize(std::vector<uint8_t>);
};

std::variant<Quotient, ToLeRadix, PermutationSort> value;
std::variant<ToLeRadix, PermutationSort> value;

friend bool operator==(const Directive&, const Directive&);
std::vector<uint8_t> bincodeSerialize() const;
Expand Down Expand Up @@ -4188,44 +4168,6 @@ Circuit::Directive serde::Deserializable<Circuit::Directive>::deserialize(Deseri
return obj;
}

namespace Circuit {

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

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

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

} // end of namespace Circuit

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

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

namespace Circuit {

inline bool operator==(const Directive::ToLeRadix &lhs, const Directive::ToLeRadix &rhs) {
Expand Down Expand Up @@ -4990,60 +4932,6 @@ Circuit::PublicInputs serde::Deserializable<Circuit::PublicInputs>::deserialize(
return obj;
}

namespace Circuit {

inline bool operator==(const QuotientDirective &lhs, const QuotientDirective &rhs) {
if (!(lhs.a == rhs.a)) { return false; }
if (!(lhs.b == rhs.b)) { return false; }
if (!(lhs.q == rhs.q)) { return false; }
if (!(lhs.r == rhs.r)) { return false; }
if (!(lhs.predicate == rhs.predicate)) { return false; }
return true;
}

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

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

} // end of namespace Circuit

template <>
template <typename Serializer>
void serde::Serializable<Circuit::QuotientDirective>::serialize(const Circuit::QuotientDirective &obj, Serializer &serializer) {
serializer.increase_container_depth();
serde::Serializable<decltype(obj.a)>::serialize(obj.a, serializer);
serde::Serializable<decltype(obj.b)>::serialize(obj.b, serializer);
serde::Serializable<decltype(obj.q)>::serialize(obj.q, serializer);
serde::Serializable<decltype(obj.r)>::serialize(obj.r, serializer);
serde::Serializable<decltype(obj.predicate)>::serialize(obj.predicate, serializer);
serializer.decrease_container_depth();
}

template <>
template <typename Deserializer>
Circuit::QuotientDirective serde::Deserializable<Circuit::QuotientDirective>::deserialize(Deserializer &deserializer) {
deserializer.increase_container_depth();
Circuit::QuotientDirective obj;
obj.a = serde::Deserializable<decltype(obj.a)>::deserialize(deserializer);
obj.b = serde::Deserializable<decltype(obj.b)>::deserialize(deserializer);
obj.q = serde::Deserializable<decltype(obj.q)>::deserialize(deserializer);
obj.r = serde::Deserializable<decltype(obj.r)>::deserialize(deserializer);
obj.predicate = serde::Deserializable<decltype(obj.predicate)>::deserialize(deserializer);
deserializer.decrease_container_depth();
return obj;
}

namespace Circuit {

inline bool operator==(const RegisterIndex &lhs, const RegisterIndex &rhs) {
Expand Down
12 changes: 0 additions & 12 deletions noir/acvm-repo/acir/src/circuit/directives.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
use crate::native_types::{Expression, Witness};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct QuotientDirective {
pub a: Expression,
pub b: Expression,
pub q: Witness,
pub r: Witness,
pub predicate: Option<Expression>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
/// Directives do not apply any constraints.
/// You can think of them as opcodes that allow one to use non-determinism
/// In the future, this can be replaced with asm non-determinism blocks
pub enum Directive {
//Performs euclidean division of a / b (as integers) and stores the quotient in q and the rest in r
Quotient(QuotientDirective),

//decomposition of a: a=\sum b[i]*radix^i where b is an array of witnesses < radix in little endian form
ToLeRadix {
a: Expression,
Expand Down
19 changes: 1 addition & 18 deletions noir/acvm-repo/acir/src/circuit/opcodes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use super::{
brillig::Brillig,
directives::{Directive, QuotientDirective},
};
use super::{brillig::Brillig, directives::Directive};
use crate::native_types::{Expression, Witness};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -48,21 +45,7 @@ impl std::fmt::Display for Opcode {

write!(f, " ]")
}
Opcode::Directive(Directive::Quotient(QuotientDirective { a, b, q, r, predicate })) => {
write!(f, "DIR::QUOTIENT ")?;
if let Some(pred) = predicate {
writeln!(f, "PREDICATE = {pred}")?;
}

write!(
f,
"(out : _{}, (_{}, {}), _{})",
a,
q.witness_index(),
b,
r.witness_index()
)
}
Opcode::BlackBoxFuncCall(g) => write!(f, "{g}"),
Opcode::Directive(Directive::ToLeRadix { a, b, radix: _ }) => {
write!(f, "DIR::TORADIX ")?;
Expand Down
1 change: 0 additions & 1 deletion noir/acvm-repo/acvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ repository.workspace = true

[dependencies]
num-bigint.workspace = true
num-traits.workspace = true
thiserror.workspace = true
tracing.workspace = true

Expand Down
4 changes: 0 additions & 4 deletions noir/acvm-repo/acvm/src/compiler/transformers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ pub(super) fn transform_internal(
}
Opcode::Directive(ref directive) => {
match directive {
Directive::Quotient(quotient_directive) => {
transformer.mark_solvable(quotient_directive.q);
transformer.mark_solvable(quotient_directive.r);
}
Directive::ToLeRadix { b, .. } => {
for witness in b {
transformer.mark_solvable(*witness);
Expand Down
Loading

0 comments on commit 824d76f

Please sign in to comment.