Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new Poseidon2 circuit builder gates #3346

Merged
merged 43 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e1c732d
initial commit
zac-williamson Oct 27, 2023
ea12f99
mmmmm constexpr
zac-williamson Oct 27, 2023
95e6572
wip
zac-williamson Oct 27, 2023
8c30828
basic poseidon hash working
zac-williamson Oct 27, 2023
86cf018
added tests + comments
zac-williamson Oct 30, 2023
6dd2511
comments
zac-williamson Oct 30, 2023
3dbd8df
removed string_view constructors
zac-williamson Oct 30, 2023
3631294
poseidon2 parameters now consistent with definition in paper
zac-williamson Oct 31, 2023
910b303
fixed bug where constructing uint from a string that is too big!
zac-williamson Oct 31, 2023
c7b4157
added cast to fix build error
lucasxia01 Nov 7, 2023
7bcee20
benchmarking file for native impl
lucasxia01 Nov 7, 2023
752bd14
Merge branch 'master' into zw/poseidon2
lucasxia01 Nov 7, 2023
7d0fe79
Merge branch 'master' into zw/poseidon2
lucasxia01 Nov 20, 2023
672ab67
external poseidon2 round relation
lucasxia01 Nov 20, 2023
60eca16
added ARC and SBox rounds to external
lucasxia01 Nov 20, 2023
d53bace
created internal round relation
lucasxia01 Nov 20, 2023
d7367f2
added poseidon2 selectors to goblin_ultra flavor
lucasxia01 Nov 21, 2023
6249c2e
adding selector
lucasxia01 Nov 21, 2023
8d2b731
forgotten updates
lucasxia01 Nov 21, 2023
20a7eb2
Merge branch 'master' into zw/poseidon2
lucasxia01 Nov 22, 2023
f09ed91
external poseidon2 round relation
lucasxia01 Nov 20, 2023
d679581
added ARC and SBox rounds to external
lucasxia01 Nov 20, 2023
35ab7d9
created internal round relation
lucasxia01 Nov 20, 2023
5e94698
naming update
lucasxia01 Nov 22, 2023
14157c1
external relation consistency test
lucasxia01 Nov 22, 2023
e04037e
internal round consistency test
lucasxia01 Nov 22, 2023
6da3335
initial manual relation tests
lucasxia01 Nov 22, 2023
0c961b1
variable renaming
lucasxia01 Nov 24, 2023
8ef04db
added manual tests for internal
lucasxia01 Nov 24, 2023
464dfd2
Merge branch 'lx/poseidon2-relations' into lx/poseidon2-circuit
lucasxia01 Nov 24, 2023
b2a7a7b
added mock gates to prevent zero selector polys
lucasxia01 Nov 27, 2023
b144cce
Merge branch 'master' into lx/poseidon2-relations
lucasxia01 Nov 28, 2023
be9d63c
added new gates to goblin ultra builder
lucasxia01 Nov 28, 2023
80958c5
updated based on review
lucasxia01 Nov 30, 2023
a3c8eed
naming update
lucasxia01 Nov 30, 2023
fba3631
Merge branch 'lx/poseidon2-relations' into lx/poseidon2-circuit
lucasxia01 Nov 30, 2023
aa818df
add poseidon checks to goblin check_circuit
lucasxia01 Nov 30, 2023
53abcc6
base case test for goblin ultra check circuit
lucasxia01 Nov 30, 2023
b24c737
typo fix
lucasxia01 Nov 30, 2023
478e429
Merge branch 'master' into lx/poseidon2-circuit
lucasxia01 Dec 1, 2023
8669e7d
Merge branch 'master' into lx/poseidon2-circuit
lucasxia01 Dec 4, 2023
3f7484b
Merge branch 'master' into lx/poseidon2-circuit
lucasxia01 Dec 4, 2023
a6d59c5
compile error fix
lucasxia01 Dec 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 58 additions & 32 deletions barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "barretenberg/relations/gen_perm_sort_relation.hpp"
#include "barretenberg/relations/lookup_relation.hpp"
#include "barretenberg/relations/permutation_relation.hpp"
#include "barretenberg/relations/poseidon2_external_relation.hpp"
#include "barretenberg/relations/poseidon2_internal_relation.hpp"
#include "barretenberg/relations/relation_parameters.hpp"
#include "barretenberg/relations/ultra_arithmetic_relation.hpp"
#include "barretenberg/transcript/transcript.hpp"
Expand All @@ -37,10 +39,10 @@ class GoblinUltra {
// The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often
// need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`.
// Note: this number does not include the individual sorted list polynomials.
static constexpr size_t NUM_ALL_ENTITIES = 53;
static constexpr size_t NUM_ALL_ENTITIES = 55;
// The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying
// assignment of witnesses. We again choose a neutral name.
static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 28;
static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 30;
// The total number of witness entities not including shifts.
static constexpr size_t NUM_WITNESS_ENTITIES = 14;

Expand All @@ -57,7 +59,9 @@ class GoblinUltra {
proof_system::EllipticRelation<FF>,
proof_system::AuxiliaryRelation<FF>,
proof_system::EccOpQueueRelation<FF>,
proof_system::DatabusLookupRelation<FF>>;
proof_system::DatabusLookupRelation<FF>,
proof_system::Poseidon2ExternalRelation<FF>,
proof_system::Poseidon2InternalRelation<FF>>;
using Relations = Relations_<FF>;

using LogDerivLookupRelation = proof_system::DatabusLookupRelation<FF>;
Expand Down Expand Up @@ -90,40 +94,56 @@ class GoblinUltra {
public:
using DataType = DataType_;
DEFINE_FLAVOR_MEMBERS(DataType,
q_m, // column 0
q_c, // column 1
q_l, // column 2
q_r, // column 3
q_o, // column 4
q_4, // column 5
q_arith, // column 6
q_sort, // column 7
q_elliptic, // column 8
q_aux, // column 9
q_lookup, // column 10
q_busread, // column 11
sigma_1, // column 12
sigma_2, // column 13
sigma_3, // column 14
sigma_4, // column 15
id_1, // column 16
id_2, // column 17
id_3, // column 18
id_4, // column 19
table_1, // column 20
table_2, // column 21
table_3, // column 22
table_4, // column 23
lagrange_first, // column 24
lagrange_last, // column 25
lagrange_ecc_op, // column 26 // indicator poly for ecc op gates
databus_id) // column 27 // id polynomial, i.e. id_i = i
q_m, // column 0
q_c, // column 1
q_l, // column 2
q_r, // column 3
q_o, // column 4
q_4, // column 5
q_arith, // column 6
q_sort, // column 7
q_elliptic, // column 8
q_aux, // column 9
q_lookup, // column 10
q_busread, // column 11
q_poseidon2_external, // column 12
q_poseidon2_internal, // column 13
sigma_1, // column 14
sigma_2, // column 15
sigma_3, // column 16
sigma_4, // column 17
id_1, // column 18
id_2, // column 19
id_3, // column 20
id_4, // column 21
table_1, // column 22
table_2, // column 23
table_3, // column 24
table_4, // column 25
lagrange_first, // column 26
lagrange_last, // column 27
lagrange_ecc_op, // column 28 // indicator poly for ecc op gates
databus_id // column 29 // id polynomial, i.e. id_i = i
)

static constexpr CircuitType CIRCUIT_TYPE = CircuitBuilder::CIRCUIT_TYPE;

RefVector<DataType> get_selectors()
{
return { q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_sort, q_elliptic, q_aux, q_lookup, q_busread };
return { q_m,
q_c,
q_l,
q_r,
q_o,
q_4,
q_arith,
q_sort,
q_elliptic,
q_aux,
q_lookup,
q_busread,
q_poseidon2_external,
q_poseidon2_internal };
};
RefVector<DataType> get_sigma_polynomials() { return { sigma_1, sigma_2, sigma_3, sigma_4 }; };
RefVector<DataType> get_id_polynomials() { return { id_1, id_2, id_3, id_4 }; };
Expand Down Expand Up @@ -237,6 +257,8 @@ class GoblinUltra {
this->q_aux,
this->q_lookup,
this->q_busread,
this->q_poseidon2_external,
this->q_poseidon2_internal,
this->sigma_1,
this->sigma_2,
this->sigma_3,
Expand Down Expand Up @@ -402,6 +424,8 @@ class GoblinUltra {
q_aux = "__Q_AUX";
q_lookup = "__Q_LOOKUP";
q_busread = "__Q_BUSREAD";
q_poseidon2_external = "__Q_POSEIDON2_EXTERNAL";
q_poseidon2_internal = "__Q_POSEIDON2_INTERNAL";
sigma_1 = "__SIGMA_1";
sigma_2 = "__SIGMA_2";
sigma_3 = "__SIGMA_3";
Expand Down Expand Up @@ -440,6 +464,8 @@ class GoblinUltra {
this->q_aux = verification_key->q_aux;
this->q_lookup = verification_key->q_lookup;
this->q_busread = verification_key->q_busread;
this->q_poseidon2_external = verification_key->q_poseidon2_external;
this->q_poseidon2_internal = verification_key->q_poseidon2_internal;
this->sigma_1 = verification_key->sigma_1;
this->sigma_2 = verification_key->sigma_2;
this->sigma_3 = verification_key->sigma_3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/polynomials/univariate.hpp"
#include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp"
#include "barretenberg/relations/auxiliary_relation.hpp"
#include "barretenberg/relations/ecc_op_queue_relation.hpp"
#include "barretenberg/relations/elliptic_relation.hpp"
#include "barretenberg/relations/gen_perm_sort_relation.hpp"
#include "barretenberg/relations/lookup_relation.hpp"
#include "barretenberg/relations/permutation_relation.hpp"
#include "barretenberg/relations/ultra_arithmetic_relation.hpp"
#include "barretenberg/srs/factories/crs_factory.hpp"
#include "barretenberg/transcript/transcript.hpp"
#include <array>
#include <concepts>
#include <span>
Expand Down Expand Up @@ -130,6 +122,8 @@ template <typename BuilderType> class GoblinUltraRecursive_ {
this->q_aux = Commitment::from_witness(builder, native_key->q_aux);
this->q_lookup = Commitment::from_witness(builder, native_key->q_lookup);
this->q_busread = Commitment::from_witness(builder, native_key->q_busread);
this->q_poseidon2_external = Commitment::from_witness(builder, native_key->q_poseidon2_external);
this->q_poseidon2_internal = Commitment::from_witness(builder, native_key->q_poseidon2_internal);
this->sigma_1 = Commitment::from_witness(builder, native_key->sigma_1);
this->sigma_2 = Commitment::from_witness(builder, native_key->sigma_2);
this->sigma_3 = Commitment::from_witness(builder, native_key->sigma_3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ template <typename FF_> class Ultra {
template <typename FF_> class UltraHonk {
public:
static constexpr size_t NUM_WIRES = 4;
static constexpr size_t NUM_SELECTORS = 12;
static constexpr size_t NUM_SELECTORS = 14;
using FF = FF_;
using SelectorType = std::vector<FF, barretenberg::ContainerSlabAllocator<FF>>;

Expand All @@ -138,6 +138,8 @@ template <typename FF_> class UltraHonk {
SelectorType& q_aux() { return selectors[9]; };
SelectorType& q_lookup_type() { return selectors[10]; };
SelectorType& q_busread() { return this->selectors[11]; };
SelectorType& q_poseidon2_external() { return this->selectors[12]; };
SelectorType& q_poseidon2_internal() { return this->selectors[13]; };

const auto& get() const { return selectors; };

Expand All @@ -154,7 +156,12 @@ template <typename FF_> class UltraHonk {
* Ultra arithmetization
*
*/
void pad_additional() { q_busread().emplace_back(0); };
void pad_additional()
{
q_busread().emplace_back(0);
q_poseidon2_external().emplace_back(0);
q_poseidon2_internal().emplace_back(0);
};

// Note: Unused. Needed only for consistency with Ultra arith (which is used by Plonk)
inline static const std::vector<std::string> selector_names = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,20 @@ template <typename FF> struct ecc_dbl_gate_ {
uint32_t x3;
uint32_t y3;
};

template <typename FF> struct poseidon2_external_gate_ {
uint32_t a;
uint32_t b;
uint32_t c;
uint32_t d;
uint32_t round_idx;
};

template <typename FF> struct poseidon2_internal_gate_ {
uint32_t a;
uint32_t b;
uint32_t c;
uint32_t d;
uint32_t round_idx;
};
} // namespace proof_system
Loading