1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
// Copyright (C) 2019-2024 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.
package txntest
import (
"testing"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/transactions/logic"
"github.com/stretchr/testify/require"
)
// Test/benchmark real programs found in the wild (testnet/mainnet).
// CreateTinyManTxGroup repro this tx group by tinyman
// https://algoexplorer.io/tx/group/d1bUcqFbNZDMIdcreM9Vw2jzOIZIa2UzDgTTlr2Sl4o%3D
func CreateTinyManTxGroup(tb testing.TB, randNote bool) []Txn {
user, err := basics.UnmarshalChecksumAddress("W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY")
require.NoError(tb, err)
luser, err := basics.UnmarshalChecksumAddress("FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA")
require.NoError(tb, err)
var note []byte = nil
if randNote {
note = make([]byte, 12)
crypto.RandBytes(note[:])
}
fees := Txn{
Type: "pay",
Fee: 1000,
Sender: user,
Receiver: luser,
Amount: 2000, // must cover the luser fees in appcall and withdraw
Note: note,
}
appcall := Txn{
Type: "appl",
Fee: 1000,
Sender: luser,
ApplicationID: 552635992,
Accounts: []basics.Address{user},
Note: note,
}.Args("swap", "fo")
deposit := Txn{
Type: "axfer",
Fee: 1000,
Sender: user,
AssetReceiver: luser,
Note: note,
}
withdraw := Txn{
Type: "pay",
Fee: 1000,
Sender: luser,
Receiver: user,
Note: note,
}
return []Txn{fees, *appcall, deposit, withdraw}
}
// TmLsig is a tinyman lsig contract used in tests/benchmarks
const TmLsig = `
#pragma version 4
intcblock 1 0 0 31566704 3 4 5 6
intc_3 // 31566704
intc_2 // 0
>
assert
txn CloseRemainderTo // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ
global ZeroAddress
==
assert
txn AssetCloseTo // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ
global ZeroAddress
==
assert
txn RekeyTo // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ
global ZeroAddress
==
assert
global GroupSize // size=4
intc_0 // 1
>
assert
gtxn 1 Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 1 TypeEnum
intc 7 // 6
==
assert
gtxn 1 ApplicationID // id=552635992
pushint 552635992
==
assert // PC=65
gtxn 1 OnCompletion
intc_0 // 1
==
gtxn 1 NumAppArgs // index=2
intc 4 // 3
==
&&
gtxna 1 ApplicationArgs 0 // arg=73776170
pushbytes 0x626f6f747374726170 // "bootstrap"
==
&&
bnz label1
gtxn 1 OnCompletion
intc_1 // 0
==
assert
gtxn 1 NumAppArgs // index=2
pushint 2
==
gtxna 1 ApplicationArgs 0 // arg=73776170
pushbytes 0x73776170 // "swap"
==
&&
bnz label2
gtxn 1 NumAppArgs // index=2
intc_0 // 1
==
assert
gtxna 1 ApplicationArgs 0 // arg=73776170
pushbytes 0x6d696e74 // "mint"
==
bnz label3
gtxna 1 ApplicationArgs 0 // arg=73776170
pushbytes 0x6275726e // "burn"
==
bnz label4
gtxna 1 ApplicationArgs 0 // arg=73776170
pushbytes 0x72656465656d // "redeem"
==
bnz label5
gtxna 1 ApplicationArgs 0 // arg=73776170
pushbytes 0x66656573 // "fees"
==
bnz label6
err
label1:
intc 6 // 5
intc 5 // 4
intc_2 // 0
intc_1 // 0
==
select
global GroupSize // size=4
==
assert
gtxna 1 ApplicationArgs 1 // arg=666f
btoi
intc_3 // 31566704
==
gtxna 1 ApplicationArgs 2
btoi
intc_2 // 0
==
&&
assert
gtxn 2 Sender // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 2 TypeEnum
intc 4 // 3
==
assert
gtxn 2 ConfigAsset // id=0
intc_1 // 0
==
assert
gtxn 2 ConfigAssetTotal // total=0.
intc_1 // 0
~
==
assert
gtxn 2 ConfigAssetDecimals // dec=0
intc 7 // 6
==
assert
gtxn 2 ConfigAssetDefaultFrozen // default=false
intc_1 // 0
==
assert
gtxn 2 ConfigAssetUnitName //
pushbytes 0x544d504f4f4c3131 // "TMPOOL11"
==
assert
gtxn 2 ConfigAssetName //
substring 0 15
pushbytes 0x54696e796d616e506f6f6c312e3120 // "TinymanPool1.1 "
==
assert
gtxn 2 ConfigAssetURL //
pushbytes 0x68747470733a2f2f74696e796d616e2e6f7267 // "https://tinyman.org"
==
assert
gtxn 2 ConfigAssetManager
global ZeroAddress
==
assert
gtxn 2 ConfigAssetReserve
global ZeroAddress
==
assert
gtxn 2 ConfigAssetFreeze
global ZeroAddress
==
assert
gtxn 2 ConfigAssetClawback
global ZeroAddress
==
assert
gtxn 3 Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 3 TypeEnum
intc 5 // 4
==
assert
gtxn 3 XferAsset // id=0
intc_3 // 31566704
==
assert
gtxn 3 AssetReceiver // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 3 AssetAmount
intc_1 // 0
==
assert
intc_2 // 0
intc_1 // 0
!=
bnz label7
gtxn 1 Fee // 0.001000
gtxn 2 Fee // 0.001000
+
gtxn 3 Fee // 0.001000
+
store 1
b label8
label7:
gtxn 4 Sender
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 4 TypeEnum
intc 5 // 4
==
assert
gtxn 4 XferAsset
intc_2 // 0
==
assert
gtxn 4 AssetReceiver
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 4 AssetAmount
intc_1 // 0
==
assert
gtxn 1 Fee // 0.001000
gtxn 2 Fee // 0.001000
+
gtxn 3 Fee // 0.001000
+
gtxn 4 Fee
+
store 1
b label8
label3:
global GroupSize // size=4
intc 6 // 5
==
assert
gtxna 1 Accounts 1
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
!=
assert
gtxna 1 Accounts 1
gtxn 4 AssetReceiver
==
assert
gtxn 2 Sender // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
!=
assert
gtxn 2 AssetReceiver // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 3 Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
gtxn 2 Sender // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
==
assert
gtxn 2 XferAsset // id=31566704
intc_3 // 31566704
==
assert
gtxn 3 AssetReceiver // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ
gtxn 3 Receiver // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
gtxn 3 TypeEnum
intc_0 // 1
==
select
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 3 XferAsset // id=0
intc_1 // 0
gtxn 3 TypeEnum
intc_0 // 1
==
select
intc_2 // 0
==
assert
gtxn 4 Sender
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 4 AssetReceiver
gtxn 2 Sender // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
==
assert
gtxn 1 Fee // 0.001000
gtxn 4 Fee
+
store 1
b label8
label4:
global GroupSize // size=4
intc 6 // 5
==
assert
gtxna 1 Accounts 1
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
!=
assert
gtxna 1 Accounts 1
gtxn 2 AssetReceiver // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 3 AssetReceiver // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ
gtxn 3 Receiver // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
gtxn 3 TypeEnum
intc_0 // 1
==
select
gtxna 1 Accounts 1
==
assert
gtxn 2 Sender // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 2 AssetReceiver // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
gtxn 4 Sender
==
assert
gtxn 2 XferAsset // id=31566704
intc_3 // 31566704
==
assert
gtxn 3 Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 3 AssetReceiver // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ
gtxn 3 Receiver // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
gtxn 3 TypeEnum
intc_0 // 1
==
select
gtxn 4 Sender
==
assert
gtxn 3 XferAsset // id=0
intc_1 // 0
gtxn 3 TypeEnum
intc_0 // 1
==
select
intc_2 // 0
==
assert
gtxn 4 Sender
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
!=
assert
gtxn 4 AssetReceiver
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 1 Fee // 0.001000
gtxn 2 Fee // 0.001000
+
gtxn 3 Fee // 0.001000
+
store 1
b label8
label2: // swap
global GroupSize // size=4
intc 5 // 4
==
assert
gtxna 1 Accounts 1
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
!=
assert
gtxn 2 Sender // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
gtxna 1 Accounts 1
==
assert // PC=718
gtxn 2 Sender // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
!=
assert
gtxn 3 Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert // PC=732
gtxn 2 AssetReceiver // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
gtxn 2 Receiver // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ
gtxn 2 TypeEnum
intc_0 // 1
==
select
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert
gtxn 3 AssetReceiver // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ
gtxn 3 Receiver // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
gtxn 3 TypeEnum
intc_0 // 1
==
select
gtxn 2 Sender // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
==
assert // PC=765
gtxn 1 Fee // 0.001000
gtxn 3 Fee // 0.001000
+
store 1
b label8
label5:
global GroupSize // size=4
intc 4 // 3
==
assert
gtxna 1 Accounts 1
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
!=
assert
gtxn 2 AssetReceiver // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
gtxn 2 Receiver // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ
gtxn 2 TypeEnum
intc_0 // 1
==
select
gtxna 1 Accounts 1
==
assert
gtxn 1 Fee // 0.001000
gtxn 2 Fee // 0.001000
+
store 1
b label8
label6:
global GroupSize // size=4
intc 4 // 3
==
assert
gtxn 1 Fee // 0.001000
gtxn 2 Fee // 0.001000
+
store 1
b label8
label8:
gtxn 0 Sender // W2IZ3EHDRW2IQNPC33CI2CXSLMFCFICVKQVWIYLJWXCTD765RW47ONNCEY
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
!=
assert
gtxn 0 Receiver // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
txn Sender // FPOU46NBKTWUZCNMNQNXRWNW3SMPOOK4ZJIN5WSILCWP662ANJLTXVRUKA
==
assert // PC=853
gtxn 0 Amount // 0.002000
load 1
>=
return
`
// CreateTinyManSignedTxGroup repro this tx group by tinyman
// https://algoexplorer.io/tx/group/d1bUcqFbNZDMIdcreM9Vw2jzOIZIa2UzDgTTlr2Sl4o%3D
// which is an algo to USDC swap. The source code below is extracted from
// algoexplorer, which adds some unusual stuff as comments
func CreateTinyManSignedTxGroup(tb testing.TB, txns []Txn) ([]transactions.SignedTxn, []*crypto.SignatureSecrets) {
ops, err := logic.AssembleString(TmLsig)
require.NoError(tb, err)
stxns := Group(&txns[0], &txns[1], &txns[2], &txns[3])
stxns[1].Lsig.Logic = ops.Program
stxns[3].Lsig.Logic = ops.Program
// add in some signatures, so TxnGroup can succeed. A randomly generated
// private key. The actual value does not matter, as long as this is a valid
// private key.
signer := crypto.PrivateKey{
128, 128, 92, 23, 212, 119, 175, 51, 157, 2, 165,
215, 137, 37, 82, 42, 52, 227, 54, 41, 243, 67,
141, 76, 208, 17, 199, 17, 140, 46, 113, 0, 159,
50, 105, 52, 77, 104, 118, 200, 104, 220, 105, 21,
147, 162, 191, 236, 115, 201, 197, 128, 8, 91, 224,
78, 104, 209, 2, 185, 110, 28, 42, 97,
}
secrets, err := crypto.SecretKeyToSignatureSecrets(signer)
require.NoError(tb, err)
stxns[0] = stxns[0].Txn.Sign(secrets)
stxns[2] = stxns[2].Txn.Sign(secrets)
return stxns, []*crypto.SignatureSecrets{secrets}
}
|