Stack - 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 Stack is the core structure for the interpreter’s execution. It is constructed and used as a regular stack data structure.

Important

IMPLEMENTATION:

Stack reference implementation.

On a new AVM program execution, the Stack starts empty. After opcode execution the Stack can contain arbitrary values of either:

Byte-arrays length MUST NOT exceed 40964096 bytes.

A value that may be of either one of these types (not simultaneously) is generically referred to as a StackValue.

Most operations act on the stack, popping arguments from it and pushing results to it. Some operations have immediate arguments encoded directly into the instruction, rather than coming from the Stack.

The maximum Stack depth is 10001000. If the Stack depth is exceeded or if a byte-array element exceeds 40964096 bytes, the program fails.

If an opcode is documented to access a position in the Stack that does not exist, the operation fails.

Important

EXAMPLE:

This is often an attempt to access an element below the Stack. A simple example is an operation like concat that expects two arguments on the Stack: if the Stack has fewer than two elements, the operation fails.

Some operations (like frame_dig and proto) could fail because of an attempt to access above the current Stack.

While every element of the Stack is restricted to the types uint64 and bytes, the values of these types may be known to be bounded.

The most common bounded types are named to provide more semantic information in the documentation and as type checking during assembly time to provide more informative error messages.

NAME BOUND AVM TYPE
[]byte len(x)≤4096 []byte
address len(x)=32 []byte
any any
bigint len(x)≤64 []byte
bool x≤1 uint64
boxName 1≤len(x)≤64 []byte
method len(x)=4 []byte
none none
stateKey len(x)≤64 []byte
uint64 x≤18446744073709551615 uint64