Stack Execution
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.
A Simple TEAL Program
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
#define
directive is used to define TEAL Macros, -
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.
A Simple TEAL Execution
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 = 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.