Skip to content

Commit

Permalink
AVM 7 (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin authored Aug 1, 2022
1 parent d8b65b7 commit 79df68b
Show file tree
Hide file tree
Showing 65 changed files with 2,154 additions and 694 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# Unreleased
## Added

## Fixed

## Changed

# 0.15.0
## Added
* Support AVM 7 updates:
* New opcodes:
* `base64_decode` ([#418](https://github.com/algorand/pyteal/pull/418))
* `block` ([#415](https://github.com/algorand/pyteal/pull/415))
* `ed25519verify_bare` ([#426](https://github.com/algorand/pyteal/pull/426))
* `json_ref` ([#417](https://github.com/algorand/pyteal/pull/417))
* `replace2`, `replace3` ([#413](https://github.com/algorand/pyteal/pull/413))
* `sha3_256` ([#425](https://github.com/algorand/pyteal/pull/425))
* `vrf_verify` ([#419](https://github.com/algorand/pyteal/pull/419))
* `Secp256r1` curve for ECDSA opcodes ([#423](https://github.com/algorand/pyteal/pull/423))
* Program page transaction field access ([#412](https://github.com/algorand/pyteal/pull/412))

# 0.14.0

## Added
Expand Down
187 changes: 95 additions & 92 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
8 changes: 5 additions & 3 deletions docs/crypto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ Below is how you express cryptographic primitives in PyTeal:
Operator Cost Description
==================================== ========= ==================================================================================================================
:code:`Sha256(e)` `35` `SHA-256` hash function, produces 32 bytes
:code:`Sha3_256(e)` `130` `SHA3-256` hash function, produces 32 bytes
:code:`Keccak256(e)` `130` `Keccak-256` hash funciton, produces 32 bytes
:code:`Sha512_256(e)` `45` `SHA-512/256` hash function, produces 32 bytes
:code:`Ed25519Verify(d, s, p)` `1900`\* `1` if :code:`s` is the signature of :code:`d` signed by the private key corresponding to the public key :code:`p`, else `0`
:code:`Ed25519Verify(d, s, p)` `1900`\* `1` if :code:`s` is the signature of the concatenation :code:`("ProgData" + hash_of_current_program + d)` signed by the private key corresponding to the public key :code:`p`, else `0`
:code:`Ed25519Verify_Bare(d, s, p)` `1900` `1` if :code:`s` is the signature of :code:`d` signed by the private key corresponding to the public key :code:`p`, else `0`
:code:`EcdsaVerify(c, d, r, s, pk)` `1700` `1` if :code:`(r, s)` is the signature of :code:`d` by private key corresponding to public key :code:`pk`, else 0
:code:`EcdsaDecompress(c, short_pk)` `650` produces the decompressed public key associated with the compressed public key :code:`short_pk`
: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
15 changes: 8 additions & 7 deletions docs/versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
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.15.0
============ ==============

.. _version pragmas:
Expand All @@ -38,14 +39,14 @@ constraint to only a section of the AST.
PyTeal v0.5.4 and Below
-----------------------

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::
If you are updating from a v1 TEAL program, make
If you are updating from a v1 AVM program, 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
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 @@ -7,6 +7,9 @@
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 @@ -34,6 +37,9 @@
"MAX_TEAL_VERSION",
"MIN_TEAL_VERSION",
"DEFAULT_TEAL_VERSION",
"MAX_PROGRAM_VERSION",
"MIN_PROGRAM_VERSION",
"DEFAULT_PROGRAM_VERSION",
"CompileOptions",
"pragma",
"compileTeal",
Expand Down
13 changes: 13 additions & 0 deletions pyteal/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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 @@ -50,12 +53,14 @@ __all__ = [
"AssetParamObject",
"Balance",
"BareCallActions",
"Base64Decode",
"BinaryExpr",
"BitLen",
"BitwiseAnd",
"BitwiseNot",
"BitwiseOr",
"BitwiseXor",
"Block",
"Break",
"Btoi",
"Bytes",
Expand All @@ -81,6 +86,7 @@ __all__ = [
"Concat",
"Cond",
"Continue",
"DEFAULT_PROGRAM_VERSION",
"DEFAULT_TEAL_VERSION",
"Div",
"Divw",
Expand All @@ -90,6 +96,7 @@ __all__ = [
"EcdsaRecover",
"EcdsaVerify",
"Ed25519Verify",
"Ed25519Verify_Bare",
"EnumInt",
"Eq",
"Err",
Expand Down Expand Up @@ -121,6 +128,7 @@ __all__ = [
"InnerTxnGroup",
"Int",
"Itob",
"JsonRef",
"Keccak256",
"LabelReference",
"Le",
Expand All @@ -129,8 +137,10 @@ __all__ = [
"Log",
"Lt",
"MAX_GROUP_SIZE",
"MAX_PROGRAM_VERSION",
"MAX_TEAL_VERSION",
"METHOD_ARG_NUM_CUTOFF",
"MIN_PROGRAM_VERSION",
"MIN_TEAL_VERSION",
"MaybeValue",
"MethodConfig",
Expand All @@ -157,6 +167,7 @@ __all__ = [
"Pragma",
"RETURN_HASH_PREFIX",
"Reject",
"Replace",
"Return",
"Router",
"ScratchIndex",
Expand All @@ -169,6 +180,7 @@ __all__ = [
"SetBit",
"SetByte",
"Sha256",
"Sha3_256",
"Sha512_256",
"ShiftLeft",
"ShiftRight",
Expand Down Expand Up @@ -202,6 +214,7 @@ __all__ = [
"TxnType",
"TxnaExpr",
"UnaryExpr",
"VrfVerify",
"While",
"WideRatio",
"abi",
Expand Down
23 changes: 22 additions & 1 deletion pyteal/ast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Txn,
)
from pyteal.ast.gtxn import GtxnExpr, GtxnaExpr, TxnGroup, Gtxn
from pyteal.ast.block import Block
from pyteal.ast.gaid import GeneratedID
from pyteal.ast.gitxn import Gitxn, GitxnExpr, GitxnaExpr, InnerTxnGroup
from pyteal.ast.gload import ImportScratchValue
Expand Down Expand Up @@ -51,6 +52,7 @@
BitLen,
Sha256,
Sha512_256,
Sha3_256,
Keccak256,
Not,
BitwiseNot,
Expand Down Expand Up @@ -102,10 +104,22 @@
ExtractUint32,
ExtractUint64,
)
from pyteal.ast.base64decode import Base64Decode

# ternary ops
from pyteal.ast.ternaryexpr import Divw, Ed25519Verify, SetBit, SetByte
from pyteal.ast.ternaryexpr import (
Divw,
Ed25519Verify,
Ed25519Verify_Bare,
SetBit,
SetByte,
)
from pyteal.ast.substring import Substring, Extract, Suffix
from pyteal.ast.replace import Replace
from pyteal.ast.jsonref import JsonRef

# quaternary ops
from pyteal.ast.vrfverify import VrfVerify

# more ops
from pyteal.ast.naryexpr import NaryExpr, Add, And, Mul, Or, Concat
Expand Down Expand Up @@ -175,6 +189,7 @@
"GtxnaExpr",
"TxnGroup",
"Gtxn",
"Block",
"GeneratedID",
"ImportScratchValue",
"Global",
Expand Down Expand Up @@ -208,6 +223,7 @@
"BitLen",
"Sha256",
"Sha512_256",
"Sha3_256",
"Keccak256",
"Not",
"BitwiseNot",
Expand Down Expand Up @@ -237,6 +253,7 @@
"GetBit",
"GetByte",
"Ed25519Verify",
"Ed25519Verify_Bare",
"Substring",
"Extract",
"Suffix",
Expand Down Expand Up @@ -292,6 +309,8 @@
"ExtractUint16",
"ExtractUint32",
"ExtractUint64",
"Replace",
"Base64Decode",
"Log",
"While",
"For",
Expand All @@ -307,4 +326,6 @@
"EcdsaVerify",
"EcdsaDecompress",
"EcdsaRecover",
"JsonRef",
"VrfVerify",
]
Loading

0 comments on commit 79df68b

Please sign in to comment.