Stack Execution - 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

The AVM approves a program execution if it ends with:

The AVM rejects a program execution if it ends with:

Or in case of run-time errors.

Let’s consider the following TEAL program:


#pragma version X

// Macros
#define compareAndReturn ==; return

// Program
int 1; int 2; +;
int 3;
compareAndReturn

The TEAL program above, although minimal, showcases most of the features of the AVM assembly language:

  1. The first line (#pragma version X) directs the assembler to generate bytecode targeting a specific AVM version,

  2. The // prefixes a line comment,

  3. The #define directive is used to define TEAL Macros,

  4. The // Program section lists the opcode instructions of the TEAL program:

    • TEAL supports the Reverse Polish notation (RPN),
    • TEAL lines may end with a newline \n or ;.

For a complete description of the AVM instruction set, refer to the TEAL normative specification.

The AVM bytecode, resulting from the TEAL source code assembly and compilation, is executed on the stack.

Suppose we want the AVM to approve a transaction if the following condition is true:

1+2=31+2=3

This would be an insecure program, since its approval condition is a tautology, which would approve any transaction regardless of the execution context.

The following illustrations show the program execution step-by-step.