Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
transcript.hpp
Go to the documentation of this file.
1#ifdef STARKNET_GARAGA_FLAVORS
2#pragma once
3
6
7namespace bb::starknet {
8
9inline bb::fr starknet_hash_uint256(std::vector<bb::fr> const& data)
10{
11 using Poseidon = crypto::Poseidon<crypto::PoseidonStark252BaseFieldParams>;
12 using FF = Poseidon::FF;
13
14 size_t elem_count = data.size();
15 std::vector<FF> elems(2 * (1 + elem_count));
16
17 elems[0] = FF(std::string("0x0000000000000000000000000000000000000000537461726b6e6574486f6e6b")); // "StarknetHonk"
18 elems[1] = FF(0);
19
20 for (size_t k = 0; k < elem_count; ++k) {
21 std::vector<uint8_t> input = to_buffer(data[k]);
22
23 std::array<uint8_t, 32> limb_lo = {};
24 std::array<uint8_t, 32> limb_hi = {};
25
26 for (size_t i = 16; i < 32; ++i) {
27 limb_hi[i] = input[i - 16];
28 limb_lo[i] = input[i];
29 }
30
31 elems[2 * (1 + k)] = from_buffer<FF>(limb_lo);
32 elems[2 * (1 + k) + 1] = from_buffer<FF>(limb_hi);
33 }
34
35 FF iv = FF(1);
36
37 FF output = Poseidon::hash(elems, iv);
38
39 std::vector<uint8_t> result = to_buffer(output);
40
41 auto result_fr = from_buffer<bb::fr>(result);
42
43 return result_fr;
44}
45
46struct StarknetTranscriptParams : public bb::KeccakTranscriptParams {
47 static inline Fr hash(const std::vector<Fr>& data) { return starknet_hash_uint256(data); }
48};
49
50using StarknetTranscript = bb::BaseTranscript<StarknetTranscriptParams>;
51
52} // namespace bb::starknet
53#endif
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
const std::vector< FF > data
void hash(State &state) noexcept
typename Flavor::FF FF
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::vector< uint8_t > to_buffer(T const &value)