Skip to content

Commit 8a0d699

Browse files
jannottiZach Langley
andauthored
global GroupID (#2838)
Add GroupID as an accessible global field in AVM. Co-authored-by: Zach Langley <zachary.langley@algorand.com>
1 parent f8169d2 commit 8a0d699

File tree

8 files changed

+23
-4
lines changed

8 files changed

+23
-4
lines changed

data/transactions/logic/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ Global fields are fields that are common to all the transactions in the group. I
327327
| 8 | CurrentApplicationID | uint64 | ID of current application executing. Fails if no such application is executing. LogicSigVersion >= 2. |
328328
| 9 | CreatorAddress | []byte | Address of the creator of the current application. Fails if no such application is executing. LogicSigVersion >= 3. |
329329
| 10 | CurrentApplicationAddress | []byte | Address that the current application controls. Fails if no such application is executing. LogicSigVersion >= 5. |
330+
| 11 | GroupID | []byte | ID of the transaction group. 32 zero bytes if the transaction is not part of a group. LogicSigVersion >= 5. |
330331

331332

332333
**Asset Fields**

data/transactions/logic/TEAL_opcodes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ FirstValidTime causes the program to fail. The field is reserved for future use.
465465
| 8 | CurrentApplicationID | uint64 | ID of current application executing. Fails if no such application is executing. LogicSigVersion >= 2. |
466466
| 9 | CreatorAddress | []byte | Address of the creator of the current application. Fails if no such application is executing. LogicSigVersion >= 3. |
467467
| 10 | CurrentApplicationAddress | []byte | Address that the current application controls. Fails if no such application is executing. LogicSigVersion >= 5. |
468+
| 11 | GroupID | []byte | ID of the transaction group. 32 zero bytes if the transaction is not part of a group. LogicSigVersion >= 5. |
468469

469470

470471
## gtxn t f

data/transactions/logic/assembler_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,7 @@ global Round
12561256
global LatestTimestamp
12571257
global CurrentApplicationID
12581258
global CreatorAddress
1259+
global GroupID
12591260
txn Sender
12601261
txn Fee
12611262
bnz label1

data/transactions/logic/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ var globalFieldDocs = map[string]string{
404404
"CurrentApplicationID": "ID of current application executing. Fails if no such application is executing",
405405
"CreatorAddress": "Address of the creator of the current application. Fails if no such application is executing",
406406
"CurrentApplicationAddress": "Address that the current application controls. Fails if no such application is executing",
407+
"GroupID": "ID of the transaction group. 32 zero bytes if the transaction is not part of a group.",
407408
}
408409

409410
// GlobalFieldDocs are notes on fields available in `global` with extra versioning info if any

data/transactions/logic/eval.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,10 @@ func (cx *EvalContext) getCreatorAddress() ([]byte, error) {
23132313
return creator[:], nil
23142314
}
23152315

2316+
func (cx *EvalContext) getGroupID() []byte {
2317+
return cx.Txn.Txn.Group[:]
2318+
}
2319+
23162320
var zeroAddress basics.Address
23172321

23182322
func (cx *EvalContext) globalFieldToValue(fs globalFieldSpec) (sv stackValue, err error) {
@@ -2341,6 +2345,8 @@ func (cx *EvalContext) globalFieldToValue(fs globalFieldSpec) (sv stackValue, er
23412345
sv.Bytes = addr[:]
23422346
case CreatorAddress:
23432347
sv.Bytes, err = cx.getCreatorAddress()
2348+
case GroupID:
2349+
sv.Bytes = cx.getGroupID()
23442350
default:
23452351
err = fmt.Errorf("invalid global field %d", fs.field)
23462352
}

data/transactions/logic/eval_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,10 @@ len
997997
int 32
998998
==
999999
&&
1000+
global GroupID
1001+
byte 0x0706000000000000000000000000000000000000000000000000000000000000
1002+
==
1003+
&&
10001004
`
10011005

10021006
func TestGlobal(t *testing.T) {
@@ -1025,7 +1029,7 @@ func TestGlobal(t *testing.T) {
10251029
EvalStateful, CheckStateful,
10261030
},
10271031
5: {
1028-
CurrentApplicationAddress, globalV5TestProgram,
1032+
GroupID, globalV5TestProgram,
10291033
EvalStateful, CheckStateful,
10301034
},
10311035
}
@@ -1054,6 +1058,7 @@ func TestGlobal(t *testing.T) {
10541058
require.NoError(t, err)
10551059
var txn transactions.SignedTxn
10561060
txn.Lsig.Logic = ops.Program
1061+
txn.Txn.Group = crypto.Digest{0x07, 0x06}
10571062
txgroup := make([]transactions.SignedTxn, 1)
10581063
txgroup[0] = txn
10591064
sb := strings.Builder{}

data/transactions/logic/fields.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ const (
335335

336336
// CurrentApplicationAddress [32]byte
337337
CurrentApplicationAddress
338+
// GroupID [32]byte
339+
GroupID
338340

339341
invalidGlobalField
340342
)
@@ -364,6 +366,7 @@ var globalFieldSpecs = []globalFieldSpec{
364366
{CurrentApplicationID, StackUint64, runModeApplication, 2},
365367
{CreatorAddress, StackBytes, runModeApplication, 3},
366368
{CurrentApplicationAddress, StackBytes, runModeApplication, 5},
369+
{GroupID, StackBytes, modeAny, 5},
367370
}
368371

369372
// GlobalFieldSpecByField maps GlobalField to spec

data/transactions/logic/fields_string.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)