ethereum.shanghai.vm.stackethereum.cancun.vm.stack

Ethereum Virtual Machine (EVM) Stack ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. contents:: Table of Contents :backlinks: none :local:

Introduction

Implementation of the stack operators for the EVM.

pop

Pops the top item off of stack.

Parameters

stack : EVM stack.

Returns

value : U256 The top element on the stack.

def pop(stack: List[U256]) -> U256:
23
    """
24
    Pops the top item off of `stack`.
25
26
    Parameters
27
    ----------
28
    stack :
29
        EVM stack.
30
31
    Returns
32
    -------
33
    value : `U256`
34
        The top element on the stack.
35
36
    """
37
    if len(stack) == 0:
38
        raise StackUnderflowError
39
40
    return stack.pop()

push

Pushes value onto stack.

Parameters

stack : EVM stack.

value : Item to be pushed onto stack.

def push(stack: List[U256], ​​value: U256) -> None:
44
    """
45
    Pushes `value` onto `stack`.
46
47
    Parameters
48
    ----------
49
    stack :
50
        EVM stack.
51
52
    value :
53
        Item to be pushed onto `stack`.
54
55
    """
56
    if len(stack) == 1024:
57
        raise StackOverflowError
58
59
    return stack.append(value)