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 39 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
Original file line number Diff line number Diff line change
@@ -1 +1 @@
barretenberg_module(crypto_poseidon2 ecc numeric)
barretenberg_module(crypto_poseidon2 ecc)
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ template <typename Params> class Poseidon2Permutation {
auto t5 = t0 + t0;
t5 += t5;
t5 += t2; // 4A + 6B + C + D
auto t6 = t3 + t5; // 5A + 7B + 3C + D
auto t7 = t2 + t4; // A + 3B + 5D + 7C
auto t6 = t3 + t5; // 5A + 7B + C + 3D
auto t7 = t2 + t4; // A + 3B + 5C + 7D
input[0] = t6;
input[1] = t5;
input[2] = t7;
Expand Down
178 changes: 104 additions & 74 deletions barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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 @@ -35,10 +37,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 = 18;

Expand All @@ -53,7 +55,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 LogDerivLookupRelation = proof_system::DatabusLookupRelation<FF>;

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

DEFINE_POINTER_VIEW(NUM_PRECOMPUTED_ENTITIES,
&q_m,
Expand All @@ -127,6 +133,8 @@ class GoblinUltra {
&q_aux,
&q_lookup,
&q_busread,
&q_poseidon2_external,
&q_poseidon2_internal,
&sigma_1,
&sigma_2,
&sigma_3,
Expand All @@ -148,7 +156,20 @@ class GoblinUltra {

std::vector<HandleType> get_selectors() override
{
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 };
};
std::vector<HandleType> get_sigma_polynomials() override { return { sigma_1, sigma_2, sigma_3, sigma_4 }; };
std::vector<HandleType> get_id_polynomials() override { return { id_1, id_2, id_3, id_4 }; };
Expand Down Expand Up @@ -235,48 +256,49 @@ class GoblinUltra {
DataType q_aux; // column 9
DataType q_lookup; // column 10
DataType q_busread; // column 11
DataType sigma_1; // column 12
DataType sigma_2; // column 13
DataType sigma_3; // column 14
DataType sigma_4; // column 15
DataType id_1; // column 16
DataType id_2; // column 17
DataType id_3; // column 18
DataType id_4; // column 19
DataType table_1; // column 20
DataType table_2; // column 21
DataType table_3; // column 22
DataType table_4; // column 23
DataType lagrange_first; // column 24
DataType lagrange_last; // column 25
DataType lagrange_ecc_op; // column 26
DataType databus_id; // column 27
DataType w_l; // column 28
DataType w_r; // column 29
DataType w_o; // column 30
DataType w_4; // column 31
DataType sorted_accum; // column 32
DataType z_perm; // column 33
DataType z_lookup; // column 34
DataType ecc_op_wire_1; // column 35
DataType ecc_op_wire_2; // column 36
DataType ecc_op_wire_3; // column 37
DataType ecc_op_wire_4; // column 38
DataType calldata; // column 39
DataType calldata_read_counts; // column 40
DataType lookup_inverses; // column 41
DataType table_1_shift; // column 42
DataType table_2_shift; // column 43
DataType table_3_shift; // column 44
DataType table_4_shift; // column 45
DataType w_l_shift; // column 46
DataType w_r_shift; // column 47
DataType w_o_shift; // column 48
DataType w_4_shift; // column 49
DataType sorted_accum_shift; // column 50
DataType z_perm_shift; // column 51
DataType z_lookup_shift; // column 52

DataType q_poseidon2_external; // column 12
DataType q_poseidon2_internal; // column 13
DataType sigma_1; // column 14
DataType sigma_2; // column 15
DataType sigma_3; // column 16
DataType sigma_4; // column 17
DataType id_1; // column 18
DataType id_2; // column 19
DataType id_3; // column 20
DataType id_4; // column 21
DataType table_1; // column 22
DataType table_2; // column 23
DataType table_3; // column 24
DataType table_4; // column 25
DataType lagrange_first; // column 26
DataType lagrange_last; // column 27
DataType lagrange_ecc_op; // column 28
DataType databus_id; // column 29
DataType w_l; // column 30
DataType w_r; // column 31
DataType w_o; // column 32
DataType w_4; // column 33
DataType sorted_accum; // column 34
DataType z_perm; // column 35
DataType z_lookup; // column 36
DataType ecc_op_wire_1; // column 37
DataType ecc_op_wire_2; // column 38
DataType ecc_op_wire_3; // column 39
DataType ecc_op_wire_4; // column 40
DataType calldata; // column 41
DataType calldata_read_counts; // column 42
DataType lookup_inverses; // column 43
DataType table_1_shift; // column 44
DataType table_2_shift; // column 45
DataType table_3_shift; // column 46
DataType table_4_shift; // column 47
DataType w_l_shift; // column 48
DataType w_r_shift; // column 49
DataType w_o_shift; // column 50
DataType w_4_shift; // column 51
DataType sorted_accum_shift; // column 52
DataType z_perm_shift; // column 53
DataType z_lookup_shift; // column 54
// defines a method pointer_view that returns the following, with const and non-const variants
DEFINE_POINTER_VIEW(NUM_ALL_ENTITIES,
&q_c,
Expand All @@ -291,6 +313,8 @@ class GoblinUltra {
&q_aux,
&q_lookup,
&q_busread,
&q_poseidon2_external,
&q_poseidon2_internal,
&sigma_1,
&sigma_2,
&sigma_3,
Expand Down Expand Up @@ -353,6 +377,8 @@ class GoblinUltra {
q_aux,
q_lookup,
q_busread,
q_poseidon2_external,
q_poseidon2_internal,
sigma_1,
sigma_2,
sigma_3,
Expand Down Expand Up @@ -520,6 +546,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 @@ -556,6 +584,8 @@ class GoblinUltra {
q_aux = verification_key->q_aux;
q_lookup = verification_key->q_lookup;
q_busread = verification_key->q_busread;
q_poseidon2_external = verification_key->q_poseidon2_external;
q_poseidon2_internal = verification_key->q_poseidon2_internal;
sigma_1 = verification_key->sigma_1;
sigma_2 = verification_key->sigma_2;
sigma_3 = verification_key->sigma_3;
Expand Down
Loading