From e4ef148e26c700891ebe31e62a55ebaf8a8c4009 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Fri, 12 Jan 2024 21:10:57 +0000 Subject: [PATCH] updated to use span instead of vector --- .../cpp/src/barretenberg/crypto/poseidon2/poseidon2.cpp | 5 ++--- .../cpp/src/barretenberg/crypto/poseidon2/poseidon2.hpp | 2 +- .../cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.cpp | 5 ++--- .../cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.hpp | 2 +- .../barretenberg/stdlib/hash/poseidon2/poseidon2.test.cpp | 3 ++- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2.cpp b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2.cpp index ad96dc312713..65c6dc0f1684 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2.cpp @@ -5,10 +5,9 @@ namespace crypto { * @brief Hashes a vector of field elements */ template -typename Poseidon2::FF Poseidon2::hash(const std::vector::FF>& input) +typename Poseidon2::FF Poseidon2::hash(const std::span::FF>& input) { - auto input_span = input; - return Sponge::hash_fixed_length(input_span); + return Sponge::hash_fixed_length(input); } /** diff --git a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2.hpp b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2.hpp index 6969c680e177..6f86bb35e3fa 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/poseidon2/poseidon2.hpp @@ -16,7 +16,7 @@ template class Poseidon2 { /** * @brief Hashes a vector of field elements */ - static FF hash(const std::vector& input); + static FF hash(const std::span& input); /** * @brief Hashes vector of bytes by chunking it into 31 byte field elements and calling hash() * @details Slice function cuts out the required number of bytes from the byte vector diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.cpp index ff8e31dd56eb..167c6779c773 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.cpp @@ -8,15 +8,14 @@ using namespace proof_system; /** * @brief Hash a vector of field_ct. */ -template field_t poseidon2::hash(C& builder, const std::vector& inputs) +template field_t poseidon2::hash(C& builder, const std::span& inputs) { /* Run the sponge by absorbing all the input and squeezing one output. * This should just call the sponge variable length hash function * */ - auto input{ inputs }; - return Sponge::hash_fixed_length(builder, input); + return Sponge::hash_fixed_length(builder, inputs); } /** diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.hpp index fcfb93f91d26..521a33413bcb 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.hpp @@ -26,7 +26,7 @@ template class poseidon2 { using Sponge = FieldSponge; public: - static field_ct hash(Builder& builder, const std::vector& in); + static field_ct hash(Builder& builder, const std::span& in); static field_ct hash_buffer(Builder& builder, const stdlib::byte_array& input); }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.test.cpp index 797cec6669c1..f4dae1642e40 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/poseidon2/poseidon2.test.cpp @@ -68,7 +68,8 @@ template class StdlibPoseidon2 : public testing::Test { // num_inputs - 1 iterations since the first hash hashes two elements for (size_t i = 0; i < num_inputs - 1; ++i) { - left = poseidon2::hash(builder, { left, right }); + std::vector inputs = { left, right }; + left = poseidon2::hash(builder, inputs); } builder.set_public_input(left.witness_index);