Skip to content

Commit d28eca1

Browse files
authored
Gloadss (#3248)
* Three new globals for to help contract-to-contract usability * detritis * Check error * doc comments * opcode, docs, and tests * specs update
1 parent d371ef2 commit d28eca1

File tree

8 files changed

+70
-14
lines changed

8 files changed

+70
-14
lines changed

data/transactions/logic/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ Some of these have immediate data in the byte or bytes after the opcode.
250250
| `stores` | pop indexes A and B. store B to the Ath scratch space |
251251
| `gload t i` | push Ith scratch space index of the Tth transaction in the current group |
252252
| `gloads i` | push Ith scratch space index of the Xth transaction in the current group |
253+
| `gloadss` | push Bth scratch space index of the Ath transaction in the current group |
253254
| `gaid t` | push the ID of the asset or application created in the Tth transaction of the current group |
254255
| `gaids` | push the ID of the asset or application created in the Xth transaction of the current group |
255256

data/transactions/logic/TEAL_opcodes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,3 +1404,12 @@ bitlen interprets arrays as big-endian integers, unlike setbit/getbit
14041404
- push Xth LogicSig argument to stack
14051405
- LogicSigVersion >= 5
14061406
- Mode: Signature
1407+
1408+
## gloadss
1409+
1410+
- Opcode: 0xc4
1411+
- Pops: *... stack*, {uint64 A}, {uint64 B}
1412+
- Pushes: any
1413+
- push Bth scratch space index of the Ath transaction in the current group
1414+
- LogicSigVersion >= 6
1415+
- Mode: Application

data/transactions/logic/assembler_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ const v6Nonsense = v5Nonsense + `
346346
itxn_next
347347
gitxn 4 CreatedAssetID
348348
gitxna 3 Logs 12
349+
int 0
350+
dup
351+
gloadss
349352
`
350353

351354
var nonsense = map[uint64]string{
@@ -363,7 +366,7 @@ var compiled = map[uint64]string{
363366
3: "032008b7a60cf8acd19181cf959a12f8acd19181cf951af8acd19181cf15f8acd191810f01020026050212340c68656c6c6f20776f726c6421208dae2087fbba51304eb02b91f656948397a7946390e8cb70fc9ea4d95f92251d024242047465737400320032013202320328292929292a0431003101310231043105310731083109310a310b310c310d310e310f3111311231133114311533000033000133000233000433000533000733000833000933000a33000b33000c33000d33000e33000f3300113300123300133300143300152d2e0102222324252104082209240a220b230c240d250e230f23102311231223132314181b1c2b171615400003290349483403350222231d4a484848482a50512a63222352410003420000432105602105612105270463484821052b62482b642b65484821052b2106662b21056721072b682b692107210570004848210771004848361c0037001a0031183119311b311d311e311f3120210721051e312131223123312431253126312731283129312a312b312c312d312e312f4478222105531421055427042106552105082106564c4d4b02210538212106391c0081e80780046a6f686e",
364367
4: "042004010200b7a60c26040242420c68656c6c6f20776f726c6421208dae2087fbba51304eb02b91f656948397a7946390e8cb70fc9ea4d95f92251d047465737400320032013202320380021234292929292a0431003101310231043105310731083109310a310b310c310d310e310f3111311231133114311533000033000133000233000433000533000733000833000933000a33000b33000c33000d33000e33000f3300113300123300133300143300152d2e01022581f8acd19181cf959a1281f8acd19181cf951a81f8acd19181cf1581f8acd191810f082209240a220b230c240d250e230f23102311231223132314181b1c28171615400003290349483403350222231d4a484848482a50512a632223524100034200004322602261222b634848222862482864286548482228236628226724286828692422700048482471004848361c0037001a0031183119311b311d311e311f312024221e312131223123312431253126312731283129312a312b312c312d312e312f44782522531422542b2355220823564c4d4b0222382123391c0081e80780046a6f686e2281d00f24231f880003420001892223902291922394239593a0a1a2a3a4a5a6a7a8a9aaabacadae23af3a00003b003c003d8164",
365368
5: "052004010002b7a60c26050242420c68656c6c6f20776f726c6421070123456789abcd208dae2087fbba51304eb02b91f656948397a7946390e8cb70fc9ea4d95f92251d047465737400320032013202320380021234292929292b0431003101310231043105310731083109310a310b310c310d310e310f3111311231133114311533000033000133000233000433000533000733000833000933000a33000b33000c33000d33000e33000f3300113300123300133300143300152d2e01022581f8acd19181cf959a1281f8acd19181cf951a81f8acd19181cf1581f8acd191810f082209240a220b230c240d250e230f23102311231223132314181b1c28171615400003290349483403350222231d4a484848482b50512a632223524100034200004322602261222704634848222862482864286548482228246628226723286828692322700048482371004848361c0037001a0031183119311b311d311e311f312023221e312131223123312431253126312731283129312a312b312c312d312e312f447825225314225427042455220824564c4d4b0222382124391c0081e80780046a6f686e2281d00f23241f880003420001892224902291922494249593a0a1a2a3a4a5a6a7a8a9aaabacadae24af3a00003b003c003d816472064e014f012a57000823810858235b235a2359b03139330039b1b200b322c01a23c1001a2323c21a23c3233e233f8120af06002a494905002a49490700b53a03",
366-
6: "062004010002b7a60c26050242420c68656c6c6f20776f726c6421070123456789abcd208dae2087fbba51304eb02b91f656948397a7946390e8cb70fc9ea4d95f92251d047465737400320032013202320380021234292929292b0431003101310231043105310731083109310a310b310c310d310e310f3111311231133114311533000033000133000233000433000533000733000833000933000a33000b33000c33000d33000e33000f3300113300123300133300143300152d2e01022581f8acd19181cf959a1281f8acd19181cf951a81f8acd19181cf1581f8acd191810f082209240a220b230c240d250e230f23102311231223132314181b1c28171615400003290349483403350222231d4a484848482b50512a632223524100034200004322602261222704634848222862482864286548482228246628226723286828692322700048482371004848361c0037001a0031183119311b311d311e311f312023221e312131223123312431253126312731283129312a312b312c312d312e312f447825225314225427042455220824564c4d4b0222382124391c0081e80780046a6f686e2281d00f23241f880003420001892224902291922494249593a0a1a2a3a4a5a6a7a8a9aaabacadae24af3a00003b003c003d816472064e014f012a57000823810858235b235a2359b03139330039b1b200b322c01a23c1001a2323c21a23c3233e233f8120af06002a494905002a49490700b53a03b6b7043cb8033a0c}",
369+
6: "062004010002b7a60c26050242420c68656c6c6f20776f726c6421070123456789abcd208dae2087fbba51304eb02b91f656948397a7946390e8cb70fc9ea4d95f92251d047465737400320032013202320380021234292929292b0431003101310231043105310731083109310a310b310c310d310e310f3111311231133114311533000033000133000233000433000533000733000833000933000a33000b33000c33000d33000e33000f3300113300123300133300143300152d2e01022581f8acd19181cf959a1281f8acd19181cf951a81f8acd19181cf1581f8acd191810f082209240a220b230c240d250e230f23102311231223132314181b1c28171615400003290349483403350222231d4a484848482b50512a632223524100034200004322602261222704634848222862482864286548482228246628226723286828692322700048482371004848361c0037001a0031183119311b311d311e311f312023221e312131223123312431253126312731283129312a312b312c312d312e312f447825225314225427042455220824564c4d4b0222382124391c0081e80780046a6f686e2281d00f23241f880003420001892224902291922494249593a0a1a2a3a4a5a6a7a8a9aaabacadae24af3a00003b003c003d816472064e014f012a57000823810858235b235a2359b03139330039b1b200b322c01a23c1001a2323c21a23c3233e233f8120af06002a494905002a49490700b53a03b6b7043cb8033a0c2349c4}",
367370
}
368371

369372
func pseudoOp(opcode string) bool {

data/transactions/logic/doc.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,16 @@ var opDocByName = map[string]string{
100100
"gitxn": "push field F of the Tth transaction in the last inner group",
101101
"gitxna": "push Ith value of the array field F from the Tth transaction in the last inner group",
102102

103-
"global": "push value from globals to stack",
104-
"load": "copy a value from scratch space to the stack. All scratch spaces are 0 at program start.",
105-
"store": "pop value X. store X to the Ith scratch space",
106-
"loads": "copy a value from the Xth scratch space to the stack. All scratch spaces are 0 at program start.",
107-
"stores": "pop indexes A and B. store B to the Ath scratch space",
108-
"gload": "push Ith scratch space index of the Tth transaction in the current group",
109-
"gloads": "push Ith scratch space index of the Xth transaction in the current group",
110-
"gaid": "push the ID of the asset or application created in the Tth transaction of the current group",
111-
"gaids": "push the ID of the asset or application created in the Xth transaction of the current group",
103+
"global": "push value from globals to stack",
104+
"load": "copy a value from scratch space to the stack. All scratch spaces are 0 at program start.",
105+
"store": "pop value X. store X to the Ith scratch space",
106+
"loads": "copy a value from the Xth scratch space to the stack. All scratch spaces are 0 at program start.",
107+
"stores": "pop indexes A and B. store B to the Ath scratch space",
108+
"gload": "push Ith scratch space index of the Tth transaction in the current group",
109+
"gloads": "push Ith scratch space index of the Xth transaction in the current group",
110+
"gloadss": "push Bth scratch space index of the Ath transaction in the current group",
111+
"gaid": "push the ID of the asset or application created in the Tth transaction of the current group",
112+
"gaids": "push the ID of the asset or application created in the Xth transaction of the current group",
112113

113114
"bnz": "branch to TARGET if value X is not zero",
114115
"bz": "branch to TARGET if value X is zero",
@@ -302,7 +303,7 @@ var OpGroups = map[string][]string{
302303
"Byte Array Slicing": {"substring", "substring3", "extract", "extract3", "extract_uint16", "extract_uint32", "extract_uint64"},
303304
"Byte Array Arithmetic": {"b+", "b-", "b/", "b*", "b<", "b>", "b<=", "b>=", "b==", "b!=", "b%"},
304305
"Byte Array Logic": {"b|", "b&", "b^", "b~"},
305-
"Loading Values": {"intcblock", "intc", "intc_0", "intc_1", "intc_2", "intc_3", "pushint", "bytecblock", "bytec", "bytec_0", "bytec_1", "bytec_2", "bytec_3", "pushbytes", "bzero", "arg", "arg_0", "arg_1", "arg_2", "arg_3", "args", "txn", "gtxn", "txna", "txnas", "gtxna", "gtxnas", "gtxns", "gtxnsa", "gtxnsas", "global", "load", "loads", "store", "stores", "gload", "gloads", "gaid", "gaids"},
306+
"Loading Values": {"intcblock", "intc", "intc_0", "intc_1", "intc_2", "intc_3", "pushint", "bytecblock", "bytec", "bytec_0", "bytec_1", "bytec_2", "bytec_3", "pushbytes", "bzero", "arg", "arg_0", "arg_1", "arg_2", "arg_3", "args", "txn", "gtxn", "txna", "txnas", "gtxna", "gtxnas", "gtxns", "gtxnsa", "gtxnsas", "global", "load", "loads", "store", "stores", "gload", "gloads", "gloadss", "gaid", "gaids"},
306307
"Flow Control": {"err", "bnz", "bz", "b", "return", "pop", "dup", "dup2", "dig", "cover", "uncover", "swap", "select", "assert", "callsub", "retsub"},
307308
"State Access": {"balance", "min_balance", "app_opted_in", "app_local_get", "app_local_get_ex", "app_global_get", "app_global_get_ex", "app_local_put", "app_global_put", "app_local_del", "app_global_del", "asset_holding_get", "asset_params_get", "app_params_get", "log"},
308309
"Inner Transactions": {"itxn_begin", "itxn_next", "itxn_field", "itxn_submit", "itxn", "itxna", "gitxn", "gitxna"},

data/transactions/logic/eval.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2977,6 +2977,30 @@ func opGloads(cx *EvalContext) {
29772977
cx.stack[last] = scratchValue
29782978
}
29792979

2980+
func opGloadss(cx *EvalContext) {
2981+
last := len(cx.stack) - 1
2982+
prev := last - 1
2983+
2984+
gi := cx.stack[prev].Uint
2985+
if gi >= uint64(len(cx.TxnGroup)) {
2986+
cx.err = fmt.Errorf("gloads lookup TxnGroup[%d] but it only has %d", gi, len(cx.TxnGroup))
2987+
return
2988+
}
2989+
scratchIdx := cx.stack[last].Uint
2990+
if scratchIdx >= 256 {
2991+
cx.err = fmt.Errorf("gloadss scratch index >= 256 (%d)", scratchIdx)
2992+
return
2993+
}
2994+
scratchValue, err := opGloadImpl(cx, int(gi), byte(scratchIdx), "gloadss")
2995+
if err != nil {
2996+
cx.err = err
2997+
return
2998+
}
2999+
3000+
cx.stack[prev] = scratchValue
3001+
cx.stack = cx.stack[:last]
3002+
}
3003+
29803004
func opConcat(cx *EvalContext) {
29813005
last := len(cx.stack) - 1
29823006
prev := last - 1

data/transactions/logic/evalStateful_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,7 @@ func TestReturnTypes(t *testing.T) {
22442244
"store": "store 0",
22452245
"gload": "gload 0 0",
22462246
"gloads": "gloads 0",
2247+
"gloadss": "pop; pop; int 0; int 1; gloadss", // Needs txn index = 0 to work
22472248
"gaid": "gaid 0",
22482249
"dig": "dig 0",
22492250
"cover": "cover 0",
@@ -2325,7 +2326,7 @@ func TestReturnTypes(t *testing.T) {
23252326
require.Equal(
23262327
t,
23272328
len(spec.Returns), len(cx.stack),
2328-
fmt.Sprintf("\n%s%s expected to return %d values but stack has %d", ep.Trace.String(), spec.Name, len(spec.Returns), len(cx.stack)),
2329+
fmt.Sprintf("\n%s%s expected to return %d values but stack is %v", ep.Trace.String(), spec.Name, len(spec.Returns), cx.stack),
23292330
)
23302331
for i := 0; i < len(spec.Returns); i++ {
23312332
sp := len(cx.stack) - 1 - i

data/transactions/logic/eval_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,7 @@ int 1`,
24682468
}
24692469
}
24702470

2471+
// TestGloads tests gloads and gloadss
24712472
func TestGloads(t *testing.T) {
24722473
partitiontest.PartitionTest(t)
24732474

@@ -2487,11 +2488,26 @@ int 0
24872488
gloads 0
24882489
byte "txn 1"
24892490
==
2491+
assert
24902492
int 1
24912493
gloads 1
24922494
byte "txn 2"
24932495
==
2494-
&&`
2496+
assert
2497+
int 0
2498+
int 0
2499+
gloadss
2500+
byte "txn 1"
2501+
==
2502+
assert
2503+
int 1
2504+
int 1
2505+
gloadss
2506+
byte "txn 2"
2507+
==
2508+
assert
2509+
int 1
2510+
`
24952511

24962512
sources := []string{source1, source2, source3}
24972513

data/transactions/logic/opcodes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ var OpSpecs = []OpSpec{
221221
// Group scratch space access
222222
{0x3a, "gload", opGload, asmDefault, disDefault, nil, oneAny, 4, runModeApplication, immediates("t", "i")},
223223
{0x3b, "gloads", opGloads, asmDefault, disDefault, oneInt, oneAny, 4, runModeApplication, immediates("i")},
224-
// Access creatable IDs
224+
// Access creatable IDs (consider deprecating, as txn CreatedAssetID, CreatedApplicationID should be enough
225225
{0x3c, "gaid", opGaid, asmDefault, disDefault, nil, oneInt, 4, runModeApplication, immediates("t")},
226226
{0x3d, "gaids", opGaids, asmDefault, disDefault, oneInt, oneInt, 4, runModeApplication, opDefault},
227227

@@ -334,6 +334,7 @@ var OpSpecs = []OpSpec{
334334
{0xc1, "gtxnas", opGtxnas, assembleGtxnas, disGtxn, oneInt, oneAny, 5, modeAny, immediates("t", "f")},
335335
{0xc2, "gtxnsas", opGtxnsas, assembleGtxnsas, disTxn, twoInts, oneAny, 5, modeAny, immediates("f")},
336336
{0xc3, "args", opArgs, asmDefault, disDefault, oneInt, oneBytes, 5, runModeSignature, opDefault},
337+
{0xc4, "gloadss", opGloadss, asmDefault, disDefault, twoInts, oneAny, 6, runModeApplication, opDefault},
337338
}
338339

339340
type sortByOpcode []OpSpec

0 commit comments

Comments
 (0)