@@ -12,22 +12,23 @@ include "./lib/decode-float.circom";
12
12
* @input previousOnChain - {Bool} - determines if previous transaction is L1
13
13
* @input txCompressedData - {Uint241} - encode transaction fields
14
14
* @input maxNumBatch - {Uint32} - maximum allowed batch number when the transaction can be processed
15
+ * @input amountF - {Uint40} - amount
15
16
* @input toEthAddr - {Uint160} - ethereum address receiver
16
17
* @input toBjjAy - {Field} - babyjubjub Y coordinate receiver
17
18
* @input rqTxCompressedDataV2 - {Uint193} -requested encode transaction fields version2
18
19
* @input rqToEthAddr - {Uint160} - requested ethereum address receiver
19
20
* @input rqToBjjAy - {Field} - requested babyjubjub Y coordinate
20
21
* @input fromEthAddr - {Uint160} - ethereum address sender
21
22
* @input fromBjjCompressed[256] - {Array[Bool]} - babyjubjub compressed sender
22
- * @input loadAmountF - {Uint16 } - amount to deposit from L1 to L2 encoded as float16
23
+ * @input loadAmountF - {Uint40 } - amount to deposit from L1 to L2 encoded as float40
23
24
* @input globalChainID - {Uint16} - global chain identifier
24
25
* @input currentNumBatch - {Uint32} - current batch number
25
26
* @input onChain - {Bool} - determines if the transaction is L1 or L2
26
27
* @input newAccount - {Bool} - determines if transaction creates a new account
27
28
* @input auxFromIdx - {Uint48} - auxiliary index to create accounts
28
29
* @input auxToIdx - {Uint48} - auxiliary index when signed index receiver is set to null
29
30
* @input inIdx - {Uint48} - old last index assigned
30
- * @output L1L2TxData[nLevels*2 + 16 + 8] - {Array[Bool]} - L1-L2 data availability
31
+ * @output L1L2TxData[nLevels*2 + 40 + 8] - {Array[Bool]} - L1-L2 data availability
31
32
* @output txCompressedDataV2 - {Uint193} - encode transaction fields together version 2
32
33
* @output L1TxFullData - {Array[Bool]} - L1 full data
33
34
* @output outIdx - {Uint48} - new last index assigned
@@ -45,14 +46,15 @@ template DecodeTx(nLevels) {
45
46
signal input previousOnChain;
46
47
signal input txCompressedData; // data shared with L1 tx
47
48
signal input maxNumBatch;
49
+ signal input amountF;
48
50
signal input toEthAddr;
49
51
signal input toBjjAy;
50
52
signal input rqTxCompressedDataV2;
51
53
signal input rqToEthAddr;
52
54
signal input rqToBjjAy;
53
55
54
56
// fromIdx | toIdx | amountF | userFee
55
- signal output L1L2TxData[nLevels* 2 + 16 + 8 ];
57
+ signal output L1L2TxData[nLevels* 2 + 40 + 8 ];
56
58
signal output txCompressedDataV2;
57
59
58
60
// tx L1 fields
@@ -68,7 +70,7 @@ template DecodeTx(nLevels) {
68
70
signal input auxToIdx;
69
71
70
72
// fromEthAddr | fromBjjCompressed | fromIdx | loadAmountF | amountF | tokenID | toIdx
71
- signal output L1TxFullData[160 + 256 + 48 + 16 + 16 + 32 + 48 ];
73
+ signal output L1TxFullData[160 + 256 + 48 + 40 + 40 + 32 + 48 ];
72
74
73
75
signal input inIdx;
74
76
signal output outIdx;
@@ -78,19 +80,20 @@ template DecodeTx(nLevels) {
78
80
signal chainID; // 16 32..47
79
81
signal output fromIdx; // 48 48..95
80
82
signal output toIdx; // 48 96..143
81
- signal output amount; // 16 144..159
82
- signal output tokenID; // 32 160..191
83
- signal output nonce; // 40 192..231
84
- signal output userFee; // 8 232..239
85
- signal output toBjjSign; // 1 240
83
+ signal output tokenID; // 32 144..175
84
+ signal output nonce; // 40 176..215
85
+ signal output userFee; // 8 216..223
86
+ signal output toBjjSign; // 1 224
87
+
88
+ signal output amount;
86
89
87
90
signal output sigL2Hash; // For the L2 signature
88
91
89
92
var i;
90
93
91
94
// Parse txCompressedData
92
95
// //////
93
- component n2bData = Num2Bits(241 );
96
+ component n2bData = Num2Bits(225 );
94
97
n2bData.in <== txCompressedData;
95
98
96
99
// constant signature
@@ -133,43 +136,48 @@ template DecodeTx(nLevels) {
133
136
}
134
137
paddingTo === 0 ;
135
138
136
- // amountF
137
- component dfAmount = DecodeFloatBin();
138
- for (i = 0 ; i < 16 ; i++ ) {
139
- dfAmount.in [i] <== n2bData.out[144 + i];
140
- }
141
- dfAmount.out ==> amount;
142
139
143
140
// tokenID
144
141
component b2ntokenID = Bits2Num(32 );
145
142
for (i = 0 ; i < 32 ; i++ ) {
146
- b2ntokenID.in [i] <== n2bData.out[160 + i];
143
+ b2ntokenID.in [i] <== n2bData.out[144 + i];
147
144
}
148
145
b2ntokenID.out ==> tokenID;
149
146
150
147
// nonce
151
148
component b2nNonce = Bits2Num(40 );
152
149
for (i = 0 ; i < 40 ; i++ ) {
153
- b2nNonce.in [i] <== n2bData.out[192 + i];
150
+ b2nNonce.in [i] <== n2bData.out[176 + i];
154
151
}
155
152
b2nNonce.out ==> nonce;
156
153
157
154
// userFee
158
155
component b2nUserFee = Bits2Num(8 );
159
156
for (i = 0 ; i < 8 ; i++ ) {
160
- b2nUserFee.in [i] <== n2bData.out[232 + i];
157
+ b2nUserFee.in [i] <== n2bData.out[216 + i];
161
158
}
162
159
b2nUserFee.out ==> userFee;
163
160
164
161
// toBjjSign
165
- toBjjSign <== n2bData.out[240 ];
162
+ toBjjSign <== n2bData.out[224 ];
163
+
164
+ // Parse amount
165
+ // //////
166
+
167
+ component n2bAmount = Num2Bits(40 );
168
+ n2bAmount.in <== amountF;
169
+ component dfAmount = DecodeFloatBin();
170
+ for (i = 0 ; i < 40 ; i++ ) {
171
+ dfAmount.in [i] <== n2bAmount.out[i];
172
+ }
173
+ dfAmount.out ==> amount;
166
174
167
175
// Build txCompressedDataV2
168
176
// //////
169
177
// fromIdx | toIdx | amountF | tokenID | nonce | userFee | toBjjSign
170
178
171
179
// add fromIdx
172
- component b2nTxCompressedDataV2 = Bits2Num(48 * 2 + 16 + 32 + 40 + 8 + 1 );
180
+ component b2nTxCompressedDataV2 = Bits2Num(48 * 2 + 40 + 32 + 40 + 8 + 1 );
173
181
for (i = 0 ; i < 48 ; i++ ) {
174
182
b2nTxCompressedDataV2.in [i] <== n2bData.out[48 + i]* (1 - onChain);
175
183
}
@@ -180,27 +188,27 @@ template DecodeTx(nLevels) {
180
188
}
181
189
182
190
// add amountF
183
- for (i = 0 ; i < 16 ; i++ ) {
184
- b2nTxCompressedDataV2.in [48 + 48 + i] <== n2bData .out[144 + i]* (1 - onChain);
191
+ for (i = 0 ; i < 40 ; i++ ) {
192
+ b2nTxCompressedDataV2.in [48 + 48 + i] <== n2bAmount .out[i]* (1 - onChain);
185
193
}
186
194
187
195
// add tokenID
188
196
for (i = 0 ; i < 32 ; i++ ) {
189
- b2nTxCompressedDataV2.in [48 + 48 + 16 + i] <== n2bData.out[160 + i]* (1 - onChain);
197
+ b2nTxCompressedDataV2.in [48 + 48 + 40 + i] <== n2bData.out[144 + i]* (1 - onChain);
190
198
}
191
199
192
200
// add nonce
193
201
for (i = 0 ; i < 40 ; i++ ) {
194
- b2nTxCompressedDataV2.in [48 + 48 + 16 + 32 + i] <== n2bData.out[192 + i]* (1 - onChain);
202
+ b2nTxCompressedDataV2.in [48 + 48 + 40 + 32 + i] <== n2bData.out[176 + i]* (1 - onChain);
195
203
}
196
204
197
205
// add userFee
198
206
for (i = 0 ; i < 8 ; i++ ) {
199
- b2nTxCompressedDataV2.in [48 + 48 + 16 + 32 + 40 + i] <== n2bData.out[232 + i]* (1 - onChain);
207
+ b2nTxCompressedDataV2.in [48 + 48 + 40 + 32 + 40 + i] <== n2bData.out[216 + i]* (1 - onChain);
200
208
}
201
209
202
210
// add toSignBjj
203
- b2nTxCompressedDataV2.in [192 ] <== n2bData.out[240 ];
211
+ b2nTxCompressedDataV2.in [48 + 48 + 40 + 32 + 40 + 8 ] <== n2bData.out[224 ];
204
212
205
213
b2nTxCompressedDataV2.out ==> txCompressedDataV2;
206
214
@@ -231,19 +239,20 @@ template DecodeTx(nLevels) {
231
239
L1L2TxData[nLevels* 2 - 1 - i] <== n2bFinalToIdx.out[i];
232
240
}
233
241
// Add amountF
234
- for (i = 0 ; i < 16 ; i++ ) {
235
- L1L2TxData[nLevels* 2 + 16 - 1 - i] <== n2bData .out[144 + i];
242
+ for (i = 0 ; i < 40 ; i++ ) {
243
+ L1L2TxData[nLevels* 2 + 40 - 1 - i] <== n2bAmount .out[i];
236
244
}
237
245
// Add fee
238
246
for (i = 0 ; i < 8 ; i++ ) {
239
- L1L2TxData[nLevels* 2 + 16 + 8 - 1 - i] <== n2bData.out[232 + i]* (1 - onChain);
247
+ L1L2TxData[nLevels* 2 + 40 + 8 - 1 - i] <== n2bData.out[216 + i]* (1 - onChain);
240
248
}
241
249
242
250
// Build sigL2Hash
243
251
// //////
244
252
// build e_1: toEthAddr 160 bits 0..159
245
- // maxNumBatch 32 bits 160..192
246
- component b2nElement1 = Bits2Num(160 + 32 );
253
+ // amountF 40 bits 160..199
254
+ // maxNumBatch 32 bits 200..232
255
+ component b2nElement1 = Bits2Num(160 + 32 + 40 );
247
256
248
257
// add toEthAddr
249
258
component n2bToEthAddr = Num2Bits(160 );
@@ -252,11 +261,16 @@ template DecodeTx(nLevels) {
252
261
b2nElement1.in [i] <== n2bToEthAddr.out[i];
253
262
}
254
263
264
+ // amountF
265
+ for (i = 0 ; i < 40 ; i++ ) {
266
+ b2nElement1.in [160 + i] <== n2bAmount.out[i];
267
+ }
268
+
255
269
// add maxNumBatch
256
270
component n2bMaxNumBatch = Num2Bits(32 );
257
271
n2bMaxNumBatch.in <== maxNumBatch;
258
272
for (i = 0 ; i < 32 ; i++ ) {
259
- b2nElement1.in [160 + i] <== n2bMaxNumBatch.out[i];
273
+ b2nElement1.in [200 + i] <== n2bMaxNumBatch.out[i];
260
274
}
261
275
262
276
component hashSig = Poseidon(6 );
@@ -289,25 +303,25 @@ template DecodeTx(nLevels) {
289
303
}
290
304
291
305
// Add loadAmountF
292
- component n2bLoadAmountF = Num2Bits(16 );
306
+ component n2bLoadAmountF = Num2Bits(40 );
293
307
n2bLoadAmountF.in <== loadAmountF;
294
- for (i = 0 ; i < 16 ; i++ ) {
295
- L1TxFullData[160 + 256 + 48 + 16 - 1 - i] <== n2bLoadAmountF.out[i]* (onChain);
308
+ for (i = 0 ; i < 40 ; i++ ) {
309
+ L1TxFullData[160 + 256 + 48 + 40 - 1 - i] <== n2bLoadAmountF.out[i]* (onChain);
296
310
}
297
311
298
312
// Add amountF
299
- for (i = 0 ; i < 16 ; i++ ) {
300
- L1TxFullData[160 + 256 + 48 + 16 + 16 - 1 - i] <== n2bData .out[144 + i]* (onChain);
313
+ for (i = 0 ; i < 40 ; i++ ) {
314
+ L1TxFullData[160 + 256 + 48 + 40 + 40 - 1 - i] <== n2bAmount .out[i]* (onChain);
301
315
}
302
316
303
317
// Add tokenID
304
318
for (i = 0 ; i < 32 ; i++ ) {
305
- L1TxFullData[160 + 256 + 48 + 16 + 16 + 32 - 1 - i] <== n2bData.out[160 + i]* (onChain);
319
+ L1TxFullData[160 + 256 + 48 + 40 + 40 + 32 - 1 - i] <== n2bData.out[144 + i]* (onChain);
306
320
}
307
321
308
322
// Add toIdx
309
323
for (i = 0 ; i < 48 ; i++ ) {
310
- L1TxFullData[160 + 256 + 48 + 16 + 16 + 32 + 48 - 1 - i] <== n2bData.out[96 + i]* (onChain);
324
+ L1TxFullData[160 + 256 + 48 + 40 + 40 + 32 + 48 - 1 - i] <== n2bData.out[96 + i]* (onChain);
311
325
}
312
326
313
327
// Perform checks on transaction fields
0 commit comments