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
- Auto
- Light
- Dark
Algorand Specifications
The AVM approves a program execution if it ends with:
- A single non-zero value on top of the stack,
The AVM rejects a program execution if it ends with:
- A single zero value on top of the stack,
- Multiple values on top of the stack,
- No value on top of the stack,
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:
The first line (
#pragma version X) directs the assembler to generate bytecode targeting a specific AVM version,The
//prefixes a line comment,The
#definedirective is used to define TEAL Macros,The
// Programsection lists the opcode instructions of the TEAL program:- TEAL supports the Reverse Polish notation (RPN),
- TEAL lines may end with a newline
\nor;.
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.