Skip to content

Commit

Permalink
updated to use span instead of vector
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasxia01 committed Jan 12, 2024
1 parent 6f02598 commit e4ef148
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ namespace crypto {
* @brief Hashes a vector of field elements
*/
template <typename Params>
typename Poseidon2<Params>::FF Poseidon2<Params>::hash(const std::vector<typename Poseidon2<Params>::FF>& input)
typename Poseidon2<Params>::FF Poseidon2<Params>::hash(const std::span<typename Poseidon2<Params>::FF>& input)
{
auto input_span = input;
return Sponge::hash_fixed_length(input_span);
return Sponge::hash_fixed_length(input);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ template <typename Params> class Poseidon2 {
/**
* @brief Hashes a vector of field elements
*/
static FF hash(const std::vector<FF>& input);
static FF hash(const std::span<FF>& 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ using namespace proof_system;
/**
* @brief Hash a vector of field_ct.
*/
template <typename C> field_t<C> poseidon2<C>::hash(C& builder, const std::vector<field_ct>& inputs)
template <typename C> field_t<C> poseidon2<C>::hash(C& builder, const std::span<field_ct>& 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ template <typename Builder> class poseidon2 {
using Sponge = FieldSponge<Params::t - 1, 1, Params::t, Permutation, Builder>;

public:
static field_ct hash(Builder& builder, const std::vector<field_ct>& in);
static field_ct hash(Builder& builder, const std::span<field_ct>& in);
static field_ct hash_buffer(Builder& builder, const stdlib::byte_array<Builder>& input);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ template <typename Builder> 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<fr_ct> inputs = { left, right };
left = poseidon2::hash(builder, inputs);
}

builder.set_public_input(left.witness_index);
Expand Down

0 comments on commit e4ef148

Please sign in to comment.