Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dynamic indexing into txn array fields #2799

Closed
jasonpaulos opened this issue Aug 24, 2021 · 2 comments · Fixed by #2847
Closed

Support dynamic indexing into txn array fields #2799

jasonpaulos opened this issue Aug 24, 2021 · 2 comments · Fixed by #2847
Assignees

Comments

@jasonpaulos
Copy link
Member

jasonpaulos commented Aug 24, 2021

Problem

Thanks to the gtxns and gtxnsa opcodes, TEAL programs can dynamically index into the group transaction array to access any transaction's fields.

However, it is not currently possible to dynamically index into the array fields of a specific transaction (ApplicationArgs, Accounts, etc.). This is a useful feature in general, and specifically it needs to be added in order to support foreign arrays like algorandfoundation/ARCs#7 proposes.

Solution

Introduce 3 new opcodes:

  • txnas like txna, but it takes the array index as a stack arg. Usage: int <array-index>; txnas ApplicationArgs
  • gtxnas like gtxna, but it takes the array index as a stack arg. Usage: int <array-index>; gtxnas <gtxn-index> ApplicationArgs
  • gtxnsas like gtxnsa, but it takes the array index as an additional stack arg. Usage: int <gtxn-index>; int <array-index>; gtxnsas ApplicationArgs

Adding all 3 opcodes might be overkill (we may want to drop gtxnas), but I've listing them all for completeness.

Dependencies

This would also require PyTeal support.

Urgency

This should make it into TEAL 5.

@jasonpaulos
Copy link
Member Author

jasonpaulos commented Aug 24, 2021

@jannotti suggested it's probably worth adding dynamic index support for scratch store/load as well. I could see that happening with 2 more opcodes:

  • stores: like store, but it takes the slot ID as an additional stack arg. Usage: int <slot-id>; int <value>; stores
  • loads: like load, but it takes the slot ID as a stack arg. Usage: int <slot-id>; loads

One use case that would be enabled by this changes is allowing TEAL values to be passed by reference into subroutines.

@jasonpaulos
Copy link
Member Author

Also worthwhile to support dynamically indexing into LogicSig args:

  • args: like arg, but it takes the argument index as a stack arg. Usage: int <argument-index>; args

This will let LogicSigs iterate through their arguments as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants