From 6f9119495bdbaf9c0ee006b3ad595bd77982d4cf Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Tue, 14 Feb 2023 20:50:22 +0000 Subject: [PATCH] Changes in stdlib necessary for aztec3. Handpicked changes necessary for aztec3. More handpicked changes and a fix. Fix. Port `copy_as_new_witness`. Port `must_imply`. `operator++`. Port changes from `common`. Co-authored-by: iAmMichaelConnor Minor pedersen fix. Port `ecc/groups`. Co-authored-by: Michael Connor Port remaining `stdlib` changes. Co-authored-by: Michael Connor Latest fixes. Co-authored-by: Michael Connor grumpkin conversion fix. Co-authored-by: Michael Connor --- cpp/src/aztec/common/container.hpp | 12 + cpp/src/aztec/common/map.hpp | 18 +- cpp/src/aztec/common/serialize.hpp | 28 +++ cpp/src/aztec/common/streams.hpp | 24 +- .../crypto/pedersen_commitment/pedersen.cpp | 26 +++ .../crypto/pedersen_commitment/pedersen.hpp | 6 +- .../pedersen_commitment/pedersen_lookup.cpp | 67 ++++++ .../pedersen_commitment/pedersen_lookup.hpp | 6 + .../pedersen_lookup.test.cpp | 64 ++++++ cpp/src/aztec/ecc/fields/field.hpp | 5 + cpp/src/aztec/ecc/fields/field_impl.hpp | 11 + cpp/src/aztec/ecc/groups/affine_element.hpp | 3 + .../aztec/ecc/groups/affine_element_impl.hpp | 15 ++ cpp/src/aztec/ecc/groups/element.hpp | 2 +- cpp/src/aztec/ecc/groups/element_impl.hpp | 10 + .../stdlib/commitment/pedersen/pedersen.cpp | 39 ++++ .../stdlib/commitment/pedersen/pedersen.hpp | 14 +- .../commitment/pedersen/pedersen_plookup.cpp | 85 +++++++ .../commitment/pedersen/pedersen_plookup.hpp | 8 +- .../pedersen/pedersen_plookup.test.cpp | 75 ++++++ .../stdlib/primitives/address/address.hpp | 140 ++++++++++++ .../stdlib/primitives/bigfield/bigfield.hpp | 6 +- .../primitives/bigfield/bigfield_impl.hpp | 32 +-- cpp/src/aztec/stdlib/primitives/bool/bool.cpp | 50 ++++ cpp/src/aztec/stdlib/primitives/bool/bool.hpp | 4 + .../aztec/stdlib/primitives/field/array.hpp | 153 +++++++++++++ .../aztec/stdlib/primitives/field/field.hpp | 29 ++- .../stdlib/primitives/field/field.test.cpp | 49 +++- .../aztec/stdlib/primitives/point/point.hpp | 15 ++ .../primitives/safe_uint/safe_uint.test.cpp | 3 +- .../stdlib/recursion/verifier/verifier.hpp | 11 + cpp/src/aztec/stdlib/types/circuit_types.hpp | 95 ++++++++ cpp/src/aztec/stdlib/types/convert.hpp | 215 ++++++++++++++++++ cpp/src/aztec/stdlib/types/native_types.hpp | 87 +++++++ 34 files changed, 1377 insertions(+), 30 deletions(-) create mode 100644 cpp/src/aztec/stdlib/primitives/address/address.hpp create mode 100644 cpp/src/aztec/stdlib/primitives/field/array.hpp create mode 100644 cpp/src/aztec/stdlib/types/circuit_types.hpp create mode 100644 cpp/src/aztec/stdlib/types/convert.hpp create mode 100644 cpp/src/aztec/stdlib/types/native_types.hpp diff --git a/cpp/src/aztec/common/container.hpp b/cpp/src/aztec/common/container.hpp index 6418be1461..1c87bb1224 100644 --- a/cpp/src/aztec/common/container.hpp +++ b/cpp/src/aztec/common/container.hpp @@ -48,4 +48,16 @@ InnerCont flatten(Cont const& in) result.insert(result.end(), e.begin(), e.end()); } return result; +} + +// Return the first index at which a given item can be found in the vector. +// Only safe for vectors with length less than the size_t overflow size. +template long index_of(std::vector const& vec, T const& item) +{ + auto const& begin = vec.begin(); + auto const& end = vec.end(); + + auto const& itr = std::find(begin, end, item); + + return itr == end ? -1 : std::distance(begin, itr); } \ No newline at end of file diff --git a/cpp/src/aztec/common/map.hpp b/cpp/src/aztec/common/map.hpp index a78c81ca62..79205f2bda 100644 --- a/cpp/src/aztec/common/map.hpp +++ b/cpp/src/aztec/common/map.hpp @@ -10,13 +10,29 @@ template