Skip to content

Commit f0e0db7

Browse files
authored
Merge pull request #518 from AztecProtocol/ir/05-20-feat_avm_optimised_version_of_new_poseidon2_perm
feat(avm)!: optimised poseidon2 permutation
2 parents 9039fa2 + ce692ca commit f0e0db7

22 files changed

Lines changed: 1170 additions & 2728 deletions

File tree

barretenberg/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ ts/src/cbind/generated/
2020
!cpp/src/barretenberg/flavor/generated/
2121
!cpp/src/barretenberg/vm2/generated/
2222
!cpp/src/barretenberg/honk/execution_trace/generated/
23+
!cpp/src/barretenberg/vm2/generated/

barretenberg/cpp/pil/vm2/poseidon2_params.pil

Lines changed: 16 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Values taken from barretenberg/crypto/poseidon2/poseidon2_params.hpp
2+
// More information can also be found at barretenberg/crypto/poseidon2/poseidon2_quad_params.hpp
23

34
// Note: These constants are solely used in poseidon2_perm.pil but the latter
45
// is not re-generated when we run `bb_pil`. We manually optimized the
@@ -18,6 +19,21 @@ namespace poseidon2_params;
1819
pol MU_2 = 148936322117705719734052984176402258788283488576388928671173547788498414613;
1920
pol MU_3 = 15456385653678559339152734484033356164266089951521103188900320352052358038155;
2021

22+
// Closed-form constants for the K_BRIDGE=56 partial-round chain in
23+
// poseidon2_perm.pil.
24+
//
25+
// Algebraic source: M_3 = diag(MU_1, MU_2, MU_3) + 1·1^T acts on the 3 linear
26+
// lanes of one Poseidon2 internal round. M3_ii is the diagonal entry on lane i;
27+
// off-diagonal entries are all 1 and inlined at use site.
28+
// M3_ii = MU_i + 1
29+
//
30+
// Soundness precondition: MU_1, MU_2, MU_3 must be pairwise distinct so the
31+
// linear-lane evolution is uniquely solvable. Holds on BN254 with the
32+
// parameters above.
33+
pol M3_11 = MU_1 + 1;
34+
pol M3_22 = MU_2 + 1;
35+
pol M3_33 = MU_3 + 1;
36+
2137
// Round constants
2238
// Naming scheme is c_{round_count}_{input_count} where the counts are zero-indexed
2339
// So the round constant applied in the 5th round to the 3rd input is c_4_2
@@ -44,284 +60,116 @@ namespace poseidon2_params;
4460
pol C_3_3 = 4573768376486344895797915946239137669624900197544620153250805961657870918727;
4561
// Round 5 constants
4662
pol C_4_0 = 5624865188680173294191042415227598609140934495743721047183803859030618890703;
47-
pol C_4_1 = 0;
48-
pol C_4_2 = 0;
49-
pol C_4_3 = 0;
5063
// Round 6 constants
5164
pol C_5_0 = 8228252753786907198149068514193371173033070694924002912950645971088002709521;
52-
pol C_5_1 = 0;
53-
pol C_5_2 = 0;
54-
pol C_5_3 = 0;
5565
// Round 7 constants
5666
pol C_6_0 = 17586714789554691446538331362711502394998837215506284064347036653995353304693;
57-
pol C_6_1 = 0;
58-
pol C_6_2 = 0;
59-
pol C_6_3 = 0;
6067
// Round 8 constants
6168
pol C_7_0 = 12985198716830497423350597750558817467658937953000235442251074063454897365701;
62-
pol C_7_1 = 0;
63-
pol C_7_2 = 0;
64-
pol C_7_3 = 0;
6569
// Round 9 constants
6670
pol C_8_0 = 13480076116139680784838493959937969792577589073830107110893279354229821035984;
67-
pol C_8_1 = 0;
68-
pol C_8_2 = 0;
69-
pol C_8_3 = 0;
7071
// Round 10 constants
7172
pol C_9_0 = 480609231761423388761863647137314056373740727639536352979673303078459561332;
72-
pol C_9_1 = 0;
73-
pol C_9_2 = 0;
74-
pol C_9_3 = 0;
7573
// Round 11 constants
7674
pol C_10_0 = 19503345496799249258956440299354839375920540225688429628121751361906635419276;
77-
pol C_10_1 = 0;
78-
pol C_10_2 = 0;
79-
pol C_10_3 = 0;
8075
// Round 12 constants
8176
pol C_11_0 = 16837818502122887883669221005435922946567532037624537243846974433811447595173;
82-
pol C_11_1 = 0;
83-
pol C_11_2 = 0;
84-
pol C_11_3 = 0;
8577
// Round 13 constants
8678
pol C_12_0 = 5492108497278641078569490709794391352213168666744080628008171695469579703581;
87-
pol C_12_1 = 0;
88-
pol C_12_2 = 0;
89-
pol C_12_3 = 0;
9079
// Round 14 constants
9180
pol C_13_0 = 11365311159988448419785032079155356000691294261495515880484003277443744617083;
92-
pol C_13_1 = 0;
93-
pol C_13_2 = 0;
94-
pol C_13_3 = 0;
9581
// Round 15 constants
9682
pol C_14_0 = 13876891705632851072613751905778242936713392247975808888614530203269491723653;
97-
pol C_14_1 = 0;
98-
pol C_14_2 = 0;
99-
pol C_14_3 = 0;
10083
// Round 16 constants
10184
pol C_15_0 = 10660388389107698747692475159023710744797290186015856503629656779989214850043;
102-
pol C_15_1 = 0;
103-
pol C_15_2 = 0;
104-
pol C_15_3 = 0;
10585
// Round 17 constants
10686
pol C_16_0 = 18876318870401623474401728758498150977988613254023317877612912724282285739292;
107-
pol C_16_1 = 0;
108-
pol C_16_2 = 0;
109-
pol C_16_3 = 0;
11087
// Round 18 constants
11188
pol C_17_0 = 15543349138237018307536452195922365893694804703361435879256942490123776892424;
112-
pol C_17_1 = 0;
113-
pol C_17_2 = 0;
114-
pol C_17_3 = 0;
11589
// Round 19 constants
11690
pol C_18_0 = 2839988449157209999638903652853828318645773519300826410959678570041742458201;
117-
pol C_18_1 = 0;
118-
pol C_18_2 = 0;
119-
pol C_18_3 = 0;
12091
// Round 20 constants
12192
pol C_19_0 = 7566039810305694135184226097163626060317478635973510706368412858136696413063;
122-
pol C_19_1 = 0;
123-
pol C_19_2 = 0;
124-
pol C_19_3 = 0;
12593
// Round 21 constants
12694
pol C_20_0 = 6344830340705033582410486810600848473125256338903726340728639711688240744220;
127-
pol C_20_1 = 0;
128-
pol C_20_2 = 0;
129-
pol C_20_3 = 0;
13095
// Round 22 constants
13196
pol C_21_0 = 12475357769019880256619207099578191648078162511547701737481203260317463892731;
132-
pol C_21_1 = 0;
133-
pol C_21_2 = 0;
134-
pol C_21_3 = 0;
13597
// Round 23 constants
13698
pol C_22_0 = 13337401254840718303633782478677852514218549070508887338718446132574012311307;
137-
pol C_22_1 = 0;
138-
pol C_22_2 = 0;
139-
pol C_22_3 = 0;
14099
// Round 24 constants
141100
pol C_23_0 = 21161869193849404954234950798647336336709035097706159414187214758702055364571;
142-
pol C_23_1 = 0;
143-
pol C_23_2 = 0;
144-
pol C_23_3 = 0;
145101
// Round 25 constants
146102
pol C_24_0 = 20671052961616073313397254362345395594858011165315285344464242404604146448678;
147-
pol C_24_1 = 0;
148-
pol C_24_2 = 0;
149-
pol C_24_3 = 0;
150103
// Round 26 constants
151104
pol C_25_0 = 2772189387845778213446441819361180378678387127454165972767013098872140927416;
152-
pol C_25_1 = 0;
153-
pol C_25_2 = 0;
154-
pol C_25_3 = 0;
155105
// Round 27 constants
156106
pol C_26_0 = 3339032002224218054945450150550795352855387702520990006196627537441898997147;
157-
pol C_26_1 = 0;
158-
pol C_26_2 = 0;
159-
pol C_26_3 = 0;
160107
// Round 28 constants
161108
pol C_27_0 = 14919705931281848425960108279746818433850049439186607267862213649460469542157;
162-
pol C_27_1 = 0;
163-
pol C_27_2 = 0;
164-
pol C_27_3 = 0;
165109
// Round 29 constants
166110
pol C_28_0 = 17056699976793486403099510941807022658662936611123286147276760381688934087770;
167-
pol C_28_1 = 0;
168-
pol C_28_2 = 0;
169-
pol C_28_3 = 0;
170111
// Round 30 constants
171112
pol C_29_0 = 16144580075268719403964467603213740327573316872987042261854346306108421013323;
172-
pol C_29_1 = 0;
173-
pol C_29_2 = 0;
174-
pol C_29_3 = 0;
175113
// Round 31 constants
176114
pol C_30_0 = 15582343953927413680541644067712456296539774919658221087452235772880573393376;
177-
pol C_30_1 = 0;
178-
pol C_30_2 = 0;
179-
pol C_30_3 = 0;
180115
// Round 32 constants
181116
pol C_31_0 = 17528510080741946423534916423363640132610906812668323263058626230135522155749;
182-
pol C_31_1 = 0;
183-
pol C_31_2 = 0;
184-
pol C_31_3 = 0;
185117
// Round 33 constants
186118
pol C_32_0 = 3190600034239022251529646836642735752388641846393941612827022280601486805721;
187-
pol C_32_1 = 0;
188-
pol C_32_2 = 0;
189-
pol C_32_3 = 0;
190119
// Round 34 constants
191120
pol C_33_0 = 8463814172152682468446984305780323150741498069701538916468821815030498611418;
192-
pol C_33_1 = 0;
193-
pol C_33_2 = 0;
194-
pol C_33_3 = 0;
195121
// Round 35 constants
196122
pol C_34_0 = 16533435971270903741871235576178437313873873358463959658178441562520661055273;
197-
pol C_34_1 = 0;
198-
pol C_34_2 = 0;
199-
pol C_34_3 = 0;
200123
// Round 36 constants
201124
pol C_35_0 = 11845696835505436397913764735273748291716405946246049903478361223369666046634;
202-
pol C_35_1 = 0;
203-
pol C_35_2 = 0;
204-
pol C_35_3 = 0;
205125
// Round 37 constants
206126
pol C_36_0 = 18391057370973634202531308463652130631065370546571735004701144829951670507215;
207-
pol C_36_1 = 0;
208-
pol C_36_2 = 0;
209-
pol C_36_3 = 0;
210127
// Round 38 constants
211128
pol C_37_0 = 262537877325812689820791215463881982531707709719292538608229687240243203710;
212-
pol C_37_1 = 0;
213-
pol C_37_2 = 0;
214-
pol C_37_3 = 0;
215129
// Round 39 constants
216130
pol C_38_0 = 2187234489894387585309965540987639130975753519805550941279098789852422770021;
217-
pol C_38_1 = 0;
218-
pol C_38_2 = 0;
219-
pol C_38_3 = 0;
220131
// Round 40 constants
221132
pol C_39_0 = 19189656350920455659006418422409390013967064310525314160026356916172976152967;
222-
pol C_39_1 = 0;
223-
pol C_39_2 = 0;
224-
pol C_39_3 = 0;
225133
// Round 41 constants
226134
pol C_40_0 = 15839474183930359560478122372067744245080413846070743460407578046890458719219;
227-
pol C_40_1 = 0;
228-
pol C_40_2 = 0;
229-
pol C_40_3 = 0;
230135
// Round 42 constants
231136
pol C_41_0 = 1805019124769763805045852541831585930225376844141668951787801647576910524592;
232-
pol C_41_1 = 0;
233-
pol C_41_2 = 0;
234-
pol C_41_3 = 0;
235137
// Round 43 constants
236138
pol C_42_0 = 323592203814803486950280155834638828455175703393817797003361354810251742052;
237-
pol C_42_1 = 0;
238-
pol C_42_2 = 0;
239-
pol C_42_3 = 0;
240139
// Round 44 constants
241140
pol C_43_0 = 9780393509796825017346015868945480913627956475147371732521398519483580624282;
242-
pol C_43_1 = 0;
243-
pol C_43_2 = 0;
244-
pol C_43_3 = 0;
245141
// Round 45 constants
246142
pol C_44_0 = 14009429785059642386335012561867511048847749030947687313594053997432177705759;
247-
pol C_44_1 = 0;
248-
pol C_44_2 = 0;
249-
pol C_44_3 = 0;
250143
// Round 46 constants
251144
pol C_45_0 = 13749550162460745037234826077137388777330401847577727796245150843898019635981;
252-
pol C_45_1 = 0;
253-
pol C_45_2 = 0;
254-
pol C_45_3 = 0;
255145
// Round 47 constants
256146
pol C_46_0 = 19497187499283431845443758879472819384797584633472792651343926414232528405311;
257-
pol C_46_1 = 0;
258-
pol C_46_2 = 0;
259-
pol C_46_3 = 0;
260147
// Round 48 constants
261148
pol C_47_0 = 3708428802547661961864524194762556064568867603968214870300574294082023305587;
262-
pol C_47_1 = 0;
263-
pol C_47_2 = 0;
264-
pol C_47_3 = 0;
265149
// Round 49 constants
266150
pol C_48_0 = 1339414413482882567499652761996854155383863472782829777976929310155400981782;
267-
pol C_48_1 = 0;
268-
pol C_48_2 = 0;
269-
pol C_48_3 = 0;
270151
// Round 50 constants
271152
pol C_49_0 = 6396261245879814100794661157306877072718690153118140891315137894471052482309;
272-
pol C_49_1 = 0;
273-
pol C_49_2 = 0;
274-
pol C_49_3 = 0;
275153
// Round 51 constants
276154
pol C_50_0 = 2069661495404347929962833138824526893650803079024564477269192079629046031674;
277-
pol C_50_1 = 0;
278-
pol C_50_2 = 0;
279-
pol C_50_3 = 0;
280155
// Round 52 constants
281156
pol C_51_0 = 15793521554502133342917616035884588152451122589545915605459159078589855944361;
282-
pol C_51_1 = 0;
283-
pol C_51_2 = 0;
284-
pol C_51_3 = 0;
285157
// Round 53 constants
286158
pol C_52_0 = 17053424498357819626596285492499512504457128907932827007302385782133229252374;
287-
pol C_52_1 = 0;
288-
pol C_52_2 = 0;
289-
pol C_52_3 = 0;
290159
// Round 54 constants
291160
pol C_53_0 = 13658536470391360399708067455536748955260723760813498481671323619545320978896;
292-
pol C_53_1 = 0;
293-
pol C_53_2 = 0;
294-
pol C_53_3 = 0;
295161
// Round 55 constants
296162
pol C_54_0 = 21546095668130239633971575351786704948662094117932406102037724221634677838565;
297-
pol C_54_1 = 0;
298-
pol C_54_2 = 0;
299-
pol C_54_3 = 0;
300163
// Round 56 constants
301164
pol C_55_0 = 21411726238386979516934941789127061362496195649331822900487557574597304399109;
302-
pol C_55_1 = 0;
303-
pol C_55_2 = 0;
304-
pol C_55_3 = 0;
305165
// Round 57 constants
306166
pol C_56_0 = 1944776378988765673004063363506638781964264107780425928778257145151172817981;
307-
pol C_56_1 = 0;
308-
pol C_56_2 = 0;
309-
pol C_56_3 = 0;
310167
// Round 58 constants
311168
pol C_57_0 = 15590719714223718537172639598316570285163081746016049278954513732528516468773;
312-
pol C_57_1 = 0;
313-
pol C_57_2 = 0;
314-
pol C_57_3 = 0;
315169
// Round 59 constants
316170
pol C_58_0 = 1351266421179051765004709939353170430290500926943038391678843253157009556309;
317-
pol C_58_1 = 0;
318-
pol C_58_2 = 0;
319-
pol C_58_3 = 0;
320171
// Round 60 constants
321172
pol C_59_0 = 6772476224477167317130064764757502335545080109882028900432703947986275397548;
322-
pol C_59_1 = 0;
323-
pol C_59_2 = 0;
324-
pol C_59_3 = 0;
325173
// Round 61 constants
326174
pol C_60_0 = 10670120969725161535937685539136065944959698664551200616467222887025111751992;
327175
pol C_60_1 = 4731853626374224678749618809759140702342195350742653173378450474772131006181;

0 commit comments

Comments
 (0)