Barretenberg
The ZK-SNARK library at the core of Aztec
|
Enumerations | |
enum | blake_constant { BLAKE_STATE_SIZE = 16 } |
Functions | |
template<typename Builder > | |
field_t< Builder > | add_normalize (const field_t< Builder > &a, const field_t< Builder > &b) |
template<typename Builder > | |
void | g (field_t< Builder > state[BLAKE_STATE_SIZE], size_t a, size_t b, size_t c, size_t d, field_t< Builder > x, field_t< Builder > y, const bool last_update=false) |
template<typename Builder > | |
void | round_fn (field_t< Builder > state[BLAKE_STATE_SIZE], field_t< Builder > msg[BLAKE_STATE_SIZE], size_t round, const bool which_blake=false) |
Variables | |
constexpr uint8_t | MSG_SCHEDULE_BLAKE3 [7][16] |
constexpr uint8_t | MSG_SCHEDULE_BLAKE2 [10][16] |
Enumerator | |
---|---|
BLAKE_STATE_SIZE |
Definition at line 16 of file blake_util.hpp.
field_t< Builder > bb::stdlib::blake_util::add_normalize | ( | const field_t< Builder > & | a, |
const field_t< Builder > & | b | ||
) |
Addition with normalisation (to ensure the addition is in the scalar field.) Given two field_t elements a and b, this function computes ((a + b) % 2^{32}). Additionally, it checks if the overflow of the addition is a maximum of 3 bits. This is to ascertain that the additions of two 32-bit scalars in blake2s and blake3s do not exceed 35 bits.
Definition at line 39 of file blake_util.hpp.
void bb::stdlib::blake_util::g | ( | field_t< Builder > | state[BLAKE_STATE_SIZE], |
size_t | a, | ||
size_t | b, | ||
size_t | c, | ||
size_t | d, | ||
field_t< Builder > | x, | ||
field_t< Builder > | y, | ||
const bool | last_update = false |
||
) |
Function ‘G’ in the Blake2s and Blake3s algorithm which is the core mixing step with additions, xors and right-rotates. This function is used in Ultra version (with lookup tables).
Inputs: - A pointer to a 16-word state
,
last_update
to make sure addition is normalised only in last update of the stateGate costs per call to function G in lookup case:
Read sequence from table = 6 gates per read => 6 * 4 = 24 Addition gates = 4 gates Range gates = 2 gates Addition gate for correct output of XOR rotate 12 = 1 gate Normalizing scaling factors = 2 gates
Subtotal = 33 gates Outside rounds, each of Blake2s and Blake3s needs 20 and 24 lookup reads respectively.
+--------—+-----------—+--------------------—+------------------------—+-----------—+
calls to G | gate count for rounds | gate count outside rounds | total | |
---|---|---|---|---|
Blake2s | 80 | 80 * 33 | 20 * 6 | 2760 |
Blake3s | 56 | 56 * 33 | 24 * 6 | 1992 |
+--------—+-----------—+--------------------—+------------------------—+-----------—+
P.S. This doesn't include some more addition gates required after the rounds. This cost would be negligible as compared to the above gate counts.
TODO: Idea for getting rid of extra addition and multiplication gates by tweaking gate structure. To be implemented later.
q_plookup = 1 | d0 | a0 | d'0 | – | q_plookup = 1 | d1 | a1 | d'1 | d2 | <— set q_arith = 1 and validate d2 - d'5 * scale_factor = 0 q_plookup = 1 | d2 | a2 | d'2 | d'5 | q_plookup = 1 | d3 | a3 | d'3 | – | q_plookup = 1 | d4 | a4 | d'4 | – | q_plookup = 1 | d5 | a5 | d'5 | c | <-— set q_arith = 1 and validate d'5 * scale_factor + c - c2 = 0. | | c2 | <-— this row is start of another lookup table (b ^ c)
Definition at line 113 of file blake_util.hpp.
void bb::stdlib::blake_util::round_fn | ( | field_t< Builder > | state[BLAKE_STATE_SIZE], |
field_t< Builder > | msg[BLAKE_STATE_SIZE], | ||
size_t | round, | ||
const bool | which_blake = false |
||
) |
Definition at line 176 of file blake_util.hpp.
|
constexpr |
Definition at line 25 of file blake_util.hpp.
|
constexpr |
Definition at line 18 of file blake_util.hpp.