Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate TEAL and AVM versioning #441

Merged
merged 16 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ PyTeal provides high level, functional programming style abstractions over TEAL

PyTeal requires Python version >= 3.10.

To manage multiple Python versions use tooling like [pyenv](https://github.com/pyenv/pyenv).
If your operating system (OS) Python version < 3.10, we recommend:
* Rather than override the OS Python version, install Python >= 3.10 alongside the OS Python version.
* Use [pyenv](https://github.com/pyenv/pyenv#installation) or similar tooling to manage multiple Python versions.

### Recommended: Install from PyPi

Expand Down
176 changes: 88 additions & 88 deletions docs/accessing_transaction_field.rst

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/arithmetic_expression.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The associativity and precedence of the overloaded Python arithmetic operators a
Byteslice Arithmetic
--------------------

Byteslice arithemetic is available for Teal V4 and above.
Byteslice arithemetic is available for AVM V4 and above.
jdtzmn marked this conversation as resolved.
Show resolved Hide resolved
Byteslice arithmetic operators allow up to 512-bit arithmetic.
In PyTeal, byteslice arithmetic expressions include
:code:`TealType.Bytes` values as arguments (with the exception of :code:`BytesZero`)
Expand Down
2 changes: 1 addition & 1 deletion docs/byte_expression.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Extract
~~~~~~~

.. note::
:code:`Extract` is only available in TEAL version 5 or higher.
:code:`Extract` is only available in program version 5 or higher.

The :any:`Extract` expression can extract part of a byte slice given the start index and length. For
example:
Expand Down
8 changes: 4 additions & 4 deletions docs/control_structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Exiting the Program: :code:`Approve` and :code:`Reject`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. note::
The :code:`Approve` and :code:`Reject` expressions are only available in TEAL version 4 or higher.
The :code:`Approve` and :code:`Reject` expressions are only available in program version 4 or higher.
Prior to this, :code:`Return(Int(1))` is equivalent to :code:`Approve()` and :code:`Return(Int(0))`
is equivalent to :code:`Reject()`.

Expand Down Expand Up @@ -166,7 +166,7 @@ Looping: :code:`While`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. note::
This expression is only available in TEAL version 4 or higher.
This expression is only available in program version 4 or higher.

The :any:`While` expression can be used to create simple loops in PyTeal. The syntax of :code:`While` is:

Expand Down Expand Up @@ -203,7 +203,7 @@ Looping: :code:`For`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. note::
This expression is only available in TEAL version 4 or higher.
This expression is only available in program version 4 or higher.

Similar to :code:`While`, the :any:`For` expression can also be used to create loops in PyTeal. The
syntax of :code:`For` is:
Expand Down Expand Up @@ -294,7 +294,7 @@ Subroutines
~~~~~~~~~~~

.. note::
Subroutines are only available in TEAL version 4 or higher.
Subroutines are only available in program version 4 or higher.

A subroutine is section of code that can be called multiple times from within a program. Subroutines are PyTeal's equivalent to functions. Subroutine constraints include:

Expand Down
4 changes: 2 additions & 2 deletions docs/crypto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Operator Cost Description
:code:`EcdsaRecover(c, d, id, r, s)` `2000` produces the public key associated with the signature :code:`(r, s)` and recovery id :code:`id`
==================================== ========= ==================================================================================================================

\* :code:`Ed25519Verify` is only available in signature mode up to version 4 of TEAL. From version 5 upwards, `Ed25519Verify` can be used in any mode.
\* :code:`Ed25519Verify` is only available in signature mode up to version 4 of AVM. From version 5 upwards, `Ed25519Verify` can be used in any mode.

Note the cost amount is accurate for version 2 of TEAL and higher. The parameter :code:`c` in the ECDSA expressions defined above represents the elliptic curve
Note the cost amount is accurate for version 2 of AVM and higher. The parameter :code:`c` in the ECDSA expressions defined above represents the elliptic curve
specification to be used (for example, :code:`Secp256k1`).

These cryptographic primitives cover the most used ones in blockchains and cryptocurrencies. For example, Bitcoin uses `SHA-256` for creating Bitcoin addresses;
Expand Down
7 changes: 7 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Install PyTeal
==============

PyTeal requires Python version >= 3.10.

If your operating system (OS) Python version < 3.10, we recommend:

* Rather than override the OS Python version, install Python >= 3.10 alongside the OS Python version.
* Use `pyenv <https://github.com/pyenv/pyenv#installation>`_ or similar tooling to manage multiple Python versions.

The easiest way of installing PyTeal is using :code:`pip` : ::

$ pip3 install pyteal
Expand Down
2 changes: 1 addition & 1 deletion docs/loading_group_transaction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Loading Values from Group Transactions
======================================

Since TEAL version 4 and above, programs can load values from transactions within an atomic
Since program version 4 and above, programs can load values from transactions within an atomic
group transaction. For instance, you can import values from the scratch space of another
application call, and you can access the generated ID of a new application or asset.
These operations are only permitted in application mode.
Expand Down
18 changes: 9 additions & 9 deletions docs/versions.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.. _versions:

TEAL Versions
AVM Versions
=============

Each version of PyTeal compiles contracts for a specific version of TEAL. Newer versions of TEAL
Each version of PyTeal compiles contracts for a specific version of AVM. Newer versions of the AVM
jdtzmn marked this conversation as resolved.
Show resolved Hide resolved
introduce new opcodes and transaction fields, so PyTeal must be updated to support these new
features. Below is a table which shows the relationship between TEAL and PyTeal versions.
features. Below is a table which shows the relationship between AVM and PyTeal versions.

============ ==============
TEAL Version PyTeal Version
AVM Version PyTeal Version
============ ==============
1 <= 0.5.4
2 >= 0.6.0
Expand All @@ -18,14 +18,14 @@ TEAL Version PyTeal Version
6 >= 0.10.0
jdtzmn marked this conversation as resolved.
Show resolved Hide resolved
============ ==============

In order to support TEAL v2, PyTeal v0.6.0 breaks backward compatibility with v0.5.4. PyTeal
In order to support AVM v2, PyTeal v0.6.0 breaks backward compatibility with v0.5.4. PyTeal
programs written for PyTeal version 0.5.4 and below will not compile properly and most likely will
display an error of the form :code:`AttributeError: * object has no attribute 'teal'`.

**WARNING:** before updating PyTeal to a version with generates TEAL v2 contracts and fixing the
**WARNING:** before updating PyTeal to a version with generates AVM v2 contracts and fixing the
programs to use the global function :any:`compileTeal` rather the class method :code:`.teal()`, make
sure your program abides by the TEAL safety guidelines `<https://developer.algorand.org/docs/reference/teal/guidelines/>`_.
Changing a v1 TEAL program to a v2 TEAL program without any code changes is insecure because v2
TEAL programs allow rekeying. Specifically, you must add a check that the :code:`RekeyTo` property
sure your program abides by the AVM safety guidelines `<https://developer.algorand.org/docs/reference/teal/guidelines/>`_.
Changing a v1 AVM program to a v2 AVM program without any code changes is insecure because v2
AVM programs allow rekeying. Specifically, you must add a check that the :code:`RekeyTo` property
of any transaction is set to the zero address when updating an older PyTeal program from v0.5.4 and
below.
2 changes: 1 addition & 1 deletion examples/signature/factorizer_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def logicsig(a: int, p: int, q: int) -> Expr:
"""
Choices
* (a, p, q) = (1, 5, 7)
* compiling on TEAL version 5 and
* compiling on program version 5 and
* with assembleConstants = True
results in Logic-Sig Contract Account Address:
WO3TQD3WBSDKB6WEHUMSEBFH53GZVVXYGPWYDWKUZCKEXTVCDNDHJGG6II
Expand Down
6 changes: 6 additions & 0 deletions pyteal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
MAX_TEAL_VERSION,
MIN_TEAL_VERSION,
DEFAULT_TEAL_VERSION,
MAX_PROGRAM_VERSION,
MIN_PROGRAM_VERSION,
DEFAULT_PROGRAM_VERSION,
CompileOptions,
compileTeal,
OptimizeOptions,
Expand All @@ -27,6 +30,9 @@
"MAX_TEAL_VERSION",
"MIN_TEAL_VERSION",
"DEFAULT_TEAL_VERSION",
"MAX_PROGRAM_VERSION",
"MIN_PROGRAM_VERSION",
"DEFAULT_PROGRAM_VERSION",
"CompileOptions",
"compileTeal",
"OptimizeOptions",
Expand Down
6 changes: 6 additions & 0 deletions pyteal/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ from pyteal.compiler import (
MAX_TEAL_VERSION,
MIN_TEAL_VERSION,
DEFAULT_TEAL_VERSION,
MAX_PROGRAM_VERSION,
MIN_PROGRAM_VERSION,
DEFAULT_PROGRAM_VERSION,
CompileOptions,
compileTeal,
OptimizeOptions,
Expand Down Expand Up @@ -67,6 +70,7 @@ __all__ = [
"Concat",
"Cond",
"Continue",
"DEFAULT_PROGRAM_VERSION",
"DEFAULT_TEAL_VERSION",
"Div",
"Divw",
Expand Down Expand Up @@ -115,7 +119,9 @@ __all__ = [
"Log",
"Lt",
"MAX_GROUP_SIZE",
"MAX_PROGRAM_VERSION",
"MAX_TEAL_VERSION",
"MIN_PROGRAM_VERSION",
"MIN_TEAL_VERSION",
"MaybeValue",
"MethodSignature",
Expand Down
12 changes: 6 additions & 6 deletions pyteal/ast/acct_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pyteal as pt

options = pt.CompileOptions()
teal4Options = pt.CompileOptions(version=4)
teal5Options = pt.CompileOptions(version=5)
teal6Options = pt.CompileOptions(version=6)
avm4Options = pt.CompileOptions(version=4)
avm5Options = pt.CompileOptions(version=5)
avm6Options = pt.CompileOptions(version=6)


def test_acct_param_balance_valid():
Expand All @@ -21,7 +21,7 @@ def test_acct_param_balance_valid():
]
)

actual, _ = expr.__teal__(teal6Options)
actual, _ = expr.__teal__(avm6Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand All @@ -44,7 +44,7 @@ def test_acct_param_min_balance_valid():
]
)

actual, _ = expr.__teal__(teal6Options)
actual, _ = expr.__teal__(avm6Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand All @@ -67,7 +67,7 @@ def test_acct_param_auth_addr_valid():
]
)

actual, _ = expr.__teal__(teal6Options)
actual, _ = expr.__teal__(avm6Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand Down
8 changes: 4 additions & 4 deletions pyteal/ast/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def clearStateProgram(cls, app: Expr) -> MaybeValue:
)

@classmethod
def globalNumUnit(cls, app: Expr) -> MaybeValue:
def globalNumUint(cls, app: Expr) -> MaybeValue:
"""Get the number of uint64 values allowed in Global State for the application.

Args:
Expand All @@ -260,7 +260,7 @@ def globalNumUnit(cls, app: Expr) -> MaybeValue:
return MaybeValue(
Op.app_params_get,
TealType.uint64,
immediate_args=["AppGlobalNumUnit"],
immediate_args=["AppGlobalNumUint"],
args=[app],
)

Expand All @@ -281,7 +281,7 @@ def globalNumByteSlice(cls, app: Expr) -> MaybeValue:
)

@classmethod
def localNumUnit(cls, app: Expr) -> MaybeValue:
def localNumUint(cls, app: Expr) -> MaybeValue:
"""Get the number of uint64 values allowed in Local State for the application.

Args:
Expand All @@ -292,7 +292,7 @@ def localNumUnit(cls, app: Expr) -> MaybeValue:
return MaybeValue(
Op.app_params_get,
TealType.uint64,
immediate_args=["AppLocalNumUnit"],
immediate_args=["AppLocalNumUint"],
args=[app],
)

Expand Down
Loading