Skip to content

Commit

Permalink
feat: allow brillig to read arrays directly from memory (#4460)
Browse files Browse the repository at this point in the history
This PR allows the `BrilligSolver` to read inputs directly from ACIR
memory. This allows us to remove constraints which are generated purely
to load values out of memory to pass into ACIR.

Resolves noir-lang/noir#4262
  • Loading branch information
TomAFrench authored and AztecBot committed Feb 7, 2024
1 parent 026918c commit a9a7f72
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,15 @@ struct BrilligInputs {
static Array bincodeDeserialize(std::vector<uint8_t>);
};

std::variant<Single, Array> value;
struct MemoryArray {
Circuit::BlockId value;

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

std::variant<Single, Array, MemoryArray> value;

friend bool operator==(const BrilligInputs&, const BrilligInputs&);
std::vector<uint8_t> bincodeSerialize() const;
Expand Down Expand Up @@ -4923,6 +4931,53 @@ Circuit::BrilligInputs::Array serde::Deserializable<Circuit::BrilligInputs::Arra

namespace Circuit {

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

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

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

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

namespace Circuit {

inline bool operator==(const BrilligOpcode& lhs, const BrilligOpcode& rhs)
{
if (!(lhs.value == rhs.value)) {
Expand Down

0 comments on commit a9a7f72

Please sign in to comment.