Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
c_bind.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Sergei], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#include "c_bind.hpp"
8
12#include "poseidon2.hpp"
13#include <algorithm>
14
15using namespace bb;
16
18{
19 std::vector<fr> to_hash;
20 read(inputs_buffer, to_hash);
22 fr::serialize_to_buffer(r, output);
23}
24
26{
28
29 // Serialise input vector.
30 std::vector<fr> to_permute;
31 read(inputs_buffer, to_permute);
32
33 // Permutation requires exactly t=4 input elements
34 BB_ASSERT(to_permute.size() == Permutation::t, "poseidon2_permutation input must have exactly 4 elements");
35
36 // Copy input vector into Permutation::State (which is an std::array).
37 Permutation::State input_state;
38 std::ranges::copy(to_permute, input_state.data());
39
40 Permutation::State results_array = Permutation::permutation(input_state);
41
42 const std::vector<fr> results(results_array.begin(), results_array.end());
43 *output = to_heap_buffer(results);
44}
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
Applies the Poseidon2 permutation function from https://eprint.iacr.org/2023/323.
Circuit form of Poseidon2 permutation from https://eprint.iacr.org/2023/323.
std::array< field_t< Builder >, t > State
static State permutation(Builder *builder, const State &input)
Circuit form of Poseidon2 permutation from https://eprint.iacr.org/2023/323.
WASM_EXPORT void poseidon2_hash(fr::vec_in_buf inputs_buffer, fr::out_buf output)
Definition c_bind.cpp:17
WASM_EXPORT void poseidon2_permutation(fr::vec_in_buf inputs_buffer, fr::vec_out_buf output)
Definition c_bind.cpp:25
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
void read(B &it, field2< base_field, Params > &value)
uint8_t * to_heap_buffer(T const &value)
uint8_t ** vec_out_buf
static void serialize_to_buffer(const field &value, uint8_t *buffer)
const uint8_t * vec_in_buf
#define WASM_EXPORT