Skip to content

Commit

Permalink
Merge Teal7 to AVM8, and consolidate Teal to AVM versioning (#470)
Browse files Browse the repository at this point in the history
* swapping base64 modes to match the rest (#446)

* Merge master into teal7 (#450)

* AVM 7:  Address integration branch feedback (#452)

* Add Execute Method (#444)

* adding execute method to allow omission of begin/submit for common use case

* exec docstring

* update testcase

Co-authored-by: Hang Su <hang.su@algorand.com>

* Merge branch 'master' into teal7 (#463)

* fix misspelling of uint (#431)

* fix misspelling of uint

* Clarify minimum Python version management docs (#435)

* Foreign prefix on App and Asset arrays (#440)

* replacing foreignapps with applications

* fix assets as well

* Add Execute Method (#444)

* adding execute method to allow omission of begin/submit for common use case

* exec docstring

* update testcase

Co-authored-by: Hang Su <hang.su@algorand.com>

Co-authored-by: Ben Guidarelli <ben.guidarelli@gmail.com>
Co-authored-by: Hang Su <hang.su@algorand.com>

* Consolidate TEAL and AVM versioning (#441)

* fix misspelling of uint (#431)

* fix misspelling of uint

* Clarify minimum Python version management docs (#435)

* Convert TEAL version references to program version by hand

* Replace `teal#Options` with `avm#Options`

* Deprecate `*_TEAL_VERSION` in favor of `*_PROGRAM_VERSION`

* Fix docs typo

Co-authored-by: Michael Diamant <michaeldiamant@users.noreply.github.com>

* Minor `versions.rst` changes

* Fix `verifyTealVersion` in new opcode files

* Fix linter errors

* Fix language discrepencies introduced by the merge

* Remove incorrect avm replacement

* Fix inconsistent language introduced by merge

Co-authored-by: Ben Guidarelli <ben.guidarelli@gmail.com>
Co-authored-by: Michael Diamant <michaeldiamant@users.noreply.github.com>

* max program version

Co-authored-by: Ben Guidarelli <ben.guidarelli@gmail.com>
Co-authored-by: Michael Diamant <michaeldiamant@users.noreply.github.com>
Co-authored-by: Jacob Daitzman <jdtzmn@gmail.com>
  • Loading branch information
4 people authored Jul 22, 2022
1 parent 7c24013 commit ba260e6
Show file tree
Hide file tree
Showing 60 changed files with 764 additions and 687 deletions.
184 changes: 91 additions & 93 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 arithmetic is available for AVM V4 and above.
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 @@ -24,9 +24,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
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
19 changes: 10 additions & 9 deletions docs/versions.rst
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
.. _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 AVM version. Newer versions of the AVM
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
3 >= 0.7.0
4 >= 0.8.0
5 >= 0.9.0
6 >= 0.10.0
7 >= 0.14.0
============ ==============

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 @@ -76,6 +79,7 @@ __all__ = [
"Concat",
"Cond",
"Continue",
"DEFAULT_PROGRAM_VERSION",
"DEFAULT_TEAL_VERSION",
"Div",
"Divw",
Expand Down Expand Up @@ -126,7 +130,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
24 changes: 12 additions & 12 deletions pyteal/ast/app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pyteal as pt

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


def test_on_complete():
Expand Down Expand Up @@ -258,7 +258,7 @@ def test_global_get_ex_direct_ref():
]
)

actual, _ = expr.__teal__(teal4Options)
actual, _ = expr.__teal__(avm4Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand Down Expand Up @@ -439,7 +439,7 @@ def test_app_param_approval_program_valid():
]
)

actual, _ = expr.__teal__(teal5Options)
actual, _ = expr.__teal__(avm5Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand Down Expand Up @@ -467,7 +467,7 @@ def test_app_param_clear_state_program_valid():
]
)

actual, _ = expr.__teal__(teal5Options)
actual, _ = expr.__teal__(avm5Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand Down Expand Up @@ -495,7 +495,7 @@ def test_app_param_global_num_uint_valid():
]
)

actual, _ = expr.__teal__(teal5Options)
actual, _ = expr.__teal__(avm5Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand Down Expand Up @@ -523,7 +523,7 @@ def test_app_param_global_num_byte_slice_valid():
]
)

actual, _ = expr.__teal__(teal5Options)
actual, _ = expr.__teal__(avm5Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand Down Expand Up @@ -551,7 +551,7 @@ def test_app_param_local_num_uint_valid():
]
)

actual, _ = expr.__teal__(teal5Options)
actual, _ = expr.__teal__(avm5Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand Down Expand Up @@ -579,7 +579,7 @@ def test_app_param_local_num_byte_slice_valid():
]
)

actual, _ = expr.__teal__(teal5Options)
actual, _ = expr.__teal__(avm5Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand Down Expand Up @@ -607,7 +607,7 @@ def test_app_param_extra_programs_page_valid():
]
)

actual, _ = expr.__teal__(teal5Options)
actual, _ = expr.__teal__(avm5Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand Down Expand Up @@ -635,7 +635,7 @@ def test_app_param_creator_valid():
]
)

actual, _ = expr.__teal__(teal5Options)
actual, _ = expr.__teal__(avm5Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand Down Expand Up @@ -663,7 +663,7 @@ def test_app_param_address_valid():
]
)

actual, _ = expr.__teal__(teal5Options)
actual, _ = expr.__teal__(avm5Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

Expand Down
8 changes: 4 additions & 4 deletions pyteal/ast/arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pyteal.types import TealType, require_type
from pyteal.ir import TealOp, Op, TealBlock
from pyteal.errors import TealInputError, verifyTealVersion
from pyteal.errors import TealInputError, verifyProgramVersion
from pyteal.ast.expr import Expr
from pyteal.ast.leafexpr import LeafExpr

Expand All @@ -21,7 +21,7 @@ def __init__(self, index: Union[int, Expr]) -> None:
Args:
index: The index of the argument to get. The index must be between 0 and 255 inclusive.
Starting in TEAL v5, the index may be a PyTeal expression that evaluates to uint64.
Starting in AVM v5, the index may be a PyTeal expression that evaluates to uint64.
"""
super().__init__()

Expand All @@ -38,10 +38,10 @@ def __teal__(self, options: "CompileOptions"):
op = TealOp(self, Op.arg, self.index)
return TealBlock.FromOp(options, op)

verifyTealVersion(
verifyProgramVersion(
Op.args.min_version,
options.version,
"TEAL version too low to use dynamic indexes with Arg",
"Program version too low to use dynamic indexes with Arg",
)

op = TealOp(self, Op.args)
Expand Down
12 changes: 6 additions & 6 deletions pyteal/ast/arg_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import pyteal as pt

teal2Options = pt.CompileOptions(version=2)
teal4Options = pt.CompileOptions(version=4)
teal5Options = pt.CompileOptions(version=5)
avm2Options = pt.CompileOptions(version=2)
avm4Options = pt.CompileOptions(version=4)
avm5Options = pt.CompileOptions(version=5)


def test_arg_static():
Expand All @@ -15,7 +15,7 @@ def test_arg_static():

expected = pt.TealSimpleBlock([pt.TealOp(expr, pt.Op.arg, i)])

actual, _ = expr.__teal__(teal2Options)
actual, _ = expr.__teal__(avm2Options)
assert actual == expected


Expand All @@ -29,14 +29,14 @@ def test_arg_dynamic():
[pt.TealOp(i, pt.Op.int, 7), pt.TealOp(expr, pt.Op.args)]
)

actual, _ = expr.__teal__(teal5Options)
actual, _ = expr.__teal__(avm5Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

assert actual == expected

with pytest.raises(pt.TealInputError):
expr.__teal__(teal4Options)
expr.__teal__(avm4Options)


def test_arg_invalid():
Expand Down
Loading

0 comments on commit ba260e6

Please sign in to comment.