Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::stdlib::Poseidon2Permutation< Builder > Class Template Reference

Circuit form of Poseidon2 permutation from https://eprint.iacr.org/2023/323. More...

#include <poseidon2_permutation.hpp>

Public Types

using Params = crypto::Poseidon2Bn254ScalarFieldParams
 
using NativePermutation = crypto::Poseidon2Permutation< Params >
 
using FF = typename Params::FF
 
using State = std::array< field_t< Builder >, t >
 
using NativeState = std::array< FF, t >
 
using RoundConstants = std::array< FF, t >
 
using RoundConstantsContainer = std::array< RoundConstants, NUM_ROUNDS >
 

Static Public Member Functions

static State permutation (Builder *builder, const State &input)
 Circuit form of Poseidon2 permutation from https://eprint.iacr.org/2023/323.
 
static void matrix_multiplication_external (State &state)
 In-circuit method to efficiently multiply the initial state by the external matrix \( M_E \).
 
static void matrix_multiplication_external (State &state)
 
static void propagate_current_state_to_next_row (Builder *builder, const State &state, auto &block)
 The result of applying a round of Poseidon2 is stored in the next row and is accessed by Poseidon2 Internal and External Relations via the shifts mechanism. Note that it does not activate any selectors since it only serves to store the values. See Poseidon2ExternalRelationImpl and Poseidon2InternalRelationImpl docs.
 

Static Public Attributes

static constexpr size_t t = Params::t
 
static constexpr size_t rounds_f = Params::rounds_f
 
static constexpr size_t rounds_p = Params::rounds_p
 
static constexpr size_t NUM_ROUNDS = Params::rounds_f + Params::rounds_p
 
static constexpr RoundConstantsContainer round_constants = Params::round_constants
 

Detailed Description

template<typename Builder>
class bb::stdlib::Poseidon2Permutation< Builder >

Circuit form of Poseidon2 permutation from https://eprint.iacr.org/2023/323.

The permutation consists of one initial linear layer, then a set of external rounds, a set of internal rounds, and a set of external rounds.

Note that we compute the round results natively and record them into Poseidon2 custom gates. This allows us to heavily reduce the number of arithmetic gates that would have been otherwise required to perform expensive non-linear S-box operations in-circuit.

The external rounds are constrained via Poseidon2ExternalRelationImpl; Mega also uses Poseidon2InitialExternalRelationImpl for the initial external linear layer. Mega constrains the internal rounds via a K=4 compressed block (Poseidon2TransitionEntryRelationImpl, Poseidon2QuadInternalRelationImpl, and Poseidon2QuadInternalTerminalRelationImpl); Ultra uses Poseidon2InternalRelationImpl.

Definition at line 33 of file poseidon2_permutation.hpp.

Member Typedef Documentation

◆ FF

template<typename Builder >
using bb::stdlib::Poseidon2Permutation< Builder >::FF = typename Params::FF

Definition at line 48 of file poseidon2_permutation.hpp.

◆ NativePermutation

template<typename Builder >
using bb::stdlib::Poseidon2Permutation< Builder >::NativePermutation = crypto::Poseidon2Permutation<Params>

Definition at line 36 of file poseidon2_permutation.hpp.

◆ NativeState

template<typename Builder >
using bb::stdlib::Poseidon2Permutation< Builder >::NativeState = std::array<FF, t>

Definition at line 50 of file poseidon2_permutation.hpp.

◆ Params

◆ RoundConstants

template<typename Builder >
using bb::stdlib::Poseidon2Permutation< Builder >::RoundConstants = std::array<FF, t>

Definition at line 52 of file poseidon2_permutation.hpp.

◆ RoundConstantsContainer

template<typename Builder >
using bb::stdlib::Poseidon2Permutation< Builder >::RoundConstantsContainer = std::array<RoundConstants, NUM_ROUNDS>

Definition at line 53 of file poseidon2_permutation.hpp.

◆ State

template<typename Builder >
using bb::stdlib::Poseidon2Permutation< Builder >::State = std::array<field_t<Builder>, t>

Definition at line 49 of file poseidon2_permutation.hpp.

Member Function Documentation

◆ matrix_multiplication_external() [1/2]

template<typename Builder >
requires IsMegaBuilder<Builder>
void bb::stdlib::Poseidon2Permutation< Builder >::matrix_multiplication_external ( State state)
static

In-circuit method to efficiently multiply the initial state by the external matrix \( M_E \).

Separate function to do just the first linear layer (equivalent to external matrix mul).

Update the state with \( M_E \cdot (\text{state}[0], \text{state}[1], \text{state}[2], \text{state}[3])^{\top}\). Where \( M_E \) is the external round matrix. See Poseidon2ExternalRelationImpl.

Definition at line 226 of file poseidon2_permutation.cpp.

◆ matrix_multiplication_external() [2/2]

template<typename Builder >
static void bb::stdlib::Poseidon2Permutation< Builder >::matrix_multiplication_external ( State state)
static

◆ permutation()

template<typename Builder >
static State bb::stdlib::Poseidon2Permutation< Builder >::permutation ( Builder builder,
const State input 
)
static

Circuit form of Poseidon2 permutation from https://eprint.iacr.org/2023/323.

The permutation consists of one initial linear layer, then a set of external rounds, a set of internal rounds, and a set of external rounds.

Parameters
builder
input
Returns
State

◆ propagate_current_state_to_next_row()

template<typename Builder >
static void bb::stdlib::Poseidon2Permutation< Builder >::propagate_current_state_to_next_row ( Builder builder,
const State state,
auto &  block 
)
inlinestatic

The result of applying a round of Poseidon2 is stored in the next row and is accessed by Poseidon2 Internal and External Relations via the shifts mechanism. Note that it does not activate any selectors since it only serves to store the values. See Poseidon2ExternalRelationImpl and Poseidon2InternalRelationImpl docs.

Parameters
builder
statean array of t field_t elements
blockEither poseidon2_external or poseidon2_internal block of the Execution Trace

Definition at line 84 of file poseidon2_permutation.hpp.

Member Data Documentation

◆ NUM_ROUNDS

template<typename Builder >
constexpr size_t bb::stdlib::Poseidon2Permutation< Builder >::NUM_ROUNDS = Params::rounds_f + Params::rounds_p
staticconstexpr

Definition at line 46 of file poseidon2_permutation.hpp.

◆ round_constants

template<typename Builder >
constexpr RoundConstantsContainer bb::stdlib::Poseidon2Permutation< Builder >::round_constants = Params::round_constants
staticconstexpr

Definition at line 54 of file poseidon2_permutation.hpp.

◆ rounds_f

template<typename Builder >
constexpr size_t bb::stdlib::Poseidon2Permutation< Builder >::rounds_f = Params::rounds_f
staticconstexpr

Definition at line 43 of file poseidon2_permutation.hpp.

◆ rounds_p

template<typename Builder >
constexpr size_t bb::stdlib::Poseidon2Permutation< Builder >::rounds_p = Params::rounds_p
staticconstexpr

Definition at line 45 of file poseidon2_permutation.hpp.

◆ t

template<typename Builder >
constexpr size_t bb::stdlib::Poseidon2Permutation< Builder >::t = Params::t
staticconstexpr

Definition at line 41 of file poseidon2_permutation.hpp.


The documentation for this class was generated from the following files: