Applications - Algorand Specifications

Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Algorand Specifications

Applications (Smart Contracts) are executed in Application Call transactions. Like Logic Signatures, Applications indicate success by leaving a single non-zero uint64 value on the Stack.

A failed Application Call to an Approval Program is not a valid transaction, thus not written to the blockchain.

An Application Call with On Complete set to ClearStateOC invokes the Clear State Program, rather than the usual Approval Program. If the Clear State Program fails, application state changes are rolled back, but the transaction still succeeds, and the sender’s Local State for the called application is removed.

Applications have access to everything a Logic Signature may access (see section), as well as the ability to examine blockchain state, such as balances and application state (their own state and the state of other applications).

Applications also have access to some Global Fields that are not visible to Logic Signatures because their values change over time.

Since Applications access changing state, nodes have to rerun their code to determine if the Application Call transactions in their Transaction Pool would still succeed each time a block is added to the blockchain.

The size of an Application is defined as the length of its approval program bytecode plus its clearstate program bytecode. The sum of these two programs MUST NOT exceed Appprog,t,max×Apppage,maxAppprog,t,max×Apppage,max.

Applications have limits on their execution cost.

Before Version 4, this was a static limit on the cost of all the instructions in the program.

Starting in Version 4, the cost is tracked dynamically during execution and MUST NOT exceed Appc,maxAppc,max.

Beginning with Version 5, programs costs are pooled and tracked dynamically across Application executions in a group. If nn application invocations appear in a group, then the total execution cost of all such calls MUST NOT exceed n×Appc,maxn×Appc,max.

In Version 6, inner Application Calls become possible, and each such call increases the pooled opcode budget by Appc,maxAppc,max at the time the inner group is submitted (with the itxn_submit opcode), allowing a maximum opcode budget of:

GTmax×(1+Appitxn)×Appc,max=190,400GTmax×(1+Appitxn)×Appc,max=190,400

Executions of the Clear State Program are more stringent to ensure that Applications may be closed out (by accounts) and have a chance to clean up their internal state.

At the beginning of a Clear State Program execution, the pooled budget available MUST be Appc,maxAppc,max or higher. If it is not, the containing transaction group fails without clearing the Application’s state.

During the Clear State Program execution, no more than Appc,maxAppc,max may be drawn. If further execution is attempted, the Clear State Program fails, and the Application’s state is cleared.

Applications have limits on the amount of blockchain state they may examine.

These limits are enforced by failing any opcode that attempts to access a resource unless the resource is available. These resources are:

Resources are available based on the contents of the executing transaction and, in later versions, the contents of other transactions in the same group.

However, the transaction access list allows for the listing of more resources than the foreign arrays. Listed resources become available to other (post-Version 8 programs) Applications through group resource sharing.

Important

EXAMPLE: If account A is made available in one transaction, and asset X is made available in another, group resource sharing does not make A’s X Holding available.

  1. pay: sender (snd), receiver (rcv), and close-to (close) (if set).
  2. keyreg: sender (snd).
  3. acfg: sender (snd), configured asset (caid), and the configured asset holding of the sender.
  4. axfer: sender (snd), asset receiver (arcv), asset sender (asnd) (if set), asset close-to (aclose) (if set), transferred asset (xaid), and the transferred asset holding of each of those accounts.
  5. afrz: sender (snd), freeze account (fadd), freeze asset (faid), and the freeze asset holding of the freeze account. The freeze asset holding of the sender is not made available.

Regardless of availability, any attempt to access an Asset or Application with an ID less than 256256 from within an Application will fail immediately. This avoids any ambiguity in opcodes that interpret their integer arguments as resource IDs or indexes into the foreign assets or foreign applications arrays.

It is RECOMMENDED that Application authors avoid supplying array indexes to these opcodes, and always use explicit resource IDs. By using explicit IDs, contracts will better take advantage of group resource sharing.

The array indexing interpretation MAY be deprecated in a future program version.