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: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#include "c_bind.hpp"
10#include "poseidon2.hpp"
12
13using namespace bb;
14
16{
17 std::vector<fr> to_hash;
18 read(inputs_buffer, to_hash);
20 fr::serialize_to_buffer(r, output);
21}
22
24{
25 std::vector<fr> to_hash;
26 read(inputs_buffer, to_hash);
27 const size_t numHashes = to_hash.size() / 2;
28 std::vector<fr> results;
29 size_t count = 0;
30 while (count < numHashes) {
32 { to_hash[count * 2], to_hash[count * 2 + 1] });
33 results.push_back(r);
34 ++count;
35 }
36 write(output, results);
37}
38
40{
42
43 // Serialise input vector.
44 std::vector<fr> to_permute;
45 read(inputs_buffer, to_permute);
46
47 // Copy input vector into Permutation::State (which is an std::array).
48 Permutation::State input_state;
49 std::copy(to_permute.begin(), to_permute.end(), input_state.data());
50
51 Permutation::State results_array = Permutation::permutation(input_state);
52
53 const std::vector<fr> results(results_array.begin(), results_array.end());
54 *output = to_heap_buffer(results);
55}
56
58{
59 std::vector<fr> to_hash;
60 read(inputs_buffer, to_hash);
61 const size_t numHashes = to_hash.size();
62 fr result = to_hash[0];
63 size_t count = 1;
64 while (count < numHashes) {
66 ++count;
67 }
68 write(output, result);
69}
Applies the Poseidon2 permutation function 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_hashes(fr::vec_in_buf inputs_buffer, fr::out_buf output)
Definition c_bind.cpp:23
WASM_EXPORT void poseidon2_hash_accumulate(fr::vec_in_buf inputs_buffer, fr::out_buf output)
Definition c_bind.cpp:57
WASM_EXPORT void poseidon2_hash(fr::vec_in_buf inputs_buffer, fr::out_buf output)
Definition c_bind.cpp:15
WASM_EXPORT void poseidon2_permutation(fr::vec_in_buf inputs_buffer, fr::vec_out_buf output)
Definition c_bind.cpp:39
Entry point for Barretenberg command-line interface.
void read(B &it, field2< base_field, Params > &value)
void write(B &buf, field2< base_field, Params > const &value)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
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