├── .flake8 ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── build.yml │ └── nightly.yml ├── .gitignore ├── .readthedocs.yaml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── README.md ├── docker-compose.yml ├── docs ├── Makefile ├── README.md ├── abi.rst ├── accessing_transaction_field.rst ├── api.rst ├── arithmetic_expression.rst ├── assets.rst ├── byte_expression.rst ├── compiler_optimization.rst ├── conf.py ├── control_structures.rst ├── crypto.rst ├── data_type.rst ├── examples.rst ├── index.rst ├── installation.rst ├── loading_group_transaction.rst ├── make.bat ├── opup.rst ├── overview.rst ├── pyteal.png ├── pyteal.svg ├── requirements.txt ├── scratch.rst ├── sourcemap.rst ├── state.rst └── versions.rst ├── examples ├── __init__.py ├── application │ ├── __init__.py │ ├── abi │ │ ├── __init__.py │ │ ├── algobank.json │ │ ├── algobank.py │ │ ├── algobank_approval.teal │ │ └── algobank_clear_state.teal │ ├── asset.py │ ├── opup.py │ ├── security_token.py │ ├── sourcemap.py │ ├── teal │ │ ├── sourcemap.teal │ │ └── sourcemap_annotated.teal │ ├── vote.py │ └── vote_deploy.py └── signature │ ├── __init__.py │ ├── atomic_swap.py │ ├── atomic_swap.teal │ ├── basic.py │ ├── basic.teal │ ├── dutch_auction.py │ ├── dutch_auction.teal │ ├── dutch_auction_annotated.teal │ ├── factorizer_game.py │ ├── periodic_payment.py │ ├── periodic_payment.teal │ ├── periodic_payment_deploy.py │ ├── recurring_swap.py │ ├── recurring_swap.teal │ ├── recurring_swap_deploy.py │ ├── split.py │ └── split.teal ├── feature_gates └── __init__.py ├── mypy.ini ├── pyteal ├── __init__.py ├── __init__.pyi ├── ast │ ├── __init__.py │ ├── abi │ │ ├── __init__.py │ │ ├── address.py │ │ ├── address_test.py │ │ ├── array_base.py │ │ ├── array_base_test.py │ │ ├── array_dynamic.py │ │ ├── array_dynamic_test.py │ │ ├── array_static.py │ │ ├── array_static_test.py │ │ ├── bool.py │ │ ├── bool_test.py │ │ ├── method_return.py │ │ ├── method_return_test.py │ │ ├── reference_type.py │ │ ├── reference_type_test.py │ │ ├── string.py │ │ ├── string_test.py │ │ ├── transaction.py │ │ ├── transaction_test.py │ │ ├── tuple.py │ │ ├── tuple_test.py │ │ ├── type.py │ │ ├── type_test.py │ │ ├── uint.py │ │ ├── uint_test.py │ │ ├── util.py │ │ └── util_test.py │ ├── abstractvar.py │ ├── acct.py │ ├── acct_test.py │ ├── addr.py │ ├── addr_test.py │ ├── app.py │ ├── app_test.py │ ├── arg.py │ ├── arg_test.py │ ├── array.py │ ├── assert_.py │ ├── assert_test.py │ ├── asset.py │ ├── asset_test.py │ ├── base64decode.py │ ├── base64decode_test.py │ ├── binaryexpr.py │ ├── binaryexpr_test.py │ ├── block.py │ ├── block_test.py │ ├── box.py │ ├── box_test.py │ ├── break_.py │ ├── break_test.py │ ├── bytes.py │ ├── bytes_test.py │ ├── comment.py │ ├── comment_test.py │ ├── cond.py │ ├── cond_test.py │ ├── continue_.py │ ├── continue_test.py │ ├── ec.py │ ├── ec_test.py │ ├── ecdsa.py │ ├── ecdsa_test.py │ ├── err.py │ ├── err_test.py │ ├── expr.py │ ├── for_.py │ ├── for_test.py │ ├── frame.py │ ├── frame_test.py │ ├── gaid.py │ ├── gaid_test.py │ ├── gitxn.py │ ├── gitxn_test.py │ ├── gload.py │ ├── gload_test.py │ ├── global_.py │ ├── global_test.py │ ├── gtxn.py │ ├── gtxn_test.py │ ├── if_.py │ ├── if_test.py │ ├── int.py │ ├── int_test.py │ ├── itxn.py │ ├── itxn_test.py │ ├── jsonref.py │ ├── jsonref_test.py │ ├── leafexpr.py │ ├── maybe.py │ ├── maybe_test.py │ ├── methodsig.py │ ├── methodsig_test.py │ ├── mimc.py │ ├── mimc_test.py │ ├── multi.py │ ├── multi_test.py │ ├── naryexpr.py │ ├── naryexpr_test.py │ ├── nonce.py │ ├── nonce_test.py │ ├── opup.py │ ├── opup_test.py │ ├── pragma.py │ ├── pragma_test.py │ ├── replace.py │ ├── replace_test.py │ ├── return_.py │ ├── return_test.py │ ├── router.py │ ├── router_test.py │ ├── scratch.py │ ├── scratch_test.py │ ├── scratchvar.py │ ├── scratchvar_test.py │ ├── seq.py │ ├── seq_test.py │ ├── stake.py │ ├── stake_test.py │ ├── subroutine.py │ ├── subroutine_test.py │ ├── substring.py │ ├── substring_test.py │ ├── ternaryexpr.py │ ├── ternaryexpr_test.py │ ├── tmpl.py │ ├── tmpl_test.py │ ├── txn.py │ ├── txn_test.py │ ├── unaryexpr.py │ ├── unaryexpr_test.py │ ├── voter.py │ ├── voter_test.py │ ├── vrfverify.py │ ├── vrfverify_test.py │ ├── while_.py │ ├── while_test.py │ └── widemath.py ├── compiler │ ├── __init__.py │ ├── compiler.py │ ├── compiler_test.py │ ├── constants.py │ ├── constants_test.py │ ├── flatten.py │ ├── flatten_test.py │ ├── optimizer │ │ ├── __init__.py │ │ ├── optimizer.py │ │ └── optimizer_test.py │ ├── scratchslots.py │ ├── scratchslots_test.py │ ├── sort.py │ ├── sort_test.py │ ├── sourcemap.py │ ├── subroutines.py │ └── subroutines_test.py ├── config.py ├── errors.py ├── ir │ ├── __init__.py │ ├── labelref.py │ ├── ops.py │ ├── tealblock.py │ ├── tealblock_test.py │ ├── tealcomponent.py │ ├── tealcomponent_test.py │ ├── tealconditionalblock.py │ ├── tealconditionalblock_test.py │ ├── teallabel.py │ ├── tealop.py │ ├── tealpragma.py │ ├── tealpragma_test.py │ ├── tealsimpleblock.py │ └── tealsimpleblock_test.py ├── pragma │ ├── __init__.py │ ├── pragma.py │ └── pragma_test.py ├── py.typed ├── stack_frame.py ├── stack_frame_test.py ├── types.py ├── types_test.py └── util.py ├── pytest.ini ├── release-process.md ├── requirements.txt ├── scripts └── generate_init.py ├── setup.py └── tests ├── __init__.py ├── abi_roundtrip.py ├── blackbox.py ├── compile_asserts.py ├── integration ├── __init__.py ├── abi_roundtrip_test.py ├── abi_router_test.py ├── algod_test.py ├── ecdsa_test.py ├── graviton_abi_test.py ├── graviton_test.py ├── opup_test.py ├── pure_logicsig_test.py ├── sourcemap_monkey_integ_test.py └── teal │ ├── annotated │ ├── AlgoBank_h0_c0.tealf │ ├── AlgoBank_h0_c1.tealf │ ├── AlgoBank_h1_c0.tealf │ └── AlgoBank_h1_c1.tealf │ ├── roundtrip │ ├── app_roundtrip_((uint64,byte[],uint64[1]))_v6.teal │ ├── app_roundtrip_((uint64,byte[],uint64[1]))_v8.teal │ ├── app_roundtrip_()_v6.teal │ ├── app_roundtrip_()_v8.teal │ ├── app_roundtrip_(bool)[10]_v6.teal │ ├── app_roundtrip_(bool)[10]_v8.teal │ ├── app_roundtrip_(bool)_v6.teal │ ├── app_roundtrip_(bool)_v8.teal │ ├── app_roundtrip_(bool,address,(uint64,bool),byte[10],bool[4],uint64)_v6.teal │ ├── app_roundtrip_(bool,address,(uint64,bool),byte[10],bool[4],uint64)_v8.teal │ ├── app_roundtrip_(bool,byte)_v6.teal │ ├── app_roundtrip_(bool,byte)_v8.teal │ ├── app_roundtrip_(bool,byte,address,string)_v6.teal │ ├── app_roundtrip_(bool,byte,address,string)_v8.teal │ ├── app_roundtrip_(bool,byte,address,string,(address,(uint32,string[],bool[2],(byte),uint8)[2],string,bool[]))[]_2_v6.teal │ ├── app_roundtrip_(bool,byte,address,string,(address,(uint32,string[],bool[2],(byte),uint8)[2],string,bool[]))[]_2_v8.teal │ ├── app_roundtrip_(bool,byte,address,string,uint64)_v6.teal │ ├── app_roundtrip_(bool,byte,address,string,uint64)_v8.teal │ ├── app_roundtrip_(bool,uint64,uint32)_v6.teal │ ├── app_roundtrip_(bool,uint64,uint32)_v8.teal │ ├── app_roundtrip_(byte)_v6.teal │ ├── app_roundtrip_(byte)_v8.teal │ ├── app_roundtrip_(byte,bool,uint64)_v6.teal │ ├── app_roundtrip_(byte,bool,uint64)_v8.teal │ ├── app_roundtrip_(byte[4],(bool,bool),uint64,address)[]_7_v6.teal │ ├── app_roundtrip_(byte[4],(bool,bool),uint64,address)[]_7_v8.teal │ ├── app_roundtrip_(byte[],byte[3])_v6.teal │ ├── app_roundtrip_(byte[],byte[3])_v8.teal │ ├── app_roundtrip_(uint16)_v6.teal │ ├── app_roundtrip_(uint16)_v8.teal │ ├── app_roundtrip_(uint16,uint8,byte)_v6.teal │ ├── app_roundtrip_(uint16,uint8,byte)_v8.teal │ ├── app_roundtrip_(uint32)_v6.teal │ ├── app_roundtrip_(uint32)_v8.teal │ ├── app_roundtrip_(uint32,uint16,uint8)_v6.teal │ ├── app_roundtrip_(uint32,uint16,uint8)_v8.teal │ ├── app_roundtrip_(uint64)_v6.teal │ ├── app_roundtrip_(uint64)_v8.teal │ ├── app_roundtrip_(uint64,uint32,uint16)_v6.teal │ ├── app_roundtrip_(uint64,uint32,uint16)_v8.teal │ ├── app_roundtrip_(uint8)_v6.teal │ ├── app_roundtrip_(uint8)_v8.teal │ ├── app_roundtrip_(uint8,byte,bool)_v6.teal │ ├── app_roundtrip_(uint8,byte,bool)_v8.teal │ ├── app_roundtrip_address[]_10_v6.teal │ ├── app_roundtrip_address[]_10_v8.teal │ ├── app_roundtrip_address_v6.teal │ ├── app_roundtrip_address_v8.teal │ ├── app_roundtrip_bool[1]_v6.teal │ ├── app_roundtrip_bool[1]_v8.teal │ ├── app_roundtrip_bool[3][]_11_v6.teal │ ├── app_roundtrip_bool[3][]_11_v8.teal │ ├── app_roundtrip_bool[42]_v6.teal │ ├── app_roundtrip_bool[42]_v8.teal │ ├── app_roundtrip_bool[]_0_v6.teal │ ├── app_roundtrip_bool[]_0_v8.teal │ ├── app_roundtrip_bool[]_1_v6.teal │ ├── app_roundtrip_bool[]_1_v8.teal │ ├── app_roundtrip_bool[]_42_v6.teal │ ├── app_roundtrip_bool[]_42_v8.teal │ ├── app_roundtrip_bool_v6.teal │ ├── app_roundtrip_bool_v8.teal │ ├── app_roundtrip_byte[16]_v6.teal │ ├── app_roundtrip_byte[16]_v8.teal │ ├── app_roundtrip_byte[]_36_v6.teal │ ├── app_roundtrip_byte[]_36_v8.teal │ ├── app_roundtrip_byte_v6.teal │ ├── app_roundtrip_byte_v8.teal │ ├── app_roundtrip_string_0_v6.teal │ ├── app_roundtrip_string_0_v8.teal │ ├── app_roundtrip_string_13_v6.teal │ ├── app_roundtrip_string_13_v8.teal │ ├── app_roundtrip_string_1_v6.teal │ ├── app_roundtrip_string_1_v8.teal │ ├── app_roundtrip_uint16_v6.teal │ ├── app_roundtrip_uint16_v8.teal │ ├── app_roundtrip_uint32_v6.teal │ ├── app_roundtrip_uint32_v8.teal │ ├── app_roundtrip_uint64[1]_v6.teal │ ├── app_roundtrip_uint64[1]_v8.teal │ ├── app_roundtrip_uint64[42]_v6.teal │ ├── app_roundtrip_uint64[42]_v8.teal │ ├── app_roundtrip_uint64[]_0_v6.teal │ ├── app_roundtrip_uint64[]_0_v8.teal │ ├── app_roundtrip_uint64[]_1_v6.teal │ ├── app_roundtrip_uint64[]_1_v8.teal │ ├── app_roundtrip_uint64[]_42_v6.teal │ ├── app_roundtrip_uint64[]_42_v8.teal │ ├── app_roundtrip_uint64_v6.teal │ ├── app_roundtrip_uint64_v8.teal │ ├── app_roundtrip_uint8_v6.teal │ └── app_roundtrip_uint8_v8.teal │ └── stability │ ├── app_exp.teal │ ├── app_oldfac.teal │ ├── app_slow_fibonacci.teal │ ├── app_square.teal │ ├── app_square_byref.teal │ ├── app_string_mult.teal │ ├── app_swap.teal │ ├── lsig_exp.teal │ ├── lsig_oldfac.teal │ ├── lsig_slow_fibonacci.teal │ ├── lsig_square.teal │ ├── lsig_square_byref.teal │ ├── lsig_string_mult.teal │ └── lsig_swap.teal ├── mock_version.py ├── teal ├── __init__.py ├── router │ ├── nontriv_clear_approval_v6.teal │ ├── nontriv_clear_approval_v8.teal │ ├── nontriv_clear_clear_v6.teal │ ├── nontriv_clear_clear_v8.teal │ ├── questionableFP_approval_v8.teal │ ├── questionableFP_clear_v8.teal │ ├── questionable_approval_v6.teal │ ├── questionable_clear_v6.teal │ ├── yaccFP_approval_v8.teal │ ├── yaccFP_clear_v8.teal │ ├── yacc_approval_v6.teal │ └── yacc_clear_v6.teal ├── rps.py ├── rps.teal ├── rps_annotated.teal ├── user_guide_snippet_dynamic_scratch_var.teal └── user_guide_snippet_recursiveIsEven.teal └── unit ├── __init__.py ├── blackbox_test.py ├── compile_test.py ├── feature_gates_test.py ├── module_test.py ├── pass_by_ref_test.py ├── pre_v6_test.py ├── sourcemap_constructs311_test.py ├── sourcemap_constructs_allpy_test.py ├── sourcemap_monkey_raises_test.py ├── sourcemap_monkey_unit_test.py ├── sourcemap_rps_test.py ├── sourcemap_test.py ├── teal ├── abi │ ├── app_fn_0arg_0ret.teal │ ├── app_fn_0arg_uint64_ret.teal │ ├── app_fn_1arg_0ret.teal │ ├── app_fn_1arg_1ret.teal │ ├── app_fn_1tt_arg_uint64_ret.teal │ ├── app_fn_2arg_0ret.teal │ ├── app_fn_2mixed_arg_1ret.teal │ ├── app_fn_3mixed_args_0ret.teal │ ├── lsig_fn_0arg_0ret.teal │ ├── lsig_fn_0arg_uint64_ret.teal │ ├── lsig_fn_1arg_0ret.teal │ ├── lsig_fn_1arg_1ret.teal │ ├── lsig_fn_1tt_arg_uint64_ret.teal │ ├── lsig_fn_2arg_0ret.teal │ ├── lsig_fn_2mixed_arg_1ret.teal │ └── lsig_fn_3mixed_args_0ret.teal ├── blackbox │ ├── app_utest_any.teal │ ├── app_utest_any_args.teal │ ├── app_utest_bytes.teal │ ├── app_utest_bytes_args.teal │ ├── app_utest_int.teal │ ├── app_utest_int_args.teal │ ├── app_utest_noop.teal │ ├── app_utest_noop_args.teal │ ├── lsig_utest_any.teal │ ├── lsig_utest_any_args.teal │ ├── lsig_utest_bytes.teal │ ├── lsig_utest_bytes_args.teal │ ├── lsig_utest_int.teal │ ├── lsig_utest_int_args.teal │ ├── lsig_utest_noop.teal │ └── lsig_utest_noop_args.teal ├── pre_v6 │ ├── sub_even.teal │ ├── sub_fastfib.teal │ ├── sub_logcat.teal │ └── sub_slowfib.teal ├── unchanged │ ├── empty_scratches.teal │ ├── lots_o_vars.teal │ ├── sub_logcat_dynamic.teal │ ├── sub_mixed.teal │ ├── swapper.teal │ └── wilt_the_stilt.teal └── user_guide │ ├── user_guide_snippet_ABIReturnSubroutine.teal │ ├── user_guide_snippet_dynamic_scratch_var.teal │ └── user_guide_snippet_recursiveIsEven.teal └── user_guide_test.py /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | ignore = 3 | E203, 4 | E241, 5 | E302, 6 | E501, 7 | E741, 8 | W291, 9 | W503, 10 | 11 | per-file-ignores = 12 | examples/application/abi/algobank.py: F403, F405 13 | examples/application/asset.py: F403, F405 14 | examples/application/opup.py: F403, F405 15 | examples/application/security_token.py: F403, F405 16 | examples/application/vote.py: F403, F405 17 | examples/signature/atomic_swap.py: F403, F405 18 | examples/signature/basic.py: F403, F405 19 | examples/signature/dutch_auction.py: F403, F405 20 | examples/signature/periodic_payment_deploy.py: F403, F405 21 | examples/signature/periodic_payment.py: F403, F405 22 | examples/signature/recurring_swap_deploy.py: F403, F405 23 | examples/signature/recurring_swap.py: F403, F405 24 | examples/signature/split.py: F403, F405 25 | pyteal/__init__.py: F401, F403 26 | pyteal/ast/ec.py: E222 27 | pyteal/ast/seq.py: E704 28 | pyteal/compiler/flatten.py: F821 29 | pyteal/compiler/optimizer/__init__.py: F401 30 | pyteal/ir/ops.py: E221 31 | pyteal/ir/tealconditionalblock.py: F821 32 | pyteal/ir/tealsimpleblock.py: F821 33 | pyteal/stack_frame.py: F821 34 | tests/teal/rps.py: F401, F403, F405, I252 35 | tests/unit/module_test.py: F401, F403 36 | 37 | # from flake8-tidy-imports 38 | ban-relative-imports = true 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41C Bug report" 3 | about: Report a reproducible bug. 4 | title: '' 5 | labels: new-bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Subject of the issue 11 | 12 | 13 | 14 | ### Your environment 15 | 16 | 22 | 23 | ### Steps to reproduce 24 | 25 | 1. 26 | 2. 27 | 28 | ### Expected behaviour 29 | 30 | ### Actual behaviour 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F514 Feature Request" 3 | about: Suggestions for how we can improve the algorand platform. 4 | title: '' 5 | labels: new-feature-request 6 | assignees: '' 7 | --- 8 | 9 | ## Problem 10 | 11 | 12 | 13 | ## Solution 14 | 15 | 16 | 17 | ## Dependencies 18 | 19 | 20 | 21 | ## Urgency 22 | 23 | 24 | -------------------------------------------------------------------------------- /.github/workflows/nightly.yml: -------------------------------------------------------------------------------- 1 | name: "Nightly Build" 2 | on: 3 | schedule: 4 | - cron: "10 1 * * *" 5 | 6 | jobs: 7 | nightly-slow-unit-tests: 8 | name: build-test + nightly-slow if changes in the previous 24 hours 9 | runs-on: ubuntu-22.04 10 | container: python:${{ matrix.python }} 11 | strategy: 12 | matrix: 13 | python: ["3.10", "3.11", "3.12"] 14 | steps: 15 | - run: python3 --version 16 | - name: Check out code 17 | uses: actions/checkout@v3 18 | - name: Check for code changes 19 | id: check 20 | run: make check-code-changes 21 | - name: Install Python dependencies, Build, and Test 22 | if: ${{ env.should_run == 'true' }} 23 | run: make setup-build-test 24 | - name: Super slow unit tests 25 | if: ${{ env.should_run == 'true' }} 26 | run: make nightly-slow 27 | 28 | nightly-run-integration-tests: 29 | name: run-integration-tests if changes in the previous 24 hours 30 | runs-on: ubuntu-22.04 31 | strategy: 32 | matrix: 33 | python: ["3.10", "3.11", "3.12"] 34 | steps: 35 | - name: Check out code 36 | uses: actions/checkout@v3 37 | - name: Check for code changes 38 | id: check 39 | run: make check-code-changes 40 | - uses: actions/setup-python@v4 41 | if: ${{ env.should_run == 'true' }} 42 | with: 43 | python-version: "${{ matrix.python }}" 44 | - name: Test Python version 45 | if: ${{ env.should_run == 'true' }} 46 | run: | 47 | installed="$(python --version)" 48 | expected="${{ matrix.python }}" 49 | echo $installed 50 | [[ $installed =~ "Python ${expected}" ]] && echo "Configured Python" || (echo "Failed to configure Python" && exit 1) 51 | - name: Integration tests using algod 52 | if: ${{ env.should_run == 'true' }} 53 | run: make algod-integration 54 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Set the version of Python and other tools you might need 9 | build: 10 | os: ubuntu-22.04 11 | tools: 12 | python: "3.10" 13 | # You can also specify other tool versions: 14 | # nodejs: "16" 15 | # rust: "1.55" 16 | # golang: "1.17" 17 | 18 | # Build documentation in the docs/ directory with Sphinx 19 | sphinx: 20 | configuration: docs/conf.py 21 | fail_on_warning: true 22 | 23 | # If using Sphinx, optionally build your docs in additional formats such as PDF 24 | # formats: 25 | # - pdf 26 | 27 | # Optionally declare the Python requirements required to build your docs 28 | python: 29 | install: 30 | - requirements: docs/requirements.txt 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Algorand 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | algod: 5 | image: algorand/algod:master 6 | platform: linux/amd64 7 | ports: 8 | - "4001:8080" # algod 9 | - "4160:4160" # gossip 10 | - "9100:9100" # prometheus 11 | environment: 12 | - DEV_MODE=1 13 | - PROFILE=development 14 | # Can remove ADMIN_TOKEN if the code stops passing an auth token. The development profile 15 | # enables the DisableAPIAuth config option, however an unfortunate side effect of this 16 | # option is that requests will error if *any* auth token is passed. Issue: https://github.com/algorand/go-algorand/issues/5883 17 | - ADMIN_TOKEN=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 18 | healthcheck: 19 | test: curl -f http://localhost:8080/health 20 | interval: 2s 21 | retries: 30 22 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Docs 2 | 3 | `docs/` contains end user documentation geared towards writing smart contracts with PyTeal. The README explains how to edit docs. 4 | 5 | ## Local testing 6 | 7 | Pyteal uses [Sphinx](https://github.com/sphinx-doc/sphinx) to generate HTML from RST files. Test changes by generating HTML and viewing with a web browser. 8 | 9 | Here's the process: 10 | * Perform one-time environment setup: 11 | * Activate the top-level virtual environment. 12 | * Install dependencies: `pip install -r requirements.txt`. 13 | * Generate HTML docs: `make html`. 14 | * If successful, generated HTML is available in `docs/_build/html`. 15 | 16 | Additionally, each PR commit generates HTML docs via [Github Actions](../.github/workflows/build.yml). 17 | 18 | ## Releasing 19 | 20 | Production docs live at https://pyteal.readthedocs.io/en/stable/. 21 | -------------------------------------------------------------------------------- /docs/api.rst: -------------------------------------------------------------------------------- 1 | .. _api: 2 | 3 | PyTeal Package 4 | ============== 5 | 6 | .. automodule:: pyteal 7 | :members: 8 | :undoc-members: 9 | :imported-members: 10 | :special-members: __getitem__ 11 | :show-inheritance: 12 | 13 | .. data:: Txn 14 | :annotation: = 15 | 16 | The current transaction being evaluated. This is an instance of :any:`TxnObject`. 17 | 18 | .. data:: Gtxn 19 | :annotation: = 20 | 21 | The current group of transactions being evaluated. This is an instance of :any:`TxnGroup`. 22 | 23 | .. data:: InnerTxn 24 | :annotation: = 25 | 26 | The most recently submitted inner transaction. This is an instance of :any:`TxnObject`. 27 | 28 | If a transaction group was submitted most recently, then this will be the last transaction in that group. 29 | 30 | .. data:: Gitxn 31 | :annotation: = 32 | 33 | The most recently submitted inner transaction group. This is an instance of :any:`InnerTxnGroup`. 34 | 35 | If a single transaction was submitted most recently, then this will be a group of size 1. 36 | 37 | .. automodule:: pyteal.abi 38 | :members: 39 | :undoc-members: 40 | :imported-members: 41 | :special-members: __getitem__ 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /docs/byte_expression.rst: -------------------------------------------------------------------------------- 1 | .. _byte_expressions: 2 | 3 | Byte Operators 4 | ==================== 5 | 6 | TEAL byte slices are similar to strings and can be manipulated in the same way. 7 | 8 | Length 9 | ------ 10 | 11 | The length of a byte slice can be obtained using the :any:`Len` expression. For example: 12 | 13 | .. code-block:: python 14 | 15 | Len(Bytes("")) # will produce 0 16 | Len(Bytes("algorand")) # will produce 8 17 | 18 | Concatenation 19 | ------------- 20 | 21 | Byte slices can be combined using the :any:`Concat` expression. This expression takes at least 22 | two arguments and produces a new byte slice consisting of each argument, one after another. For 23 | example: 24 | 25 | .. code-block:: python 26 | 27 | Concat(Bytes("a"), Bytes("b"), Bytes("c")) # will produce "abc" 28 | 29 | Substring Extraction 30 | -------------------- 31 | 32 | Byte slices can be extracted from other byte slices using the :any:`Substring` and :any:`Extract` 33 | expressions. These expressions are extremely similar, except one specifies a substring by start and 34 | end indexes, while the other uses a start index and length. Use whichever makes sense for your 35 | application. 36 | 37 | Substring 38 | ~~~~~~~~~ 39 | 40 | The :any:`Substring` expression can extract part of a byte slice given start and end indices. For 41 | example: 42 | 43 | .. code-block:: python 44 | 45 | Substring(Bytes("algorand"), Int(2), Int(8)) # will produce "gorand" 46 | 47 | Extract 48 | ~~~~~~~ 49 | 50 | .. note:: 51 | :code:`Extract` is only available in program version 5 or higher. 52 | 53 | The :any:`Extract` expression can extract part of a byte slice given the start index and length. For 54 | example: 55 | 56 | .. code-block:: python 57 | 58 | Extract(Bytes("algorand"), Int(2), Int(6)) # will produce "gorand" 59 | 60 | Manipulating Individual Bits and Bytes 61 | -------------------------------------- 62 | 63 | The individual bits and bytes in a byte string can be extracted and changed. See :ref:`bit_and_byte_manipulation` 64 | for more information. 65 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | 13 | import os 14 | import sys 15 | 16 | sys.path.insert(0, os.path.abspath("..")) 17 | 18 | 19 | # -- Project information ----------------------------------------------------- 20 | 21 | project = "PyTeal" 22 | copyright = "2022, Algorand" 23 | author = "Algorand" 24 | 25 | 26 | # -- General configuration --------------------------------------------------- 27 | 28 | # Add any Sphinx extension module names here, as strings. They can be 29 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 30 | # ones. 31 | extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon"] 32 | source_suffix = [".rst"] 33 | master_doc = "index" 34 | 35 | napoleon_include_init_with_doc = True 36 | 37 | # Add any paths that contain templates here, relative to this directory. 38 | templates_path = ["_templates"] 39 | 40 | # List of patterns, relative to source directory, that match files and 41 | # directories to ignore when looking for source files. 42 | # This pattern also affects html_static_path and html_extra_path. 43 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] 44 | 45 | 46 | # -- Options for HTML output ------------------------------------------------- 47 | 48 | # The theme to use for HTML and HTML Help pages. See the documentation for 49 | # a list of builtin themes. 50 | # 51 | html_theme = "sphinx_rtd_theme" 52 | 53 | # Add any paths that contain custom static files (such as style sheets) here, 54 | # relative to this directory. They are copied after the builtin static files, 55 | # so a file named "default.css" will overwrite the builtin "default.css". 56 | # html_static_path = ["_static"] 57 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. PyTeal documentation master file, created by 2 | sphinx-quickstart on Fri Jan 31 14:27:13 2020. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | PyTeal: Algorand Smart Contracts in Python 7 | ========================================== 8 | 9 | PyTeal is a Python language binding for `Algorand Smart Contracts (ASC1s) `_. 10 | 11 | Algorand Smart Contracts are implemented using a new language that is stack-based, 12 | called `Transaction Execution Approval Language (TEAL) `_. 13 | 14 | However, TEAL is essentially an assembly language. 15 | With PyTeal, developers can express smart contract logic purely using Python. 16 | PyTeal provides high level, functional programming style abstactions over TEAL 17 | and does type checking at construction time. 18 | 19 | The :doc:`User Guide ` describes many useful features in PyTeal, and the complete documentation for every expression and operation can be found in the :doc:`PyTeal Package API documentation `. 20 | 21 | PyTeal **hasn't been security audited**. Use it at your own risk. 22 | 23 | .. toctree:: 24 | :maxdepth: 1 25 | :caption: Getting Started 26 | 27 | overview 28 | installation 29 | examples 30 | 31 | .. toctree:: 32 | :maxdepth: 1 33 | :caption: User Guide 34 | 35 | data_type 36 | arithmetic_expression 37 | byte_expression 38 | accessing_transaction_field 39 | crypto 40 | scratch 41 | loading_group_transaction 42 | control_structures 43 | state 44 | assets 45 | versions 46 | compiler_optimization 47 | sourcemap 48 | opup 49 | abi 50 | 51 | .. toctree:: 52 | :maxdepth: 3 53 | :caption: API 54 | 55 | api 56 | 57 | Indices and tables 58 | ================== 59 | 60 | * :ref:`genindex` 61 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | Install PyTeal 2 | ============== 3 | 4 | PyTeal requires Python version >= 3.10. 5 | 6 | If your operating system (OS) Python version < 3.10, we recommend: 7 | 8 | * Rather than override the OS Python version, install Python >= 3.10 alongside the OS Python version. 9 | * Use `pyenv `_ or similar tooling to manage multiple Python versions. 10 | 11 | The easiest way of installing PyTeal is using :code:`pip` : :: 12 | 13 | $ pip3 install pyteal 14 | 15 | Alternatively, choose a `distribution file `_, and run :: 16 | 17 | $ pip3 install [file name] 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/overview.rst: -------------------------------------------------------------------------------- 1 | Overview 2 | ======== 3 | 4 | With PyTeal, developers can easily write `Algorand Smart Contracts (ASC1s) `_ in Python. 5 | PyTeal supports both stateless and stateful smart contracts. 6 | 7 | Below is an example of writing a basic stateless smart contract that allows a specific receiver to withdraw funds from an account. 8 | 9 | .. literalinclude:: ../examples/signature/basic.py 10 | :language: python 11 | 12 | As shown in this example, the logic of smart contract is expressed using PyTeal expressions constructed in Python. PyTeal overloads Python's arithmetic operators 13 | such as :code:`<` and :code:`==` (more overloaded operators can be found in :ref:`arithmetic_expressions`), allowing Python developers express smart contract logic more naturally. 14 | 15 | Lastly, :any:`compileTeal` is called to convert a PyTeal expression 16 | to a TEAL program, consisting of a sequence of TEAL opcodes. 17 | The output of the above example is: 18 | 19 | .. literalinclude:: ../examples/signature/basic.teal 20 | -------------------------------------------------------------------------------- /docs/pyteal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorand/pyteal/9a610281df4f306f2a0f94483f4a009320a5c63c/docs/pyteal.png -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx==5.1.1 2 | sphinx-rtd-theme==1.0.0 3 | # dependencies from setup.py 4 | docstring-parser==0.14.1 5 | executing==2.0.1 6 | py-algorand-sdk>=2.0.0,<3.0.0 7 | semantic-version>=2.9.0,<3.0.0 8 | tabulate>=0.9.0,<0.10.0 9 | -------------------------------------------------------------------------------- /examples/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorand/pyteal/9a610281df4f306f2a0f94483f4a009320a5c63c/examples/__init__.py -------------------------------------------------------------------------------- /examples/application/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorand/pyteal/9a610281df4f306f2a0f94483f4a009320a5c63c/examples/application/__init__.py -------------------------------------------------------------------------------- /examples/application/abi/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorand/pyteal/9a610281df4f306f2a0f94483f4a009320a5c63c/examples/application/abi/__init__.py -------------------------------------------------------------------------------- /examples/application/abi/algobank_clear_state.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | byte "lost" 3 | byte "lost" 4 | app_global_get 5 | txn Sender 6 | byte "balance" 7 | app_local_get 8 | + 9 | app_global_put 10 | int 1 11 | return -------------------------------------------------------------------------------- /examples/application/sourcemap.py: -------------------------------------------------------------------------------- 1 | """ 2 | This example shows how to use the source map feature to for a PyTeal program. 3 | 4 | To enable the source mapping (at the time of this writing 3/14/2023) 5 | one must import `FeatureGate` from `feature_gates` and call `FeatureGate.set_sourcemap_enabled(True)`. 6 | This import must occur before any object from PyTeal is imported, as PyTeal will 7 | default to its own sourcemap configuration if not set beforehand, and PyTeal imports have 8 | the side effect of importing expressions that the sourcemapper needs to be aware of. 9 | """ 10 | 11 | from feature_gates import FeatureGates 12 | 13 | FeatureGates.set("sourcemap_enabled", True) 14 | 15 | # INTENTIONALLY importing pyteal and objects _AFTER_ enabling the sourcemap feature 16 | import pyteal as pt # noqa: E402 17 | from pyteal import Compilation, Mode # noqa: E402 18 | 19 | 20 | def program(): 21 | @pt.Subroutine(pt.TealType.uint64) 22 | def is_even(i): 23 | return ( 24 | pt.If(i == pt.Int(0)) 25 | .Then(pt.Int(1)) 26 | .ElseIf(i == pt.Int(1)) 27 | .Then(pt.Int(0)) 28 | .Else(is_even(i - pt.Int(2))) 29 | ) 30 | 31 | n = pt.Btoi(arg0 := pt.Txn.application_args[0]) 32 | 33 | return pt.Seq( 34 | pt.Log(pt.Bytes("n:")), 35 | pt.Log(arg0), 36 | pt.Log(pt.Bytes("is_even(n):")), 37 | pt.Log(pt.Itob(is_even(n))), 38 | pt.Int(1), 39 | ) 40 | 41 | 42 | if __name__ == "__main__": 43 | # This assumes running as follows: 44 | # cd examples/application 45 | # python sourcemap.py 46 | approval_program = program() 47 | 48 | results = Compilation(approval_program, mode=Mode.Application, version=8).compile( 49 | with_sourcemap=True, annotate_teal=True, annotate_teal_headers=True 50 | ) 51 | 52 | teal = "teal/sourcemap.teal" 53 | annotated = "teal/sourcemap_annotated.teal" 54 | 55 | with open(teal, "w") as f: 56 | f.write(results.teal) 57 | 58 | with open(annotated, "w") as f: 59 | assert isinstance(results.sourcemap, pt.PyTealSourceMap) 60 | assert isinstance(results.sourcemap.annotated_teal, str) 61 | f.write(results.sourcemap.annotated_teal) 62 | 63 | print(f"SUCCESS!!! Please check out {teal} and {annotated}") 64 | -------------------------------------------------------------------------------- /examples/application/teal/sourcemap.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | byte "n:" 3 | log 4 | txna ApplicationArgs 0 5 | log 6 | byte "is_even(n):" 7 | log 8 | txna ApplicationArgs 0 9 | btoi 10 | callsub iseven_0 11 | itob 12 | log 13 | int 1 14 | return 15 | 16 | // is_even 17 | iseven_0: 18 | proto 1 1 19 | frame_dig -1 20 | int 0 21 | == 22 | bnz iseven_0_l4 23 | frame_dig -1 24 | int 1 25 | == 26 | bnz iseven_0_l3 27 | frame_dig -1 28 | int 2 29 | - 30 | callsub iseven_0 31 | b iseven_0_l5 32 | iseven_0_l3: 33 | int 0 34 | b iseven_0_l5 35 | iseven_0_l4: 36 | int 1 37 | iseven_0_l5: 38 | retsub -------------------------------------------------------------------------------- /examples/signature/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorand/pyteal/9a610281df4f306f2a0f94483f4a009320a5c63c/examples/signature/__init__.py -------------------------------------------------------------------------------- /examples/signature/atomic_swap.py: -------------------------------------------------------------------------------- 1 | # This example is provided for informational purposes only and has not been audited for security. 2 | 3 | from pyteal import * 4 | 5 | """Atomic Swap""" 6 | 7 | alice = Addr("6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY") 8 | bob = Addr("7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M") 9 | secret = Bytes("base32", "2323232323232323") 10 | timeout = 3000 11 | 12 | 13 | def htlc( 14 | tmpl_seller=alice, 15 | tmpl_buyer=bob, 16 | tmpl_fee=1000, 17 | tmpl_secret=secret, 18 | tmpl_hash_fn=Sha256, 19 | tmpl_timeout=timeout, 20 | ): 21 | fee_cond = Txn.fee() < Int(tmpl_fee) 22 | safety_cond = And( 23 | Txn.type_enum() == TxnType.Payment, 24 | Txn.close_remainder_to() == Global.zero_address(), 25 | Txn.rekey_to() == Global.zero_address(), 26 | ) 27 | 28 | recv_cond = And(Txn.receiver() == tmpl_seller, tmpl_hash_fn(Arg(0)) == tmpl_secret) 29 | 30 | esc_cond = And(Txn.receiver() == tmpl_buyer, Txn.first_valid() > Int(tmpl_timeout)) 31 | 32 | return And(fee_cond, safety_cond, Or(recv_cond, esc_cond)) 33 | 34 | 35 | if __name__ == "__main__": 36 | print(compileTeal(htlc(), mode=Mode.Signature, version=2)) 37 | -------------------------------------------------------------------------------- /examples/signature/atomic_swap.teal: -------------------------------------------------------------------------------- 1 | #pragma version 2 2 | txn Fee 3 | int 1000 4 | < 5 | txn TypeEnum 6 | int pay 7 | == 8 | txn CloseRemainderTo 9 | global ZeroAddress 10 | == 11 | && 12 | txn RekeyTo 13 | global ZeroAddress 14 | == 15 | && 16 | && 17 | txn Receiver 18 | addr 6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY 19 | == 20 | arg 0 21 | sha256 22 | byte base32(2323232323232323) 23 | == 24 | && 25 | txn Receiver 26 | addr 7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M 27 | == 28 | txn FirstValid 29 | int 3000 30 | > 31 | && 32 | || 33 | && 34 | return 35 | -------------------------------------------------------------------------------- /examples/signature/basic.py: -------------------------------------------------------------------------------- 1 | # This example is provided for informational purposes only and has not been audited for security. 2 | 3 | from pyteal import * 4 | 5 | """Basic Bank""" 6 | 7 | 8 | def bank_for_account(receiver): 9 | """Only allow receiver to withdraw funds from this contract account. 10 | 11 | Args: 12 | receiver (str): Base 32 Algorand address of the receiver. 13 | """ 14 | 15 | is_payment = Txn.type_enum() == TxnType.Payment 16 | is_single_tx = Global.group_size() == Int(1) 17 | is_correct_receiver = Txn.receiver() == Addr(receiver) 18 | no_close_out_addr = Txn.close_remainder_to() == Global.zero_address() 19 | no_rekey_addr = Txn.rekey_to() == Global.zero_address() 20 | acceptable_fee = Txn.fee() <= Int(1000) 21 | 22 | return And( 23 | is_payment, 24 | is_single_tx, 25 | is_correct_receiver, 26 | no_close_out_addr, 27 | no_rekey_addr, 28 | acceptable_fee, 29 | ) 30 | 31 | 32 | if __name__ == "__main__": 33 | program = bank_for_account( 34 | "ZZAF5ARA4MEC5PVDOP64JM5O5MQST63Q2KOY2FLYFLXXD3PFSNJJBYAFZM" 35 | ) 36 | print(compileTeal(program, mode=Mode.Signature, version=3)) 37 | -------------------------------------------------------------------------------- /examples/signature/basic.teal: -------------------------------------------------------------------------------- 1 | #pragma version 3 2 | txn TypeEnum 3 | int pay 4 | == 5 | global GroupSize 6 | int 1 7 | == 8 | && 9 | txn Receiver 10 | addr ZZAF5ARA4MEC5PVDOP64JM5O5MQST63Q2KOY2FLYFLXXD3PFSNJJBYAFZM 11 | == 12 | && 13 | txn CloseRemainderTo 14 | global ZeroAddress 15 | == 16 | && 17 | txn RekeyTo 18 | global ZeroAddress 19 | == 20 | && 21 | txn Fee 22 | int 1000 23 | <= 24 | && 25 | return 26 | -------------------------------------------------------------------------------- /examples/signature/periodic_payment.py: -------------------------------------------------------------------------------- 1 | # This example is provided for informational purposes only and has not been audited for security. 2 | 3 | from pyteal import * 4 | 5 | """Periodic Payment""" 6 | 7 | tmpl_fee = Int(1000) 8 | tmpl_period = Int(50) 9 | tmpl_dur = Int(5000) 10 | tmpl_lease = Bytes("base64", "023sdDE2") 11 | tmpl_amt = Int(2000) 12 | tmpl_rcv = Addr("6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY") 13 | tmpl_timeout = Int(30000) 14 | 15 | 16 | def periodic_payment( 17 | tmpl_fee=tmpl_fee, 18 | tmpl_period=tmpl_period, 19 | tmpl_dur=tmpl_dur, 20 | tmpl_lease=tmpl_lease, 21 | tmpl_amt=tmpl_amt, 22 | tmpl_rcv=tmpl_rcv, 23 | tmpl_timeout=tmpl_timeout, 24 | ): 25 | periodic_pay_core = And( 26 | Txn.type_enum() == TxnType.Payment, 27 | Txn.fee() < tmpl_fee, 28 | Txn.first_valid() % tmpl_period == Int(0), 29 | Txn.last_valid() == tmpl_dur + Txn.first_valid(), 30 | Txn.lease() == tmpl_lease, 31 | ) 32 | 33 | periodic_pay_transfer = And( 34 | Txn.close_remainder_to() == Global.zero_address(), 35 | Txn.rekey_to() == Global.zero_address(), 36 | Txn.receiver() == tmpl_rcv, 37 | Txn.amount() == tmpl_amt, 38 | ) 39 | 40 | periodic_pay_close = And( 41 | Txn.close_remainder_to() == tmpl_rcv, 42 | Txn.rekey_to() == Global.zero_address(), 43 | Txn.receiver() == Global.zero_address(), 44 | Txn.first_valid() == tmpl_timeout, 45 | Txn.amount() == Int(0), 46 | ) 47 | 48 | periodic_pay_escrow = periodic_pay_core.And( 49 | periodic_pay_transfer.Or(periodic_pay_close) 50 | ) 51 | 52 | return periodic_pay_escrow 53 | 54 | 55 | if __name__ == "__main__": 56 | print(compileTeal(periodic_payment(), mode=Mode.Signature, version=2)) 57 | -------------------------------------------------------------------------------- /examples/signature/periodic_payment.teal: -------------------------------------------------------------------------------- 1 | #pragma version 2 2 | txn TypeEnum 3 | int pay 4 | == 5 | txn Fee 6 | int 1000 7 | < 8 | && 9 | txn FirstValid 10 | int 50 11 | % 12 | int 0 13 | == 14 | && 15 | txn LastValid 16 | int 5000 17 | txn FirstValid 18 | + 19 | == 20 | && 21 | txn Lease 22 | byte base64(023sdDE2) 23 | == 24 | && 25 | txn CloseRemainderTo 26 | global ZeroAddress 27 | == 28 | txn RekeyTo 29 | global ZeroAddress 30 | == 31 | && 32 | txn Receiver 33 | addr 6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY 34 | == 35 | && 36 | txn Amount 37 | int 2000 38 | == 39 | && 40 | txn CloseRemainderTo 41 | addr 6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY 42 | == 43 | txn RekeyTo 44 | global ZeroAddress 45 | == 46 | && 47 | txn Receiver 48 | global ZeroAddress 49 | == 50 | && 51 | txn FirstValid 52 | int 30000 53 | == 54 | && 55 | txn Amount 56 | int 0 57 | == 58 | && 59 | || 60 | && 61 | return 62 | -------------------------------------------------------------------------------- /examples/signature/recurring_swap.teal: -------------------------------------------------------------------------------- 1 | #pragma version 2 2 | txn Fee 3 | int 1000 4 | <= 5 | txn TypeEnum 6 | int 1 7 | == 8 | txn RekeyTo 9 | global ZeroAddress 10 | == 11 | && 12 | && 13 | txn CloseRemainderTo 14 | global ZeroAddress 15 | == 16 | txn Receiver 17 | addr 7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M 18 | == 19 | && 20 | txn Amount 21 | int 100000 22 | == 23 | && 24 | txn FirstValid 25 | itob 26 | arg 0 27 | addr 7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M 28 | ed25519verify 29 | && 30 | txn Lease 31 | txn FirstValid 32 | itob 33 | sha256 34 | == 35 | && 36 | txn CloseRemainderTo 37 | addr 6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY 38 | == 39 | txn Amount 40 | int 0 41 | == 42 | && 43 | txn FirstValid 44 | int 100000 45 | >= 46 | && 47 | || 48 | && 49 | return 50 | -------------------------------------------------------------------------------- /examples/signature/split.py: -------------------------------------------------------------------------------- 1 | # This example is provided for informational purposes only and has not been audited for security. 2 | 3 | from pyteal import * 4 | 5 | """Split Payment""" 6 | 7 | tmpl_fee = Int(1000) 8 | tmpl_rcv1 = Addr("6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY") 9 | tmpl_rcv2 = Addr("7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M") 10 | tmpl_own = Addr("5MK5NGBRT5RL6IGUSYDIX5P7TNNZKRVXKT6FGVI6UVK6IZAWTYQGE4RZIQ") 11 | tmpl_ratn = Int(1) 12 | tmpl_ratd = Int(3) 13 | tmpl_min_pay = Int(1000) 14 | tmpl_timeout = Int(3000) 15 | 16 | 17 | def split( 18 | tmpl_fee=tmpl_fee, 19 | tmpl_rcv1=tmpl_rcv1, 20 | tmpl_rcv2=tmpl_rcv2, 21 | tmpl_own=tmpl_own, 22 | tmpl_ratn=tmpl_ratn, 23 | tmpl_ratd=tmpl_ratd, 24 | tmpl_min_pay=tmpl_min_pay, 25 | tmpl_timeout=tmpl_timeout, 26 | ): 27 | split_core = And( 28 | Txn.type_enum() == TxnType.Payment, 29 | Txn.fee() < tmpl_fee, 30 | Txn.rekey_to() == Global.zero_address(), 31 | ) 32 | 33 | split_transfer = And( 34 | Gtxn[0].sender() == Gtxn[1].sender(), 35 | Txn.close_remainder_to() == Global.zero_address(), 36 | Gtxn[0].receiver() == tmpl_rcv1, 37 | Gtxn[1].receiver() == tmpl_rcv2, 38 | Gtxn[0].amount() 39 | == ((Gtxn[0].amount() + Gtxn[1].amount()) * tmpl_ratn) / tmpl_ratd, 40 | Gtxn[0].amount() == tmpl_min_pay, 41 | ) 42 | 43 | split_close = And( 44 | Txn.close_remainder_to() == tmpl_own, 45 | Txn.receiver() == Global.zero_address(), 46 | Txn.amount() == Int(0), 47 | Txn.first_valid() > tmpl_timeout, 48 | ) 49 | 50 | split_program = And( 51 | split_core, If(Global.group_size() == Int(2), split_transfer, split_close) 52 | ) 53 | 54 | return split_program 55 | 56 | 57 | if __name__ == "__main__": 58 | print(compileTeal(split(), mode=Mode.Signature, version=2)) 59 | -------------------------------------------------------------------------------- /examples/signature/split.teal: -------------------------------------------------------------------------------- 1 | #pragma version 2 2 | txn TypeEnum 3 | int pay 4 | == 5 | txn Fee 6 | int 1000 7 | < 8 | && 9 | txn RekeyTo 10 | global ZeroAddress 11 | == 12 | && 13 | global GroupSize 14 | int 2 15 | == 16 | bnz main_l2 17 | txn CloseRemainderTo 18 | addr 5MK5NGBRT5RL6IGUSYDIX5P7TNNZKRVXKT6FGVI6UVK6IZAWTYQGE4RZIQ 19 | == 20 | txn Receiver 21 | global ZeroAddress 22 | == 23 | && 24 | txn Amount 25 | int 0 26 | == 27 | && 28 | txn FirstValid 29 | int 3000 30 | > 31 | && 32 | b main_l3 33 | main_l2: 34 | gtxn 0 Sender 35 | gtxn 1 Sender 36 | == 37 | txn CloseRemainderTo 38 | global ZeroAddress 39 | == 40 | && 41 | gtxn 0 Receiver 42 | addr 6ZHGHH5Z5CTPCF5WCESXMGRSVK7QJETR63M3NY5FJCUYDHO57VTCMJOBGY 43 | == 44 | && 45 | gtxn 1 Receiver 46 | addr 7Z5PWO2C6LFNQFGHWKSK5H47IQP5OJW2M3HA2QPXTY3WTNP5NU2MHBW27M 47 | == 48 | && 49 | gtxn 0 Amount 50 | gtxn 0 Amount 51 | gtxn 1 Amount 52 | + 53 | int 1 54 | * 55 | int 3 56 | / 57 | == 58 | && 59 | gtxn 0 Amount 60 | int 1000 61 | == 62 | && 63 | main_l3: 64 | && 65 | return -------------------------------------------------------------------------------- /feature_gates/__init__.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | from typing import Final 3 | 4 | 5 | @dataclass 6 | class _FeatureGatesConfig: 7 | """ 8 | Configuration for feature gates. 9 | 10 | We follow the following convention: 11 | 12 | feature_property: True/False 13 | """ 14 | 15 | sourcemap_enabled: bool 16 | sourcemap_debug: bool 17 | 18 | 19 | class FeatureGates: 20 | """ 21 | Feature gates work as follows: 22 | 1. Add a new feature gate to the _FeatureGatesConfig dataclass 23 | 2. Set the default value for the feature gate in the _gates field below 24 | 25 | Automagically, a new setter and getter will be available for the feature gate. 26 | For example, given feature `foo_on` by adding _FeatureGatesConfig.foo_on, 27 | the following methods will be available: 28 | * FeatureGates.foo_on() -> bool 29 | * FeatureGates.set_foo_on(gate: bool) 30 | """ 31 | 32 | # default values for feature gates: 33 | _gates: _FeatureGatesConfig = _FeatureGatesConfig( 34 | sourcemap_enabled=False, 35 | sourcemap_debug=False, 36 | ) 37 | _features: Final[set[str]] = set(vars(_gates).keys()) 38 | 39 | @classmethod 40 | def _make_feature(cls, feature: str): 41 | setattr(cls, feature, classmethod(lambda cls: cls.get(feature))) 42 | setattr( 43 | cls, f"set_{feature}", classmethod(lambda cls, gate: cls.set(feature, gate)) 44 | ) 45 | 46 | @classmethod 47 | def get(cls, feature: str) -> bool | None: 48 | if feature not in cls._features: 49 | raise ValueError( 50 | f"Unknown {feature=} (available features: {cls._features}))" 51 | ) 52 | 53 | return getattr(cls._gates, feature) 54 | 55 | @classmethod 56 | def set(cls, feature: str, gate: bool) -> None: 57 | if feature not in cls._features: 58 | raise ValueError( 59 | f"Cannot set unknown {feature=} (available features: {cls._features}))" 60 | ) 61 | setattr(cls._gates, feature, gate) 62 | 63 | 64 | for feature in FeatureGates._features: 65 | FeatureGates._make_feature(feature) 66 | -------------------------------------------------------------------------------- /mypy.ini: -------------------------------------------------------------------------------- 1 | [mypy] 2 | files = pyteal,scripts,tests 3 | python_version = 3.10 4 | 5 | [mypy-semantic_version.*] 6 | ignore_missing_imports = True 7 | 8 | [mypy-pytest.*] 9 | ignore_missing_imports = True 10 | 11 | [mypy-algosdk.*] 12 | ignore_missing_imports = True 13 | -------------------------------------------------------------------------------- /pyteal/__init__.py: -------------------------------------------------------------------------------- 1 | from pyteal.ast import * 2 | from pyteal.ast import __all__ as ast_all 3 | from pyteal.compiler import ( 4 | DEFAULT_PROGRAM_VERSION, 5 | DEFAULT_TEAL_VERSION, 6 | MAX_PROGRAM_VERSION, 7 | MAX_TEAL_VERSION, 8 | MIN_PROGRAM_VERSION, 9 | MIN_TEAL_VERSION, 10 | Compilation, 11 | CompileOptions, 12 | CompileResults, 13 | OptimizeOptions, 14 | PyTealSourceMap, 15 | R3SourceMap, 16 | compileTeal, 17 | ) 18 | from pyteal.config import ( 19 | MAX_GROUP_SIZE, 20 | METHOD_ARG_NUM_CUTOFF, 21 | NUM_SLOTS, 22 | RETURN_HASH_PREFIX, 23 | ) 24 | from pyteal.errors import ( 25 | AlgodClientError, 26 | SourceMapDisabledError, 27 | TealCompileError, 28 | TealInputError, 29 | TealInternalError, 30 | TealPragmaError, 31 | TealSeqError, 32 | TealTypeError, 33 | ) 34 | from pyteal.ir import * 35 | from pyteal.ir import __all__ as ir_all 36 | from pyteal.pragma import pragma 37 | from pyteal.types import TealType 38 | 39 | # begin __all__ 40 | __all__ = ( 41 | ast_all 42 | + ir_all 43 | + [ 44 | "AlgodClientError", 45 | "Compilation", 46 | "CompileOptions", 47 | "CompileResults", 48 | "compileTeal", 49 | "DEFAULT_PROGRAM_VERSION", 50 | "DEFAULT_TEAL_VERSION", 51 | "MAX_GROUP_SIZE", 52 | "MAX_PROGRAM_VERSION", 53 | "MAX_TEAL_VERSION", 54 | "METHOD_ARG_NUM_CUTOFF", 55 | "MIN_PROGRAM_VERSION", 56 | "MIN_TEAL_VERSION", 57 | "NUM_SLOTS", 58 | "OptimizeOptions", 59 | "pragma", 60 | "PyTealSourceMap", 61 | "R3SourceMap", 62 | "RETURN_HASH_PREFIX", 63 | "SourceMapDisabledError", 64 | "TealCompileError", 65 | "TealInputError", 66 | "TealInternalError", 67 | "TealPragmaError", 68 | "TealSeqError", 69 | "TealType", 70 | "TealTypeError", 71 | ] 72 | ) 73 | # end __all__ 74 | -------------------------------------------------------------------------------- /pyteal/ast/abi/method_return.py: -------------------------------------------------------------------------------- 1 | from typing import TYPE_CHECKING, Tuple 2 | from pyteal.ast.abi import BaseType 3 | from pyteal.types import TealType 4 | from pyteal.errors import TealInputError 5 | from pyteal.ast.expr import Expr 6 | from pyteal.ast.unaryexpr import Log 7 | from pyteal.ast.naryexpr import Concat 8 | from pyteal.ast.bytes import Bytes 9 | from pyteal.config import RETURN_HASH_PREFIX 10 | from pyteal.ir import TealBlock, TealSimpleBlock, Op 11 | from pyteal.stack_frame import NatalStackFrame 12 | 13 | if TYPE_CHECKING: 14 | from pyteal.compiler import CompileOptions 15 | 16 | 17 | class MethodReturn(Expr): 18 | def __init__(self, arg: BaseType): 19 | super().__init__() 20 | if not isinstance(arg, BaseType): 21 | raise TealInputError(f"Expecting an ABI type argument but get {arg}") 22 | self.arg = arg 23 | 24 | def __teal__(self, options: "CompileOptions") -> Tuple[TealBlock, TealSimpleBlock]: 25 | if options.version < Op.log.min_version: 26 | raise TealInputError( 27 | f"current version {options.version} is lower than log's min version {Op.log.min_version}" 28 | ) 29 | start, end = Log(Concat(Bytes(RETURN_HASH_PREFIX), self.arg.encode())).__teal__( 30 | options 31 | ) 32 | NatalStackFrame.reframe_ops_in_blocks(self, start) 33 | return start, end 34 | 35 | def __str__(self) -> str: 36 | return f"(MethodReturn {self.arg.type_spec()})" 37 | 38 | def type_of(self) -> TealType: 39 | return TealType.none 40 | 41 | def has_return(self) -> bool: 42 | return False 43 | 44 | 45 | MethodReturn.__module__ = "pyteal.abi" 46 | -------------------------------------------------------------------------------- /pyteal/ast/abi/method_return_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | from pyteal import abi 5 | 6 | 7 | POSITIVE_CASES = [ 8 | abi.Uint16(), 9 | abi.Uint32(), 10 | abi.StaticArray(abi.StaticArrayTypeSpec(abi.BoolTypeSpec(), 12)), 11 | ] 12 | 13 | 14 | @pytest.mark.parametrize("case", POSITIVE_CASES) 15 | def test_method_return(case): 16 | m_ret = abi.MethodReturn(case) 17 | assert m_ret.type_of() == pt.TealType.none 18 | assert not m_ret.has_return() 19 | assert str(m_ret) == f"(MethodReturn {case.type_spec()})" 20 | 21 | 22 | NEGATIVE_CASES = [ 23 | pt.Int(0), 24 | pt.Bytes("aaaaaaa"), 25 | abi.Uint16, 26 | abi.Uint32, 27 | ] 28 | 29 | 30 | @pytest.mark.parametrize("case", NEGATIVE_CASES) 31 | def test_method_return_error(case): 32 | with pytest.raises(pt.TealInputError): 33 | abi.MethodReturn(case) 34 | -------------------------------------------------------------------------------- /pyteal/ast/abi/type_test.py: -------------------------------------------------------------------------------- 1 | import pyteal as pt 2 | from pyteal import abi 3 | 4 | options = pt.CompileOptions(version=5) 5 | 6 | 7 | class ContainerType(abi.ComputedValue): 8 | def __init__(self, type_spec: abi.TypeSpec, encodings: pt.Expr): 9 | self.type_spec = type_spec 10 | self.encodings = encodings 11 | 12 | def produced_type_spec(self) -> abi.TypeSpec: 13 | return self.type_spec 14 | 15 | def store_into(self, output: abi.BaseType) -> pt.Expr: 16 | if output.type_spec() != self.type_spec: 17 | raise pt.TealInputError( 18 | f"expected type_spec {self.type_spec} but get {output.type_spec()}" 19 | ) 20 | return output._stored_value.store(self.encodings) 21 | 22 | 23 | def test_ComputedType_use(): 24 | for value in (0, 1, 2, 3, 12345): 25 | dummyComputedType = ContainerType(abi.Uint64TypeSpec(), pt.Int(value)) 26 | expr = dummyComputedType.use(lambda output: pt.Int(2) * output.get()) 27 | assert expr.type_of() == pt.TealType.uint64 28 | assert not expr.has_return() 29 | 30 | actual, _ = expr.__teal__(options) 31 | actual.addIncoming() 32 | actual = pt.TealBlock.NormalizeBlocks(actual) 33 | 34 | assert type(actual) is pt.TealSimpleBlock 35 | assert actual.ops[1].op == pt.Op.store 36 | assert type(actual.ops[1].args[0]) is pt.ScratchSlot 37 | actualSlot = actual.ops[1].args[0] 38 | 39 | expected = pt.TealSimpleBlock( 40 | [ 41 | pt.TealOp(None, pt.Op.int, value), 42 | pt.TealOp(None, pt.Op.store, actualSlot), 43 | pt.TealOp(None, pt.Op.int, 2), 44 | pt.TealOp(None, pt.Op.load, actualSlot), 45 | pt.TealOp(None, pt.Op.mul), 46 | ] 47 | ) 48 | 49 | with pt.TealComponent.Context.ignoreExprEquality(): 50 | assert actual == expected 51 | -------------------------------------------------------------------------------- /pyteal/ast/addr.py: -------------------------------------------------------------------------------- 1 | from typing import TYPE_CHECKING 2 | 3 | from pyteal.types import TealType, valid_address 4 | from pyteal.ir import TealOp, Op, TealBlock 5 | from pyteal.ast.leafexpr import LeafExpr 6 | 7 | if TYPE_CHECKING: 8 | from pyteal.compiler import CompileOptions 9 | 10 | 11 | class Addr(LeafExpr): 12 | """An expression that represents an Algorand address.""" 13 | 14 | def __init__(self, address: str) -> None: 15 | """Create a new Addr expression. 16 | 17 | Args: 18 | address: A string containing a valid base32 Algorand address 19 | """ 20 | super().__init__() 21 | valid_address(address) 22 | self.address = address 23 | 24 | def __teal__(self, options: "CompileOptions"): 25 | op = TealOp(self, Op.addr, self.address) 26 | return TealBlock.FromOp(options, op) 27 | 28 | def __str__(self): 29 | return "(address: {})".format(self.address) 30 | 31 | def type_of(self): 32 | return TealType.bytes 33 | 34 | 35 | Addr.__module__ = "pyteal" 36 | -------------------------------------------------------------------------------- /pyteal/ast/addr_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | 6 | def test_addr(): 7 | expr = pt.Addr("NJUWK3DJNZTWU2LFNRUW4Z3KNFSWY2LOM5VGSZLMNFXGO2TJMVWGS3THMF") 8 | assert expr.type_of() == pt.TealType.bytes 9 | expected = pt.TealSimpleBlock( 10 | [ 11 | pt.TealOp( 12 | expr, 13 | pt.Op.addr, 14 | "NJUWK3DJNZTWU2LFNRUW4Z3KNFSWY2LOM5VGSZLMNFXGO2TJMVWGS3THMF", 15 | ) 16 | ] 17 | ) 18 | actual, _ = expr.__teal__(pt.CompileOptions()) 19 | assert actual == expected 20 | 21 | 22 | def test_addr_invalid(): 23 | with pytest.raises(pt.TealInputError): 24 | pt.Addr("NJUWK3DJNZTWU2LFNRUW4Z3KNFSWY2LOM5VGSZLMNFXGO2TJMVWGS3TH") 25 | 26 | with pytest.raises(pt.TealInputError): 27 | pt.Addr("000000000000000000000000000000000000000000000000000000000") 28 | 29 | with pytest.raises(pt.TealInputError): 30 | pt.Addr(2) 31 | -------------------------------------------------------------------------------- /pyteal/ast/arg.py: -------------------------------------------------------------------------------- 1 | from typing import Union, cast, TYPE_CHECKING 2 | 3 | from pyteal.types import TealType, require_type 4 | from pyteal.ir import TealOp, Op, TealBlock 5 | from pyteal.errors import TealInputError, verifyProgramVersion 6 | from pyteal.ast.expr import Expr 7 | from pyteal.ast.leafexpr import LeafExpr 8 | 9 | if TYPE_CHECKING: 10 | from pyteal.compiler import CompileOptions 11 | 12 | 13 | class Arg(LeafExpr): 14 | """An expression to get an argument when running in signature verification mode.""" 15 | 16 | def __init__(self, index: Union[int, Expr]) -> None: 17 | """Get an argument for this program. 18 | 19 | Should only be used in signature verification mode. For application mode arguments, see 20 | :any:`TxnObject.application_args`. 21 | 22 | Args: 23 | index: The index of the argument to get. The index must be between 0 and 255 inclusive. 24 | Starting in AVM v5, the index may be a PyTeal expression that evaluates to uint64. 25 | """ 26 | super().__init__() 27 | 28 | if type(index) is int: 29 | if index < 0 or index > 255: 30 | raise TealInputError("invalid arg index {}".format(index)) 31 | else: 32 | require_type(cast(Expr, index), TealType.uint64) 33 | 34 | self.index = index 35 | 36 | def __teal__(self, options: "CompileOptions"): 37 | if type(self.index) is int: 38 | op = TealOp(self, Op.arg, self.index) 39 | return TealBlock.FromOp(options, op) 40 | 41 | verifyProgramVersion( 42 | Op.args.min_version, 43 | options.version, 44 | "Program version too low to use dynamic indexes with Arg", 45 | ) 46 | 47 | op = TealOp(self, Op.args) 48 | return TealBlock.FromOp(options, op, cast(Expr, self.index)) 49 | 50 | def __str__(self): 51 | return "(arg {})".format(self.index) 52 | 53 | def type_of(self): 54 | return TealType.bytes 55 | 56 | 57 | Arg.__module__ = "pyteal" 58 | -------------------------------------------------------------------------------- /pyteal/ast/arg_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | avm2Options = pt.CompileOptions(version=2) 6 | avm4Options = pt.CompileOptions(version=4) 7 | avm5Options = pt.CompileOptions(version=5) 8 | 9 | 10 | def test_arg_static(): 11 | for i in range(256): 12 | expr = pt.Arg(i) 13 | assert expr.type_of() == pt.TealType.bytes 14 | assert not expr.has_return() 15 | 16 | expected = pt.TealSimpleBlock([pt.TealOp(expr, pt.Op.arg, i)]) 17 | 18 | actual, _ = expr.__teal__(avm2Options) 19 | assert actual == expected 20 | 21 | 22 | def test_arg_dynamic(): 23 | i = pt.Int(7) 24 | expr = pt.Arg(i) 25 | assert expr.type_of() == pt.TealType.bytes 26 | assert not expr.has_return() 27 | 28 | expected = pt.TealSimpleBlock( 29 | [pt.TealOp(i, pt.Op.int, 7), pt.TealOp(expr, pt.Op.args)] 30 | ) 31 | 32 | actual, _ = expr.__teal__(avm5Options) 33 | actual.addIncoming() 34 | actual = pt.TealBlock.NormalizeBlocks(actual) 35 | 36 | assert actual == expected 37 | 38 | with pytest.raises(pt.TealInputError): 39 | expr.__teal__(avm4Options) 40 | 41 | 42 | def test_arg_invalid(): 43 | with pytest.raises(pt.TealTypeError): 44 | pt.Arg(pt.Bytes("k")) 45 | 46 | with pytest.raises(pt.TealInputError): 47 | pt.Arg(-1) 48 | 49 | with pytest.raises(pt.TealInputError): 50 | pt.Arg(256) 51 | -------------------------------------------------------------------------------- /pyteal/ast/array.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | from pyteal.ast.expr import Expr 4 | 5 | 6 | class Array(ABC): 7 | """Represents a variable length array of objects.""" 8 | 9 | @abstractmethod 10 | def length(self) -> Expr: 11 | """Get the length of the array.""" 12 | pass 13 | 14 | @abstractmethod 15 | def __getitem__(self, index: int): 16 | """Get the value at a given index in this array.""" 17 | pass 18 | 19 | 20 | Array.__module__ = "pyteal" 21 | -------------------------------------------------------------------------------- /pyteal/ast/base64decode_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | avm6Options = pt.CompileOptions(version=6) 6 | avm7Options = pt.CompileOptions(version=7) 7 | 8 | 9 | def test_base64decode_std(): 10 | arg = pt.Bytes("aGVsbG8gd29ybGQ=") 11 | expr = pt.Base64Decode.std(arg) 12 | assert expr.type_of() == pt.TealType.bytes 13 | 14 | expected = pt.TealSimpleBlock( 15 | [ 16 | pt.TealOp(arg, pt.Op.byte, '"aGVsbG8gd29ybGQ="'), 17 | pt.TealOp(expr, pt.Op.base64_decode, "StdEncoding"), 18 | ] 19 | ) 20 | 21 | actual, _ = expr.__teal__(avm7Options) 22 | actual.addIncoming() 23 | actual = pt.TealBlock.NormalizeBlocks(actual) 24 | 25 | assert actual == expected 26 | 27 | with pytest.raises(pt.TealInputError): 28 | expr.__teal__(avm6Options) 29 | 30 | 31 | def test_base64decode_url(): 32 | arg = pt.Bytes("aGVsbG8gd29ybGQ") 33 | expr = pt.Base64Decode.url(arg) 34 | assert expr.type_of() == pt.TealType.bytes 35 | 36 | expected = pt.TealSimpleBlock( 37 | [ 38 | pt.TealOp(arg, pt.Op.byte, '"aGVsbG8gd29ybGQ"'), 39 | pt.TealOp(expr, pt.Op.base64_decode, "URLEncoding"), 40 | ] 41 | ) 42 | 43 | actual, _ = expr.__teal__(avm7Options) 44 | actual.addIncoming() 45 | actual = pt.TealBlock.NormalizeBlocks(actual) 46 | 47 | assert actual == expected 48 | 49 | with pytest.raises(pt.TealInputError): 50 | expr.__teal__(avm6Options) 51 | 52 | 53 | def test_base64decode_invalid(): 54 | with pytest.raises(pt.TealTypeError): 55 | pt.Base64Decode.std(pt.Int(0)) 56 | with pytest.raises(pt.TealTypeError): 57 | pt.Base64Decode.url(pt.Int(0)) 58 | -------------------------------------------------------------------------------- /pyteal/ast/break_.py: -------------------------------------------------------------------------------- 1 | from typing import TYPE_CHECKING 2 | 3 | from pyteal.types import TealType 4 | from pyteal.errors import TealCompileError 5 | from pyteal.ast.expr import Expr 6 | from pyteal.ir import TealSimpleBlock 7 | 8 | 9 | if TYPE_CHECKING: 10 | from pyteal.compiler import CompileOptions 11 | 12 | 13 | class Break(Expr): 14 | """A break expression""" 15 | 16 | def __init__(self) -> None: 17 | """Create a new break expression. 18 | 19 | This operation is only permitted in a loop. 20 | 21 | """ 22 | super().__init__() 23 | 24 | def __str__(self) -> str: 25 | return "break" 26 | 27 | def __teal__(self, options: "CompileOptions"): 28 | if not options.isInLoop(): 29 | raise TealCompileError("break is only allowed in a loop", self) 30 | 31 | start = TealSimpleBlock([]) 32 | options.addLoopBreakBlock(start) 33 | 34 | return start, start 35 | 36 | def type_of(self): 37 | return TealType.none 38 | 39 | def has_return(self): 40 | return False 41 | 42 | 43 | Break.__module__ = "pyteal" 44 | -------------------------------------------------------------------------------- /pyteal/ast/break_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | options = pt.CompileOptions() 6 | 7 | 8 | def test_break_fail(): 9 | with pytest.raises(pt.TealCompileError): 10 | pt.Break().__teal__(options) 11 | 12 | with pytest.raises(pt.TealCompileError): 13 | pt.If(pt.Int(1), pt.Break()).__teal__(options) 14 | 15 | with pytest.raises(pt.TealCompileError): 16 | pt.Seq([pt.Break()]).__teal__(options) 17 | 18 | with pytest.raises(TypeError): 19 | pt.Break(pt.Int(1)) 20 | 21 | 22 | def test_break(): 23 | expr = pt.Break() 24 | 25 | assert expr.type_of() == pt.TealType.none 26 | assert not expr.has_return() 27 | 28 | expected = pt.TealSimpleBlock([]) 29 | 30 | options.enterLoop() 31 | actual, _ = expr.__teal__(options) 32 | breakBlocks, continueBlocks = options.exitLoop() 33 | 34 | assert actual == expected 35 | assert breakBlocks == [actual] 36 | assert continueBlocks == [] 37 | -------------------------------------------------------------------------------- /pyteal/ast/continue_.py: -------------------------------------------------------------------------------- 1 | from typing import TYPE_CHECKING 2 | 3 | from pyteal.types import TealType 4 | from pyteal.errors import TealCompileError 5 | from pyteal.ast.expr import Expr 6 | from pyteal.ir import TealSimpleBlock 7 | 8 | 9 | if TYPE_CHECKING: 10 | from pyteal.compiler import CompileOptions 11 | 12 | 13 | class Continue(Expr): 14 | """A continue expression""" 15 | 16 | def __init__(self) -> None: 17 | """Create a new continue expression. 18 | 19 | This operation is only permitted in a loop. 20 | 21 | """ 22 | super().__init__() 23 | 24 | def __str__(self) -> str: 25 | return "continue" 26 | 27 | def __teal__(self, options: "CompileOptions"): 28 | if not options.isInLoop(): 29 | raise TealCompileError("continue is only allowed in a loop", self) 30 | 31 | start = TealSimpleBlock([]) 32 | options.addLoopContinueBlock(start) 33 | 34 | return start, start 35 | 36 | def type_of(self): 37 | return TealType.none 38 | 39 | def has_return(self): 40 | return False 41 | 42 | 43 | Continue.__module__ = "pyteal" 44 | -------------------------------------------------------------------------------- /pyteal/ast/continue_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | options = pt.CompileOptions() 6 | 7 | 8 | def test_continue_fail(): 9 | with pytest.raises(pt.TealCompileError): 10 | pt.Continue().__teal__(options) 11 | 12 | with pytest.raises(pt.TealCompileError): 13 | pt.If(pt.Int(1), pt.Continue()).__teal__(options) 14 | 15 | with pytest.raises(pt.TealCompileError): 16 | pt.Seq([pt.Continue()]).__teal__(options) 17 | 18 | with pytest.raises(TypeError): 19 | pt.Continue(pt.Int(1)) 20 | 21 | 22 | def test_continue(): 23 | expr = pt.Continue() 24 | 25 | assert expr.type_of() == pt.TealType.none 26 | assert not expr.has_return() 27 | 28 | expected = pt.TealSimpleBlock([]) 29 | 30 | options.enterLoop() 31 | actual, _ = expr.__teal__(options) 32 | breakBlocks, continueBlocks = options.exitLoop() 33 | 34 | assert actual == expected 35 | assert breakBlocks == [] 36 | assert continueBlocks == [actual] 37 | -------------------------------------------------------------------------------- /pyteal/ast/ec_test.py: -------------------------------------------------------------------------------- 1 | from typing import Callable 2 | 3 | import pytest 4 | 5 | import pyteal as pt 6 | 7 | OPERATIONS: list[ 8 | tuple[ 9 | Callable[[pt.EllipticCurve, pt.Expr], pt.Expr] 10 | | Callable[[pt.EllipticCurve, pt.Expr, pt.Expr], pt.Expr], 11 | pt.Op, 12 | int, 13 | pt.TealType, 14 | ] 15 | ] = [ 16 | (pt.EcAdd, pt.Op.ec_add, 2, pt.TealType.bytes), 17 | (pt.EcScalarMul, pt.Op.ec_scalar_mul, 2, pt.TealType.bytes), 18 | (pt.EcPairingCheck, pt.Op.ec_pairing_check, 2, pt.TealType.uint64), 19 | (pt.EcMultiScalarMul, pt.Op.ec_multi_scalar_mul, 2, pt.TealType.bytes), 20 | (pt.EcSubgroupCheck, pt.Op.ec_subgroup_check, 1, pt.TealType.uint64), 21 | (pt.EcMapTo, pt.Op.ec_map_to, 1, pt.TealType.bytes), 22 | ] 23 | 24 | 25 | def test_EcOperation(): 26 | for operation, expected_op, num_args, expected_return_type in OPERATIONS: 27 | for curve in pt.EllipticCurve: 28 | args = [pt.Bytes(f"arg{i}") for i in range(num_args)] 29 | expr = operation(curve, *args) 30 | assert expr.type_of() == expected_return_type 31 | 32 | expected = pt.TealSimpleBlock( 33 | [pt.TealOp(arg, pt.Op.byte, f'"arg{i}"') for i, arg in enumerate(args)] 34 | + [pt.TealOp(expr, expected_op, curve.arg_name)] 35 | ) 36 | 37 | actual, _ = expr.__teal__(pt.CompileOptions(version=10)) 38 | actual.addIncoming() 39 | actual = pt.TealBlock.NormalizeBlocks(actual) 40 | 41 | assert actual == expected 42 | 43 | # Test wrong arg types 44 | for i in range(num_args): 45 | bad_args = args.copy() 46 | bad_args[i] = pt.Int(1) 47 | with pytest.raises(pt.TealTypeError): 48 | operation(curve, *bad_args) 49 | -------------------------------------------------------------------------------- /pyteal/ast/err.py: -------------------------------------------------------------------------------- 1 | from typing import TYPE_CHECKING 2 | 3 | from pyteal.types import TealType 4 | from pyteal.ir import TealOp, Op, TealBlock 5 | from pyteal.ast.expr import Expr 6 | 7 | if TYPE_CHECKING: 8 | from pyteal.compiler import CompileOptions 9 | 10 | 11 | class Err(Expr): 12 | """Expression that causes the program to immediately fail when executed.""" 13 | 14 | def __teal__(self, options: "CompileOptions"): 15 | op = TealOp(self, Op.err) 16 | return TealBlock.FromOp(options, op) 17 | 18 | def __str__(self): 19 | return "(err)" 20 | 21 | def type_of(self): 22 | return TealType.none 23 | 24 | def has_return(self): 25 | return True 26 | 27 | 28 | Err.__module__ = "pyteal" 29 | -------------------------------------------------------------------------------- /pyteal/ast/err_test.py: -------------------------------------------------------------------------------- 1 | import pyteal as pt 2 | 3 | 4 | def test_err(): 5 | expr = pt.Err() 6 | assert expr.type_of() == pt.TealType.none 7 | assert expr.has_return() 8 | expected = pt.TealSimpleBlock([pt.TealOp(expr, pt.Op.err)]) 9 | actual, _ = expr.__teal__(pt.CompileOptions()) 10 | assert actual == expected 11 | -------------------------------------------------------------------------------- /pyteal/ast/gaid_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | avm3Options = pt.CompileOptions(version=3) 6 | avm4Options = pt.CompileOptions(version=4) 7 | 8 | 9 | def test_gaid_teal_3(): 10 | with pytest.raises(pt.TealInputError): 11 | pt.GeneratedID(0).__teal__(avm3Options) 12 | 13 | 14 | def test_gaid(): 15 | expr = pt.GeneratedID(0) 16 | assert expr.type_of() == pt.TealType.uint64 17 | 18 | expected = pt.TealSimpleBlock([pt.TealOp(expr, pt.Op.gaid, 0)]) 19 | 20 | actual, _ = expr.__teal__(avm4Options) 21 | 22 | assert actual == expected 23 | 24 | 25 | def test_gaid_invalid(): 26 | with pytest.raises(pt.TealInputError): 27 | pt.GeneratedID(-1) 28 | 29 | with pytest.raises(pt.TealInputError): 30 | pt.GeneratedID(pt.MAX_GROUP_SIZE) 31 | 32 | 33 | def test_gaid_dynamic_teal_3(): 34 | with pytest.raises(pt.TealInputError): 35 | pt.GeneratedID(pt.Int(0)).__teal__(avm3Options) 36 | 37 | 38 | def test_gaid_dynamic(): 39 | arg = pt.Int(0) 40 | expr = pt.GeneratedID(arg) 41 | assert expr.type_of() == pt.TealType.uint64 42 | 43 | expected = pt.TealSimpleBlock( 44 | [pt.TealOp(arg, pt.Op.int, 0), pt.TealOp(expr, pt.Op.gaids)] 45 | ) 46 | 47 | actual, _ = expr.__teal__(avm4Options) 48 | actual.addIncoming() 49 | actual = pt.TealBlock.NormalizeBlocks(actual) 50 | 51 | assert actual == expected 52 | 53 | 54 | def test_gaid_dynamic_invalid(): 55 | with pytest.raises(pt.TealTypeError): 56 | pt.GeneratedID(pt.Bytes("index")) 57 | -------------------------------------------------------------------------------- /pyteal/ast/gitxn_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | avm5Options = pt.CompileOptions(version=5) 6 | avm6Options = pt.CompileOptions(version=6) 7 | 8 | 9 | def test_gitxn_invalid(): 10 | for ctor, e in [ 11 | ( 12 | lambda: pt.Gitxn[pt.MAX_GROUP_SIZE], 13 | pt.TealInputError, 14 | ), 15 | ( 16 | lambda: pt.Gitxn[-1], 17 | pt.TealInputError, 18 | ), 19 | ]: 20 | with pytest.raises(e): 21 | ctor() 22 | 23 | 24 | def test_gitxn_valid(): 25 | for i in range(pt.MAX_GROUP_SIZE): 26 | pt.Gitxn[i].sender() 27 | 28 | 29 | def test_gitxn_expr_invalid(): 30 | for f, e in [ 31 | ( 32 | lambda: pt.GitxnExpr(pt.Int(1), pt.TxnField.sender), 33 | pt.TealInputError, 34 | ), 35 | ( 36 | lambda: pt.GitxnExpr(1, pt.TxnField.sender).__teal__(avm5Options), 37 | pt.TealInputError, 38 | ), 39 | ]: 40 | with pytest.raises(e): 41 | f() 42 | 43 | 44 | def test_gitxn_expr_valid(): 45 | pt.GitxnExpr(1, pt.TxnField.sender).__teal__(avm6Options) 46 | 47 | 48 | def test_gitxna_expr_invalid(): 49 | for f, e in [ 50 | ( 51 | lambda: pt.GitxnaExpr("Invalid_type", pt.TxnField.application_args, 1), 52 | pt.TealInputError, 53 | ), 54 | ( 55 | lambda: pt.GitxnaExpr(1, pt.TxnField.application_args, "Invalid_type"), 56 | pt.TealInputError, 57 | ), 58 | ( 59 | lambda: pt.GitxnaExpr( 60 | 0, pt.TxnField.application_args, pt.Assert(pt.Int(1)) 61 | ), 62 | pt.TealTypeError, 63 | ), 64 | ( 65 | lambda: pt.GitxnaExpr(0, pt.TxnField.application_args, 0).__teal__( 66 | avm5Options 67 | ), 68 | pt.TealInputError, 69 | ), 70 | ]: 71 | with pytest.raises(e): 72 | f() 73 | 74 | 75 | def test_gitxna_valid(): 76 | [ 77 | e.__teal__(avm6Options) 78 | for e in [ 79 | pt.GitxnaExpr(0, pt.TxnField.application_args, 1), 80 | pt.GitxnaExpr(0, pt.TxnField.application_args, pt.Int(1)), 81 | ] 82 | ] 83 | 84 | 85 | # txn_test.py performs additional testing 86 | -------------------------------------------------------------------------------- /pyteal/ast/gtxn_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | avm6Options = pt.CompileOptions(version=6) 6 | 7 | 8 | def test_gtxn_invalid(): 9 | for f, e in [ 10 | (lambda: pt.Gtxn[-1], pt.TealInputError), 11 | (lambda: pt.Gtxn[pt.MAX_GROUP_SIZE + 1], pt.TealInputError), 12 | (lambda: pt.Gtxn[pt.Pop(pt.Int(0))], pt.TealTypeError), 13 | (lambda: pt.Gtxn[pt.Bytes("index")], pt.TealTypeError), 14 | ]: 15 | with pytest.raises(e): 16 | f() 17 | 18 | 19 | def test_gtxn_expr_invalid(): 20 | for f, e in [ 21 | ( 22 | lambda: pt.GtxnExpr(pt.Assert(pt.Int(1)), pt.TxnField.sender), 23 | pt.TealTypeError, 24 | ), 25 | ]: 26 | with pytest.raises(e): 27 | f() 28 | 29 | 30 | def test_gtxn_expr_valid(): 31 | [ 32 | e.__teal__(avm6Options) 33 | for e in [ 34 | pt.GtxnExpr(1, pt.TxnField.sender), 35 | pt.GtxnExpr(pt.Int(1), pt.TxnField.sender), 36 | ] 37 | ] 38 | 39 | 40 | def test_gtxna_expr_invalid(): 41 | for f, e in [ 42 | ( 43 | lambda: pt.GtxnaExpr("Invalid_type", pt.TxnField.assets, 1), 44 | pt.TealInputError, 45 | ), 46 | ( 47 | lambda: pt.GtxnaExpr(1, pt.TxnField.assets, "Invalid_type"), 48 | pt.TealInputError, 49 | ), 50 | ( 51 | lambda: pt.GtxnaExpr(pt.Assert(pt.Int(1)), pt.TxnField.assets, 1), 52 | pt.TealTypeError, 53 | ), 54 | ( 55 | lambda: pt.GtxnaExpr(1, pt.TxnField.assets, pt.Assert(pt.Int(1))), 56 | pt.TealTypeError, 57 | ), 58 | ]: 59 | with pytest.raises(e): 60 | f() 61 | 62 | 63 | def test_gtxna_expr_valid(): 64 | [ 65 | e.__teal__(avm6Options) 66 | for e in [ 67 | pt.GtxnaExpr(1, pt.TxnField.assets, 1), 68 | pt.GtxnaExpr(pt.Int(1), pt.TxnField.assets, pt.Int(1)), 69 | ] 70 | ] 71 | 72 | 73 | # txn_test.py performs additional testing 74 | -------------------------------------------------------------------------------- /pyteal/ast/int.py: -------------------------------------------------------------------------------- 1 | from typing import TYPE_CHECKING 2 | 3 | from pyteal.types import TealType 4 | from pyteal.ir import TealOp, Op, TealBlock 5 | from pyteal.errors import TealInputError 6 | from pyteal.ast.leafexpr import LeafExpr 7 | 8 | if TYPE_CHECKING: 9 | from pyteal.compiler import CompileOptions 10 | 11 | 12 | class Int(LeafExpr): 13 | """An expression that represents a uint64.""" 14 | 15 | def __init__(self, value: int) -> None: 16 | """Create a new uint64. 17 | 18 | Args: 19 | value: The integer value this uint64 will represent. Must be a positive value less than 20 | 2**64. 21 | """ 22 | super().__init__() 23 | 24 | if type(value) is not int: 25 | raise TealInputError("invalid input type {} to Int".format(type(value))) 26 | elif value >= 0 and value < 2**64: 27 | self.value = value 28 | else: 29 | raise TealInputError("Int {} is out of range".format(value)) 30 | 31 | def __teal__(self, options: "CompileOptions"): 32 | op = TealOp(self, Op.int, self.value) 33 | return TealBlock.FromOp(options, op) 34 | 35 | def __str__(self): 36 | return "(Int {})".format(self.value) 37 | 38 | def type_of(self): 39 | return TealType.uint64 40 | 41 | 42 | Int.__module__ = "pyteal" 43 | 44 | 45 | class EnumInt(LeafExpr): 46 | """An expression that represents uint64 enum values.""" 47 | 48 | def __init__(self, name: str) -> None: 49 | """Create an expression to reference a uint64 enum value. 50 | 51 | Args: 52 | name: The name of the enum value. 53 | """ 54 | super().__init__() 55 | self.name = name 56 | 57 | def __teal__(self, options: "CompileOptions"): 58 | op = TealOp(self, Op.int, self.name) 59 | return TealBlock.FromOp(options, op) 60 | 61 | def __str__(self): 62 | return "(IntEnum {})".format(self.name) 63 | 64 | def type_of(self): 65 | return TealType.uint64 66 | 67 | 68 | EnumInt.__module__ = "pyteal" 69 | -------------------------------------------------------------------------------- /pyteal/ast/int_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | options = pt.CompileOptions() 6 | 7 | 8 | def test_int(): 9 | values = [0, 1, 8, 232323, 2**64 - 1] 10 | 11 | for value in values: 12 | expr = pt.Int(value) 13 | assert expr.type_of() == pt.TealType.uint64 14 | 15 | expected = pt.TealSimpleBlock([pt.TealOp(expr, pt.Op.int, value)]) 16 | 17 | actual, _ = expr.__teal__(options) 18 | 19 | assert actual == expected 20 | 21 | 22 | def test_int_invalid(): 23 | with pytest.raises(pt.TealInputError): 24 | pt.Int(6.7) 25 | 26 | with pytest.raises(pt.TealInputError): 27 | pt.Int(-1) 28 | 29 | with pytest.raises(pt.TealInputError): 30 | pt.Int(2**64) 31 | 32 | with pytest.raises(pt.TealInputError): 33 | pt.Int("0") 34 | 35 | 36 | def test_enum_int(): 37 | expr = pt.EnumInt("OptIn") 38 | assert expr.type_of() == pt.TealType.uint64 39 | 40 | expected = pt.TealSimpleBlock([pt.TealOp(expr, pt.Op.int, "OptIn")]) 41 | 42 | actual, _ = expr.__teal__(options) 43 | 44 | assert actual == expected 45 | -------------------------------------------------------------------------------- /pyteal/ast/leafexpr.py: -------------------------------------------------------------------------------- 1 | from pyteal.ast.expr import Expr 2 | 3 | 4 | class LeafExpr(Expr): 5 | """Leaf expression base class.""" 6 | 7 | def has_return(self): 8 | return False 9 | 10 | 11 | LeafExpr.__module__ = "pyteal" 12 | -------------------------------------------------------------------------------- /pyteal/ast/methodsig.py: -------------------------------------------------------------------------------- 1 | from typing import TYPE_CHECKING 2 | 3 | from pyteal.errors import TealInputError 4 | from pyteal.types import TealType 5 | from pyteal.ir import TealOp, Op, TealBlock 6 | 7 | from pyteal.ast.leafexpr import LeafExpr 8 | 9 | if TYPE_CHECKING: 10 | from pyteal.compiler import CompileOptions 11 | 12 | 13 | class MethodSignature(LeafExpr): 14 | """An expression that represents an ABI method selector""" 15 | 16 | def __init__(self, methodName: str) -> None: 17 | """Create a new method selector for ABI method call. 18 | 19 | Args: 20 | methodName: A string containing a valid ABI method signature 21 | """ 22 | super().__init__() 23 | if type(methodName) is not str: 24 | raise TealInputError( 25 | "invalid input type {} to Method".format(type(methodName)) 26 | ) 27 | elif len(methodName) == 0: 28 | raise TealInputError("invalid input empty string to Method") 29 | self.methodName = methodName 30 | 31 | def __teal__(self, options: "CompileOptions"): 32 | op = TealOp(self, Op.method_signature, '"{}"'.format(self.methodName)) 33 | return TealBlock.FromOp(options, op) 34 | 35 | def __str__(self) -> str: 36 | return "(MethodSignature '{}')".format(self.methodName) 37 | 38 | def type_of(self) -> TealType: 39 | return TealType.bytes 40 | 41 | 42 | MethodSignature.__module__ = "pyteal" 43 | -------------------------------------------------------------------------------- /pyteal/ast/methodsig_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from pyteal.ast.methodsig import MethodSignature 4 | 5 | import pyteal as pt 6 | 7 | 8 | def test_method(): 9 | expr = MethodSignature("add(uint64,uint64)uint64") 10 | assert expr.type_of() == pt.TealType.bytes 11 | 12 | expected = pt.TealSimpleBlock( 13 | [pt.TealOp(expr, pt.Op.method_signature, '"add(uint64,uint64)uint64"')] 14 | ) 15 | actual, _ = expr.__teal__(pt.CompileOptions()) 16 | assert expected == actual 17 | 18 | 19 | def test_method_invalid(): 20 | with pytest.raises(pt.TealInputError): 21 | MethodSignature(114514) 22 | 23 | with pytest.raises(pt.TealInputError): 24 | MethodSignature(['"m0()void"', '"m1()uint64"']) 25 | 26 | with pytest.raises(pt.TealInputError): 27 | MethodSignature("") 28 | -------------------------------------------------------------------------------- /pyteal/ast/mimc_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | avm10Options = pt.CompileOptions(version=10) 6 | avm11Options = pt.CompileOptions(version=11) 7 | 8 | 9 | def test_mimc_bn254(): 10 | args = [pt.Bytes("a message in a bottle")] 11 | expr = pt.MiMC.bn254mp110(*args) 12 | assert expr.type_of() == pt.TealType.bytes 13 | 14 | expected = pt.TealSimpleBlock( 15 | [ 16 | pt.TealOp(args[0], pt.Op.byte, '"a message in a bottle"'), 17 | pt.TealOp(expr, pt.Op.mimc, "BN254Mp110"), 18 | ] 19 | ) 20 | 21 | actual, _ = expr.__teal__(avm11Options) 22 | actual.addIncoming() 23 | actual = pt.TealBlock.NormalizeBlocks(actual) 24 | 25 | assert actual == expected 26 | 27 | with pytest.raises(pt.TealInputError): 28 | expr.__teal__(avm10Options) 29 | 30 | 31 | def test_json_ref_invalid(): 32 | with pytest.raises(pt.TealTypeError): 33 | pt.MiMC.bn254mp110(pt.Int(1)) 34 | 35 | with pytest.raises(pt.TealTypeError): 36 | pt.MiMC.bls12_381mp111(pt.Int(2)) 37 | -------------------------------------------------------------------------------- /pyteal/ast/nonce.py: -------------------------------------------------------------------------------- 1 | from typing import TYPE_CHECKING 2 | 3 | from pyteal.errors import TealInputError 4 | from pyteal.ast.expr import Expr 5 | from pyteal.ast.seq import Seq 6 | from pyteal.ast.bytes import Bytes 7 | from pyteal.ast.unaryexpr import Pop 8 | 9 | if TYPE_CHECKING: 10 | from pyteal.compiler import CompileOptions 11 | 12 | 13 | class Nonce(Expr): 14 | """A meta expression only used to change the hash of a TEAL program.""" 15 | 16 | def __init__(self, base: str, nonce: str, child: Expr) -> None: 17 | """Create a new Nonce. 18 | 19 | The Nonce expression behaves exactly like the child expression passed into it, except it 20 | uses the provided nonce string to alter its structure in a way that does not affect 21 | execution. 22 | 23 | Args: 24 | base: The base of the nonce. Must be one of utf8, base16, base32, or base64. 25 | nonce: An arbitrary nonce string that conforms to base. 26 | child: The expression to wrap. 27 | """ 28 | super().__init__() 29 | 30 | if base not in ("utf8", "base16", "base32", "base64"): 31 | raise TealInputError("Invalid base: {}".format(base)) 32 | 33 | self.child = child 34 | if base == "utf8": 35 | self.nonce_bytes = Bytes(nonce) 36 | else: 37 | self.nonce_bytes = Bytes(base, nonce) 38 | 39 | self.seq = Seq([Pop(self.nonce_bytes), self.child]) 40 | 41 | def __teal__(self, options: "CompileOptions"): 42 | return self.seq.__teal__(options) 43 | 44 | def __str__(self): 45 | return "(nonce: {}) {}".format(self.nonce_bytes, self.child) 46 | 47 | def type_of(self): 48 | return self.child.type_of() 49 | 50 | def has_return(self): 51 | return self.child.has_return() 52 | 53 | 54 | Nonce.__module__ = "pyteal" 55 | -------------------------------------------------------------------------------- /pyteal/ast/pragma.py: -------------------------------------------------------------------------------- 1 | from typing import TYPE_CHECKING, Any 2 | 3 | from pyteal.ast.expr import Expr 4 | from pyteal.pragma import is_valid_compiler_version, pragma 5 | 6 | if TYPE_CHECKING: 7 | from pyteal.compiler import CompileOptions 8 | 9 | 10 | class Pragma(Expr): 11 | """A meta expression which defines a pragma for a specific subsection of PyTeal code. 12 | 13 | This expression does not affect the underlying compiled TEAL code in any way.""" 14 | 15 | def __init__(self, child: Expr, *, compiler_version: str, **kwargs: Any) -> None: 16 | """Define a pragma for a specific subsection of PyTeal code. 17 | 18 | The Pragma expression does not affect the underlying compiled TEAL code in any way, 19 | it merely sets a pragma for the underlying expression. 20 | 21 | Args: 22 | child: The expression to wrap. 23 | compiler_version: Acceptable versions of the compiler. Will fail if the current PyTeal version 24 | is not contained in the range. Follows the npm `semver range scheme `_ 25 | for specifying compatible versions. 26 | 27 | For example: 28 | 29 | .. code-block:: python 30 | 31 | @Subroutine(TealType.uint64) 32 | def example() -> Expr: 33 | # this will fail during compilation if the current PyTeal version does not satisfy 34 | # the version constraint 35 | return Pragma( 36 | Seq(...), 37 | compiler_version="^0.14.0" 38 | ) 39 | """ 40 | super().__init__() 41 | 42 | self.child = child 43 | 44 | if not is_valid_compiler_version(compiler_version): 45 | raise ValueError("Invalid compiler version: {}".format(compiler_version)) 46 | self.compiler_version = compiler_version 47 | 48 | def __teal__(self, options: "CompileOptions"): 49 | pragma(compiler_version=self.compiler_version) 50 | 51 | return self.child.__teal__(options) 52 | 53 | def __str__(self): 54 | return "(pragma {})".format(self.child) 55 | 56 | def type_of(self): 57 | return self.child.type_of() 58 | 59 | def has_return(self): 60 | return self.child.has_return() 61 | 62 | 63 | Pragma.__module__ = "pyteal" 64 | -------------------------------------------------------------------------------- /pyteal/ast/pragma_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from tests.mock_version import mock_version # noqa: F401 3 | 4 | import pyteal as pt 5 | 6 | 7 | @pytest.mark.usefixtures("mock_version") 8 | @pytest.mark.parametrize( 9 | "version, compiler_version, should_error", 10 | [ 11 | # valid 12 | ("0.12.0", "0.12.0", False), 13 | ( 14 | "1.0.0+AVM7.1", 15 | "=1.0.0", 16 | False, 17 | ), 18 | # invalid 19 | ("0.13.0", "0.13.1", True), 20 | ("1.2.3a2", "<0.8.0 || >=0.12.0", True), 21 | ], 22 | ) 23 | def test_pragma_expr(compiler_version, should_error): 24 | program = pt.Pragma(pt.Approve(), compiler_version=compiler_version) 25 | 26 | if should_error: 27 | with pytest.raises(pt.TealPragmaError): 28 | pt.compileTeal(program, mode=pt.Mode.Application, version=6) 29 | else: 30 | pt.compileTeal(program, mode=pt.Mode.Application, version=6) 31 | 32 | 33 | def test_pragma_expr_does_not_change(): 34 | without_pragma = pt.Seq(pt.Pop(pt.Add(pt.Int(1), pt.Int(2))), pt.Return(pt.Int(1))) 35 | pragma = pt.Pragma(without_pragma, compiler_version=">=0.0.0") 36 | 37 | compiled_with_pragma = pt.compileTeal(pragma, mode=pt.Mode.Application, version=6) 38 | compiled_without_pragma = pt.compileTeal( 39 | without_pragma, mode=pt.Mode.Application, version=6 40 | ) 41 | 42 | assert compiled_with_pragma == compiled_without_pragma 43 | 44 | 45 | def test_pragma_expr_has_return(): 46 | exprWithReturn = pt.Pragma(pt.Return(pt.Int(1)), compiler_version=">=0.0.0") 47 | assert exprWithReturn.has_return() 48 | 49 | exprWithoutReturn = pt.Pragma(pt.Int(1), compiler_version=">=0.0.0") 50 | assert not exprWithoutReturn.has_return() 51 | 52 | 53 | @pytest.mark.parametrize( 54 | "compiler_version", 55 | ["not a version", ">=0.1.1,<0.3.0", "1.2.3aq"], # incorrect spec # invalid PEP 440 56 | ) 57 | def test_pragma_expr_invalid_compiler_version(compiler_version): 58 | with pytest.raises(ValueError): 59 | pt.Pragma(pt.Approve(), compiler_version=compiler_version) 60 | -------------------------------------------------------------------------------- /pyteal/ast/stake.py: -------------------------------------------------------------------------------- 1 | from typing import TYPE_CHECKING 2 | 3 | from pyteal.types import TealType 4 | from pyteal.ir import TealOp, Op, TealBlock 5 | from pyteal.errors import verifyProgramVersion 6 | from pyteal.ast.leafexpr import LeafExpr 7 | 8 | if TYPE_CHECKING: 9 | from pyteal.compiler import CompileOptions 10 | 11 | 12 | class OnlineStake(LeafExpr): 13 | """An expression to obtain the online stake for the agreement round.""" 14 | 15 | def __str__(self): 16 | return "(OnlineStake)" 17 | 18 | def __teal__(self, options: "CompileOptions"): 19 | verifyProgramVersion( 20 | Op.online_stake.min_version, 21 | options.version, 22 | "Program version too low to use OnlineStake expression", 23 | ) 24 | 25 | op = TealOp(self, Op.online_stake) 26 | return TealBlock.FromOp(options, op) 27 | 28 | def type_of(self): 29 | return TealType.uint64 30 | 31 | 32 | OnlineStake.__module__ = "pyteal" 33 | -------------------------------------------------------------------------------- /pyteal/ast/stake_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | avm1Options = pt.CompileOptions(version=10) 6 | avm11Options = pt.CompileOptions(version=11) 7 | 8 | 9 | def test_online_stake_teal_10(): 10 | with pytest.raises(pt.TealInputError): 11 | pt.OnlineStake().__teal__(avm1Options) 12 | 13 | 14 | def test_online_stake(): 15 | expr = pt.OnlineStake() 16 | assert expr.type_of() == pt.TealType.uint64 17 | 18 | expected = pt.TealSimpleBlock([pt.TealOp(expr, pt.Op.online_stake)]) 19 | 20 | actual, _ = expr.__teal__(avm11Options) 21 | 22 | assert actual == expected 23 | -------------------------------------------------------------------------------- /pyteal/ast/tmpl_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | options = pt.CompileOptions() 6 | 7 | 8 | def test_tmpl_int(): 9 | expr = pt.Tmpl.Int("TMPL_AMNT") 10 | assert expr.type_of() == pt.TealType.uint64 11 | 12 | expected = pt.TealSimpleBlock([pt.TealOp(expr, pt.Op.int, "TMPL_AMNT")]) 13 | 14 | actual, _ = expr.__teal__(options) 15 | 16 | assert actual == expected 17 | 18 | 19 | def test_tmpl_int_invalid(): 20 | with pytest.raises(pt.TealInputError): 21 | pt.Tmpl.Int("whatever") 22 | 23 | 24 | def test_tmpl_bytes(): 25 | expr = pt.Tmpl.Bytes("TMPL_NOTE") 26 | assert expr.type_of() == pt.TealType.bytes 27 | 28 | expected = pt.TealSimpleBlock([pt.TealOp(expr, pt.Op.byte, "TMPL_NOTE")]) 29 | 30 | actual, _ = expr.__teal__(options) 31 | 32 | assert actual == expected 33 | 34 | 35 | def test_tmpl_bytes_invalid(): 36 | with pytest.raises(pt.TealInputError): 37 | pt.Tmpl.Bytes("whatever") 38 | 39 | 40 | def test_tmpl_addr(): 41 | expr = pt.Tmpl.Addr("TMPL_RECEIVER0") 42 | assert expr.type_of() == pt.TealType.bytes 43 | 44 | expected = pt.TealSimpleBlock([pt.TealOp(expr, pt.Op.addr, "TMPL_RECEIVER0")]) 45 | 46 | actual, _ = expr.__teal__(options) 47 | 48 | assert actual == expected 49 | 50 | 51 | def test_tmpl_addr_invalid(): 52 | with pytest.raises(pt.TealInputError): 53 | pt.Tmpl.Addr("whatever") 54 | -------------------------------------------------------------------------------- /pyteal/compiler/__init__.py: -------------------------------------------------------------------------------- 1 | from pyteal.compiler.compiler import ( 2 | MAX_TEAL_VERSION, 3 | MIN_TEAL_VERSION, 4 | DEFAULT_TEAL_VERSION, 5 | MAX_PROGRAM_VERSION, 6 | MIN_PROGRAM_VERSION, 7 | DEFAULT_PROGRAM_VERSION, 8 | CompileOptions, 9 | Compilation, 10 | CompileResults, 11 | compileTeal, 12 | ) 13 | from pyteal.compiler.optimizer import OptimizeOptions 14 | from pyteal.compiler.sourcemap import PyTealSourceMap, R3SourceMap 15 | 16 | 17 | __all__ = [ 18 | "MAX_TEAL_VERSION", 19 | "MIN_TEAL_VERSION", 20 | "DEFAULT_TEAL_VERSION", 21 | "MAX_PROGRAM_VERSION", 22 | "MIN_PROGRAM_VERSION", 23 | "DEFAULT_PROGRAM_VERSION", 24 | "CompileOptions", 25 | "Compilation", 26 | "CompileResults", 27 | "compileTeal", 28 | "OptimizeOptions", 29 | "PyTealSourceMap", 30 | "R3SourceMap", 31 | ] 32 | -------------------------------------------------------------------------------- /pyteal/compiler/optimizer/__init__.py: -------------------------------------------------------------------------------- 1 | from pyteal.compiler.optimizer.optimizer import ( 2 | OptimizeOptions, 3 | apply_global_optimizations, 4 | ) 5 | -------------------------------------------------------------------------------- /pyteal/compiler/sort.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | from pyteal.ir import TealBlock 4 | from pyteal.errors import TealInternalError 5 | 6 | 7 | def sortBlocks(start: TealBlock, end: TealBlock) -> List[TealBlock]: 8 | """Topologically sort the graph which starts with the input TealBlock. 9 | 10 | Args: 11 | start: The starting point of the graph to sort. 12 | 13 | Returns: 14 | An ordered list of TealBlocks that is sorted such that every block is guaranteed to appear 15 | in the list before all of its outgoing blocks. 16 | """ 17 | S = [start] 18 | order = [] 19 | visited = set() # I changed visited to a set to be more efficient 20 | while len(S) != 0: 21 | n = S.pop() 22 | 23 | if id(n) in visited: 24 | continue 25 | 26 | S += n.getOutgoing() 27 | 28 | order.append(n) 29 | visited.add(id(n)) 30 | 31 | endIndex = -1 32 | for i, block in enumerate(order): 33 | if block is end: 34 | endIndex = i 35 | break 36 | 37 | if endIndex == -1: 38 | raise TealInternalError("End block not present") 39 | 40 | order.pop(endIndex) 41 | order.append(end) 42 | 43 | return order 44 | -------------------------------------------------------------------------------- /pyteal/config.py: -------------------------------------------------------------------------------- 1 | from algosdk.atomic_transaction_composer import ABI_RETURN_HASH 2 | 3 | 4 | # Maximum size of an atomic transaction group. 5 | MAX_GROUP_SIZE = 16 6 | 7 | # Number of scratch space slots available. 8 | NUM_SLOTS = 256 9 | 10 | # Method return selector in base16 11 | RETURN_HASH_PREFIX = ABI_RETURN_HASH 12 | 13 | # Method argument number limit 14 | METHOD_ARG_NUM_CUTOFF = 15 15 | -------------------------------------------------------------------------------- /pyteal/ir/__init__.py: -------------------------------------------------------------------------------- 1 | from pyteal.ir.ops import Op, Mode 2 | from pyteal.ir.tealblock import TealBlock 3 | from pyteal.ir.tealcomponent import TealComponent 4 | from pyteal.ir.tealconditionalblock import TealConditionalBlock 5 | from pyteal.ir.teallabel import TealLabel 6 | from pyteal.ir.tealop import TealOp 7 | from pyteal.ir.tealpragma import TealPragma 8 | from pyteal.ir.tealsimpleblock import TealSimpleBlock 9 | 10 | from pyteal.ir.labelref import LabelReference 11 | 12 | __all__ = [ 13 | "LabelReference", 14 | "Mode", 15 | "Op", 16 | "TealBlock", 17 | "TealComponent", 18 | "TealConditionalBlock", 19 | "TealLabel", 20 | "TealOp", 21 | "TealPragma", 22 | "TealSimpleBlock", 23 | ] 24 | -------------------------------------------------------------------------------- /pyteal/ir/labelref.py: -------------------------------------------------------------------------------- 1 | class LabelReference: 2 | def __init__(self, label: str) -> None: 3 | self.label = label 4 | 5 | def addPrefix(self, prefix: str) -> None: 6 | self.label = prefix + self.label 7 | 8 | def getLabel(self) -> str: 9 | return self.label 10 | 11 | def __repr__(self) -> str: 12 | return repr(self.label) 13 | 14 | def __hash__(self) -> int: 15 | return hash(self.label) 16 | 17 | def __eq__(self, other) -> bool: 18 | if not isinstance(other, LabelReference): 19 | return False 20 | return self.label == other.label 21 | -------------------------------------------------------------------------------- /pyteal/ir/tealcomponent_test.py: -------------------------------------------------------------------------------- 1 | import pyteal as pt 2 | 3 | 4 | def test_EqualityContext(): 5 | expr1 = pt.Int(1) 6 | expr2 = pt.Int(1) 7 | 8 | op1 = pt.TealOp(expr1, pt.Op.int, 1) 9 | op2 = pt.TealOp(expr2, pt.Op.int, 1) 10 | 11 | assert op1 == op1 12 | assert op2 == op2 13 | assert op1 != op2 14 | assert op2 != op1 15 | 16 | with pt.TealComponent.Context.ignoreExprEquality(): 17 | assert op1 == op1 18 | assert op2 == op2 19 | assert op1 == op2 20 | assert op2 == op1 21 | -------------------------------------------------------------------------------- /pyteal/ir/tealconditionalblock.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | from pyteal.ir.tealop import TealOp 4 | from pyteal.ir.tealblock import TealBlock 5 | 6 | 7 | class TealConditionalBlock(TealBlock): 8 | """Represents a basic block of TealComponents in a graph ending with a branch condition.""" 9 | 10 | def __init__(self, ops: List[TealOp], root_expr: "Expr | None" = None) -> None: # type: ignore 11 | super().__init__(ops, root_expr=root_expr) 12 | self.trueBlock: TealBlock | None = None 13 | self.falseBlock: TealBlock | None = None 14 | 15 | def setTrueBlock(self, block: TealBlock) -> None: 16 | """Set the block that this one should branch to if its condition is true.""" 17 | self.trueBlock = block 18 | 19 | def setFalseBlock(self, block: TealBlock) -> None: 20 | """Set the block that this one should branch to if its condition is false.""" 21 | self.falseBlock = block 22 | 23 | def getOutgoing(self) -> List[TealBlock]: 24 | outgoing = [] 25 | if self.trueBlock is not None: 26 | outgoing.append(self.trueBlock) 27 | if self.falseBlock is not None: 28 | outgoing.append(self.falseBlock) 29 | return outgoing 30 | 31 | def replaceOutgoing(self, oldBlock: TealBlock, newBlock: TealBlock) -> None: 32 | if self.trueBlock is oldBlock: 33 | self.trueBlock = newBlock 34 | elif self.falseBlock is oldBlock: 35 | self.falseBlock = newBlock 36 | 37 | def __repr__(self) -> str: 38 | return "TealConditionalBlock({}, true={}, false={}, conditional={})".format( 39 | repr(self.ops), 40 | repr(self.trueBlock), 41 | repr(self.falseBlock), 42 | repr(self._sframes_container), 43 | ) 44 | 45 | def __eq__(self, other: object) -> bool: 46 | if type(other) is not TealConditionalBlock: 47 | return False 48 | return ( 49 | self.ops == other.ops 50 | and self.trueBlock == other.trueBlock 51 | and self.falseBlock == other.falseBlock 52 | ) 53 | 54 | 55 | TealConditionalBlock.__module__ = "pyteal" 56 | -------------------------------------------------------------------------------- /pyteal/ir/tealconditionalblock_test.py: -------------------------------------------------------------------------------- 1 | import pyteal as pt 2 | 3 | 4 | def test_constructor(): 5 | block1 = pt.TealConditionalBlock([]) 6 | assert block1.ops == [] 7 | assert block1.trueBlock is None 8 | assert block1.falseBlock is None 9 | 10 | block2 = pt.TealConditionalBlock([pt.TealOp(None, pt.Op.int, 1)]) 11 | assert block2.ops == [pt.TealOp(None, pt.Op.int, 1)] 12 | assert block2.trueBlock is None 13 | assert block2.falseBlock is None 14 | 15 | 16 | def test_true_block(): 17 | block = pt.TealConditionalBlock([]) 18 | block.setTrueBlock(pt.TealSimpleBlock([pt.TealOp(None, pt.Op.substring3)])) 19 | assert block.trueBlock == pt.TealSimpleBlock([pt.TealOp(None, pt.Op.substring3)]) 20 | assert block.getOutgoing() == [ 21 | pt.TealSimpleBlock([pt.TealOp(None, pt.Op.substring3)]) 22 | ] 23 | 24 | 25 | def test_false_block(): 26 | block = pt.TealConditionalBlock([]) 27 | block.setFalseBlock(pt.TealSimpleBlock([pt.TealOp(None, pt.Op.substring3)])) 28 | assert block.falseBlock == pt.TealSimpleBlock([pt.TealOp(None, pt.Op.substring3)]) 29 | 30 | 31 | def test_outgoing(): 32 | emptyBlock = pt.TealConditionalBlock([]) 33 | assert emptyBlock.getOutgoing() == [] 34 | 35 | trueBlock = pt.TealConditionalBlock([]) 36 | trueBlock.setTrueBlock(pt.TealSimpleBlock([pt.TealOp(None, pt.Op.byte, '"true"')])) 37 | assert trueBlock.getOutgoing() == [ 38 | pt.TealSimpleBlock([pt.TealOp(None, pt.Op.byte, '"true"')]) 39 | ] 40 | 41 | falseBlock = pt.TealConditionalBlock([]) 42 | falseBlock.setFalseBlock( 43 | pt.TealSimpleBlock([pt.TealOp(None, pt.Op.byte, '"false"')]) 44 | ) 45 | assert falseBlock.getOutgoing() == [ 46 | pt.TealSimpleBlock([pt.TealOp(None, pt.Op.byte, '"false"')]) 47 | ] 48 | 49 | bothBlock = pt.TealConditionalBlock([]) 50 | bothBlock.setTrueBlock(pt.TealSimpleBlock([pt.TealOp(None, pt.Op.byte, '"true"')])) 51 | bothBlock.setFalseBlock( 52 | pt.TealSimpleBlock([pt.TealOp(None, pt.Op.byte, '"false"')]) 53 | ) 54 | assert bothBlock.getOutgoing() == [ 55 | pt.TealSimpleBlock([pt.TealOp(None, pt.Op.byte, '"true"')]), 56 | pt.TealSimpleBlock([pt.TealOp(None, pt.Op.byte, '"false"')]), 57 | ] 58 | -------------------------------------------------------------------------------- /pyteal/ir/teallabel.py: -------------------------------------------------------------------------------- 1 | from typing import TYPE_CHECKING 2 | 3 | from pyteal.ir.tealcomponent import TealComponent 4 | from pyteal.ir.labelref import LabelReference 5 | 6 | if TYPE_CHECKING: 7 | from pyteal.ast import Expr 8 | 9 | 10 | class TealLabel(TealComponent): 11 | def __init__( 12 | self, expr: "Expr | None", label: LabelReference, comment: str | None = None 13 | ) -> None: 14 | super().__init__(expr) 15 | self.label = label 16 | self.comment = comment 17 | 18 | def getLabelRef(self) -> LabelReference: 19 | return self.label 20 | 21 | def assemble(self) -> str: 22 | comment = "\n// {}\n".format(self.comment) if self.comment is not None else "" 23 | return "{}{}:".format(comment, self.label.getLabel()) 24 | 25 | def __repr__(self) -> str: 26 | return "TealLabel({}, {}, {})".format( 27 | self.expr, repr(self.label), repr(self.comment) 28 | ) 29 | 30 | def __hash__(self) -> int: 31 | return hash((self.label, self.comment)) 32 | 33 | def __eq__(self, other: object) -> bool: 34 | if not isinstance(other, TealLabel): 35 | return False 36 | if TealComponent.Context.checkExprEquality and self.expr is not other.expr: 37 | return False 38 | return self.label == other.label and self.comment == other.comment 39 | 40 | 41 | TealLabel.__module__ = "pyteal" 42 | -------------------------------------------------------------------------------- /pyteal/ir/tealpragma.py: -------------------------------------------------------------------------------- 1 | from pyteal.ir.tealcomponent import TealComponent 2 | 3 | 4 | class TealPragma(TealComponent): 5 | _name: str 6 | _value: str | int 7 | 8 | def __init__(self, version: int | None = None, *, type_track: bool | None = None): 9 | """Creates an assembler pragma statement. 10 | 11 | Only one of the arguments should be set. 12 | 13 | Args: 14 | version (optional): Sets the program version. 15 | type_track (optional): Configures assembler type tracking. 16 | """ 17 | super().__init__(None) 18 | 19 | if len([x for x in [version, type_track] if x is not None]) != 1: 20 | raise ValueError("Exactly one of version or type_track must be set") 21 | 22 | if version is not None: 23 | self._name = "version" 24 | self._value = version 25 | elif type_track is not None: 26 | self._name = "typetrack" 27 | self._value = "true" if type_track else "false" 28 | else: 29 | # Shouldn't happen, just to satisfy type checker 30 | raise ValueError("Empty pragma statement") 31 | 32 | def assemble(self) -> str: 33 | return f"#pragma {self._name} {self._value}" 34 | 35 | def __repr__(self) -> str: 36 | match self._name: 37 | case "version": 38 | name = "version" 39 | value = self._value 40 | case "typetrack": 41 | name = "type_track" 42 | value = self._value == "true" 43 | case _: 44 | raise ValueError(f"Unknown pragma name: {self._name}") 45 | return f"TealPragma({name}={value})" 46 | 47 | def __hash__(self) -> int: 48 | return hash(repr(self)) 49 | 50 | def __eq__(self, other: object) -> bool: 51 | if not isinstance(other, TealPragma): 52 | return False 53 | return self._name == other._name and self._value == other._value 54 | 55 | 56 | TealPragma.__module__ = "pyteal" 57 | -------------------------------------------------------------------------------- /pyteal/ir/tealpragma_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import pyteal as pt 3 | 4 | 5 | def test_version(): 6 | for i in range(10): 7 | version_pragma = pt.TealPragma(version=i) 8 | assert version_pragma._name == "version" 9 | assert version_pragma._value == i 10 | assert version_pragma.assemble() == f"#pragma version {i}" 11 | assert repr(version_pragma) == f"TealPragma(version={i})" 12 | 13 | 14 | def test_type_track(): 15 | for value in (True, False): 16 | type_track_pragma = pt.TealPragma(type_track=value) 17 | assert type_track_pragma._name == "typetrack" 18 | assert type_track_pragma._value == str(value).lower() 19 | assert type_track_pragma.assemble() == f"#pragma typetrack {str(value).lower()}" 20 | assert repr(type_track_pragma) == f"TealPragma(type_track={value})" 21 | 22 | 23 | def test_empty(): 24 | with pytest.raises(ValueError): 25 | pt.TealPragma() 26 | 27 | 28 | def test_both(): 29 | with pytest.raises(ValueError): 30 | pt.TealPragma(version=1, type_track=True) 31 | -------------------------------------------------------------------------------- /pyteal/ir/tealsimpleblock.py: -------------------------------------------------------------------------------- 1 | from pyteal.ir.tealblock import TealBlock 2 | from pyteal.ir.tealop import TealOp 3 | 4 | 5 | class TealSimpleBlock(TealBlock): 6 | """Represents a basic block of TealComponents in a graph that does not contain a branch condition.""" 7 | 8 | def __init__(self, ops: list[TealOp]) -> None: 9 | super().__init__(ops) 10 | self.nextBlock: TealBlock | None = None 11 | self.visited = False 12 | 13 | def setNextBlock(self, block: TealBlock) -> None: 14 | """Set the block that follows this one.""" 15 | self.nextBlock = block 16 | 17 | def getOutgoing(self) -> list[TealBlock]: 18 | if self.nextBlock is None: 19 | return [] 20 | return [self.nextBlock] 21 | 22 | def replaceOutgoing(self, oldBlock: TealBlock, newBlock: TealBlock) -> None: 23 | if self.nextBlock is oldBlock: 24 | self.nextBlock = newBlock 25 | 26 | def __repr__(self) -> str: 27 | # check for loop 28 | if self.visited: 29 | return "TealSimpleBlock({}, next={})".format( 30 | repr(self.ops), 31 | "", 32 | ) 33 | self.visited = True 34 | 35 | s = "TealSimpleBlock({}, next={})".format( 36 | repr(self.ops), 37 | repr(self.nextBlock), 38 | ) 39 | 40 | self.visited = False 41 | return s 42 | 43 | def __eq__(self, other: object) -> bool: 44 | # check for loop 45 | if self.visited: 46 | return True 47 | if type(other) is not TealSimpleBlock: 48 | return False 49 | self.visited = True 50 | equal = self.ops == other.ops and self.nextBlock == other.nextBlock 51 | self.visited = False 52 | return equal 53 | 54 | 55 | TealSimpleBlock.__module__ = "pyteal" 56 | -------------------------------------------------------------------------------- /pyteal/ir/tealsimpleblock_test.py: -------------------------------------------------------------------------------- 1 | import pyteal as pt 2 | 3 | 4 | def test_constructor(): 5 | block1 = pt.TealSimpleBlock([]) 6 | assert block1.ops == [] 7 | assert block1.nextBlock is None 8 | 9 | block2 = pt.TealSimpleBlock([pt.TealOp(None, pt.Op.int, 1)]) 10 | assert block2.ops == [pt.TealOp(None, pt.Op.int, 1)] 11 | assert block2.nextBlock is None 12 | 13 | 14 | def test_next_block(): 15 | block = pt.TealSimpleBlock([]) 16 | block.setNextBlock(pt.TealSimpleBlock([pt.TealOp(None, pt.Op.substring3)])) 17 | assert block.nextBlock == pt.TealSimpleBlock([pt.TealOp(None, pt.Op.substring3)]) 18 | 19 | 20 | def test_outgoing(): 21 | emptyBlock = pt.TealSimpleBlock([]) 22 | assert emptyBlock.getOutgoing() == [] 23 | 24 | block = pt.TealSimpleBlock([]) 25 | block.setNextBlock(pt.TealSimpleBlock([pt.TealOp(None, pt.Op.byte, '"nextBlock"')])) 26 | assert block.getOutgoing() == [ 27 | pt.TealSimpleBlock([pt.TealOp(None, pt.Op.byte, '"nextBlock"')]) 28 | ] 29 | -------------------------------------------------------------------------------- /pyteal/pragma/__init__.py: -------------------------------------------------------------------------------- 1 | from pyteal.pragma.pragma import is_valid_compiler_version, pragma 2 | 3 | __all__ = [ 4 | "is_valid_compiler_version", 5 | "pragma", 6 | ] 7 | -------------------------------------------------------------------------------- /pyteal/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorand/pyteal/9a610281df4f306f2a0f94483f4a009320a5c63c/pyteal/py.typed -------------------------------------------------------------------------------- /pyteal/types_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | from pyteal.types import require_type 5 | 6 | 7 | def test_require_type(): 8 | require_type(pt.Bytes("str"), pt.TealType.bytes) 9 | assert True 10 | 11 | 12 | def test_require_type_invalid(): 13 | with pytest.raises(TypeError): 14 | pt.App.globalGet(["This is certainly invalid"]) 15 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | markers = 3 | serial: marks tests requiring serial execution 4 | slow: marks tests which are slow 5 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | black==24.8.0 2 | flake8==6.1.0 3 | flake8-tidy-imports==4.10.0 4 | graviton@git+https://github.com/algorand/graviton@v0.9.0 5 | mypy==1.7.1 6 | pytest==7.4.3 7 | pytest-cov==3.0.0 8 | pytest-custom-exit-code==0.3.0 9 | pytest-timeout==2.1.0 10 | pytest-xdist==3.0.2 11 | setuptools==70.0.0 12 | types-setuptools==70.0.0.20240524 13 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import setuptools 4 | 5 | with open("README.md", "r") as fh: 6 | long_description = fh.read() 7 | 8 | setuptools.setup( 9 | name="pyteal", 10 | version="0.27.0", 11 | author="Algorand", 12 | author_email="pypiservice@algorand.com", 13 | description="Algorand Smart Contracts in Python", 14 | long_description=long_description, 15 | long_description_content_type="text/markdown", 16 | url="https://github.com/algorand/pyteal", 17 | packages=setuptools.find_packages( 18 | include=( 19 | "feature_gates", 20 | "pyteal", 21 | "pyteal.*", 22 | ) 23 | ), 24 | install_requires=[ 25 | # when changing this list, also update docs/requirements.txt 26 | "docstring-parser==0.14.1", 27 | "executing==2.0.1", 28 | "py-algorand-sdk>=2.0.0,<3.0.0", 29 | "semantic-version>=2.9.0,<3.0.0", 30 | "tabulate>=0.9.0,<0.10.0", 31 | ], 32 | classifiers=[ 33 | "Programming Language :: Python :: 3", 34 | "License :: OSI Approved :: MIT License", 35 | "Operating System :: OS Independent", 36 | ], 37 | package_data={"pyteal": ["*.pyi", "py.typed"]}, 38 | python_requires=">=3.10", 39 | ) 40 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorand/pyteal/9a610281df4f306f2a0f94483f4a009320a5c63c/tests/__init__.py -------------------------------------------------------------------------------- /tests/compile_asserts.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | from difflib import unified_diff 3 | 4 | from pyteal.compiler import compileTeal 5 | from pyteal.ir import Mode 6 | 7 | PATH = Path.cwd() / "tests" / "unit" 8 | FIXTURES = PATH / "teal" 9 | GENERATED = PATH / "generated" 10 | 11 | 12 | def compile_and_save(approval, version: int, test_name: str) -> tuple[Path, str, str]: 13 | compiled = compileTeal(approval(), mode=Mode.Application, version=version) 14 | name = approval.__name__ 15 | tealdir = GENERATED / test_name 16 | tealdir.mkdir(parents=True, exist_ok=True) 17 | with open(tealdir / (name + ".teal"), "w") as f: 18 | f.write(compiled) 19 | print( 20 | f"""Successfuly tested approval program <<{name}>> having 21 | compiled it into {len(compiled)} characters. See the results in: 22 | {tealdir} 23 | """ 24 | ) 25 | return tealdir, name, compiled 26 | 27 | 28 | def assert_teal_as_expected(path2actual: Path, path2expected: Path): 29 | with open(path2actual, "r") as f: 30 | actual_lines = f.readlines() 31 | 32 | with open(path2expected, "r") as f: 33 | expected_lines = f.readlines() 34 | 35 | diff = list( 36 | unified_diff( 37 | expected_lines, 38 | actual_lines, 39 | fromfile=str(path2expected), 40 | tofile=str(path2actual), 41 | n=3, 42 | ) 43 | ) 44 | 45 | assert ( 46 | len(diff) == 0 47 | ), f"Difference between expected and actual TEAL code:\n\n{''.join(diff)}" 48 | 49 | 50 | def assert_new_v_old(approve_func, version: int, test_name: str): 51 | tealdir, name, compiled = compile_and_save(approve_func, version, test_name) 52 | 53 | print( 54 | f"""Compilation resulted in TEAL program of length {len(compiled)}. 55 | To view output SEE <{name}.teal> in ({tealdir}) 56 | --------------""" 57 | ) 58 | 59 | path2actual = tealdir / (name + ".teal") 60 | path2expected = FIXTURES / test_name / (name + ".teal") 61 | assert_teal_as_expected(path2actual, path2expected) 62 | -------------------------------------------------------------------------------- /tests/integration/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorand/pyteal/9a610281df4f306f2a0f94483f4a009320a5c63c/tests/integration/__init__.py -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_()_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | byte "" 18 | store 7 19 | load 7 20 | retsub 21 | 22 | // round_tripper 23 | roundtripper_1: 24 | store 2 25 | load 2 26 | callsub tuplecomplement_0 27 | store 4 28 | load 4 29 | callsub tuplecomplement_0 30 | store 5 31 | load 2 32 | load 4 33 | concat 34 | load 5 35 | concat 36 | store 3 37 | load 3 38 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_()_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dup 20 | byte "" 21 | dup 22 | byte "" 23 | frame_bury 0 24 | retsub 25 | 26 | // round_tripper 27 | roundtripper_1: 28 | proto 1 1 29 | byte "" 30 | dupn 2 31 | int 0 32 | dup 33 | byte "" 34 | dup 35 | frame_dig -1 36 | callsub tuplecomplement_0 37 | frame_bury 1 38 | frame_dig 1 39 | callsub tuplecomplement_0 40 | frame_bury 2 41 | frame_dig -1 42 | frame_dig 1 43 | concat 44 | frame_dig 2 45 | concat 46 | frame_bury 0 47 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(bool)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | int 0 19 | getbit 20 | store 8 21 | load 8 22 | callsub boolcomp_2 23 | store 8 24 | byte 0x00 25 | int 0 26 | load 8 27 | setbit 28 | store 7 29 | load 7 30 | retsub 31 | 32 | // round_tripper 33 | roundtripper_1: 34 | store 2 35 | load 2 36 | callsub tuplecomplement_0 37 | store 4 38 | load 4 39 | callsub tuplecomplement_0 40 | store 5 41 | load 2 42 | load 4 43 | concat 44 | load 5 45 | concat 46 | store 3 47 | load 3 48 | retsub 49 | 50 | // bool_comp 51 | boolcomp_2: 52 | store 9 53 | load 9 54 | ! 55 | ! 56 | ! 57 | store 10 58 | load 10 59 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(bool)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 2 20 | byte "" 21 | dup 22 | frame_dig -1 23 | int 0 24 | getbit 25 | frame_bury 1 26 | frame_dig 1 27 | callsub boolcomp_2 28 | frame_bury 1 29 | byte 0x00 30 | int 0 31 | frame_dig 1 32 | setbit 33 | frame_bury 0 34 | retsub 35 | 36 | // round_tripper 37 | roundtripper_1: 38 | proto 1 1 39 | byte "" 40 | dupn 2 41 | int 0 42 | dup 43 | byte "" 44 | dup 45 | frame_dig -1 46 | callsub tuplecomplement_0 47 | frame_bury 1 48 | frame_dig 1 49 | callsub tuplecomplement_0 50 | frame_bury 2 51 | frame_dig -1 52 | frame_dig 1 53 | concat 54 | frame_dig 2 55 | concat 56 | frame_bury 0 57 | retsub 58 | 59 | // bool_comp 60 | boolcomp_2: 61 | proto 1 1 62 | int 0 63 | frame_dig -1 64 | ! 65 | ! 66 | ! 67 | frame_bury 0 68 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(bool,byte)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | int 0 19 | getbit 20 | store 8 21 | load 6 22 | int 1 23 | getbyte 24 | store 9 25 | load 8 26 | callsub boolcomp_2 27 | store 8 28 | load 9 29 | callsub numericalcomp_3 30 | store 9 31 | byte 0x00 32 | int 0 33 | load 8 34 | setbit 35 | byte 0x00 36 | int 0 37 | load 9 38 | setbyte 39 | concat 40 | store 7 41 | load 7 42 | retsub 43 | 44 | // round_tripper 45 | roundtripper_1: 46 | store 2 47 | load 2 48 | callsub tuplecomplement_0 49 | store 4 50 | load 4 51 | callsub tuplecomplement_0 52 | store 5 53 | load 2 54 | load 4 55 | concat 56 | load 5 57 | concat 58 | store 3 59 | load 3 60 | retsub 61 | 62 | // bool_comp 63 | boolcomp_2: 64 | store 10 65 | load 10 66 | ! 67 | ! 68 | ! 69 | store 11 70 | load 11 71 | retsub 72 | 73 | // numerical_comp 74 | numericalcomp_3: 75 | store 12 76 | int 255 77 | load 12 78 | - 79 | store 13 80 | load 13 81 | int 256 82 | < 83 | assert 84 | load 13 85 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(bool,byte)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 3 20 | byte "" 21 | dup 22 | frame_dig -1 23 | int 0 24 | getbit 25 | frame_bury 1 26 | frame_dig -1 27 | int 1 28 | getbyte 29 | frame_bury 2 30 | frame_dig 1 31 | callsub boolcomp_2 32 | frame_bury 1 33 | frame_dig 2 34 | callsub numericalcomp_3 35 | frame_bury 2 36 | byte 0x00 37 | int 0 38 | frame_dig 1 39 | setbit 40 | byte 0x00 41 | int 0 42 | frame_dig 2 43 | setbyte 44 | concat 45 | frame_bury 0 46 | retsub 47 | 48 | // round_tripper 49 | roundtripper_1: 50 | proto 1 1 51 | byte "" 52 | dupn 2 53 | int 0 54 | dup 55 | byte "" 56 | dup 57 | frame_dig -1 58 | callsub tuplecomplement_0 59 | frame_bury 1 60 | frame_dig 1 61 | callsub tuplecomplement_0 62 | frame_bury 2 63 | frame_dig -1 64 | frame_dig 1 65 | concat 66 | frame_dig 2 67 | concat 68 | frame_bury 0 69 | retsub 70 | 71 | // bool_comp 72 | boolcomp_2: 73 | proto 1 1 74 | int 0 75 | frame_dig -1 76 | ! 77 | ! 78 | ! 79 | frame_bury 0 80 | retsub 81 | 82 | // numerical_comp 83 | numericalcomp_3: 84 | proto 1 1 85 | int 0 86 | int 255 87 | frame_dig -1 88 | - 89 | frame_bury 0 90 | frame_dig 0 91 | int 256 92 | < 93 | assert 94 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(bool,uint64,uint32)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | int 0 19 | getbit 20 | store 8 21 | load 6 22 | int 1 23 | extract_uint64 24 | store 9 25 | load 6 26 | int 9 27 | extract_uint32 28 | store 10 29 | load 8 30 | callsub boolcomp_2 31 | store 8 32 | load 9 33 | callsub numericalcomp_3 34 | store 9 35 | load 10 36 | callsub numericalcomp_4 37 | store 10 38 | byte 0x00 39 | int 0 40 | load 8 41 | setbit 42 | load 9 43 | itob 44 | concat 45 | load 10 46 | itob 47 | extract 4 0 48 | concat 49 | store 7 50 | load 7 51 | retsub 52 | 53 | // round_tripper 54 | roundtripper_1: 55 | store 2 56 | load 2 57 | callsub tuplecomplement_0 58 | store 4 59 | load 4 60 | callsub tuplecomplement_0 61 | store 5 62 | load 2 63 | load 4 64 | concat 65 | load 5 66 | concat 67 | store 3 68 | load 3 69 | retsub 70 | 71 | // bool_comp 72 | boolcomp_2: 73 | store 11 74 | load 11 75 | ! 76 | ! 77 | ! 78 | store 12 79 | load 12 80 | retsub 81 | 82 | // numerical_comp 83 | numericalcomp_3: 84 | store 13 85 | int 18446744073709551615 86 | load 13 87 | - 88 | store 14 89 | load 14 90 | retsub 91 | 92 | // numerical_comp 93 | numericalcomp_4: 94 | store 15 95 | int 4294967295 96 | load 15 97 | - 98 | store 16 99 | load 16 100 | int 4294967296 101 | < 102 | assert 103 | load 16 104 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(bool,uint64,uint32)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 4 20 | byte "" 21 | dup 22 | frame_dig -1 23 | int 0 24 | getbit 25 | frame_bury 1 26 | frame_dig -1 27 | int 1 28 | extract_uint64 29 | frame_bury 2 30 | frame_dig -1 31 | int 9 32 | extract_uint32 33 | frame_bury 3 34 | frame_dig 1 35 | callsub boolcomp_2 36 | frame_bury 1 37 | frame_dig 2 38 | callsub numericalcomp_3 39 | frame_bury 2 40 | frame_dig 3 41 | callsub numericalcomp_4 42 | frame_bury 3 43 | byte 0x00 44 | int 0 45 | frame_dig 1 46 | setbit 47 | frame_dig 2 48 | itob 49 | concat 50 | frame_dig 3 51 | itob 52 | extract 4 0 53 | concat 54 | frame_bury 0 55 | retsub 56 | 57 | // round_tripper 58 | roundtripper_1: 59 | proto 1 1 60 | byte "" 61 | dupn 2 62 | int 0 63 | dup 64 | byte "" 65 | dup 66 | frame_dig -1 67 | callsub tuplecomplement_0 68 | frame_bury 1 69 | frame_dig 1 70 | callsub tuplecomplement_0 71 | frame_bury 2 72 | frame_dig -1 73 | frame_dig 1 74 | concat 75 | frame_dig 2 76 | concat 77 | frame_bury 0 78 | retsub 79 | 80 | // bool_comp 81 | boolcomp_2: 82 | proto 1 1 83 | int 0 84 | frame_dig -1 85 | ! 86 | ! 87 | ! 88 | frame_bury 0 89 | retsub 90 | 91 | // numerical_comp 92 | numericalcomp_3: 93 | proto 1 1 94 | int 0 95 | int 18446744073709551615 96 | frame_dig -1 97 | - 98 | frame_bury 0 99 | retsub 100 | 101 | // numerical_comp 102 | numericalcomp_4: 103 | proto 1 1 104 | int 0 105 | int 4294967295 106 | frame_dig -1 107 | - 108 | frame_bury 0 109 | frame_dig 0 110 | int 4294967296 111 | < 112 | assert 113 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(byte)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | int 0 19 | getbyte 20 | store 8 21 | load 8 22 | callsub numericalcomp_2 23 | store 8 24 | byte 0x00 25 | int 0 26 | load 8 27 | setbyte 28 | store 7 29 | load 7 30 | retsub 31 | 32 | // round_tripper 33 | roundtripper_1: 34 | store 2 35 | load 2 36 | callsub tuplecomplement_0 37 | store 4 38 | load 4 39 | callsub tuplecomplement_0 40 | store 5 41 | load 2 42 | load 4 43 | concat 44 | load 5 45 | concat 46 | store 3 47 | load 3 48 | retsub 49 | 50 | // numerical_comp 51 | numericalcomp_2: 52 | store 9 53 | int 255 54 | load 9 55 | - 56 | store 10 57 | load 10 58 | int 256 59 | < 60 | assert 61 | load 10 62 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(byte)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 2 20 | byte "" 21 | dup 22 | frame_dig -1 23 | int 0 24 | getbyte 25 | frame_bury 1 26 | frame_dig 1 27 | callsub numericalcomp_2 28 | frame_bury 1 29 | byte 0x00 30 | int 0 31 | frame_dig 1 32 | setbyte 33 | frame_bury 0 34 | retsub 35 | 36 | // round_tripper 37 | roundtripper_1: 38 | proto 1 1 39 | byte "" 40 | dupn 2 41 | int 0 42 | dup 43 | byte "" 44 | dup 45 | frame_dig -1 46 | callsub tuplecomplement_0 47 | frame_bury 1 48 | frame_dig 1 49 | callsub tuplecomplement_0 50 | frame_bury 2 51 | frame_dig -1 52 | frame_dig 1 53 | concat 54 | frame_dig 2 55 | concat 56 | frame_bury 0 57 | retsub 58 | 59 | // numerical_comp 60 | numericalcomp_2: 61 | proto 1 1 62 | int 0 63 | int 255 64 | frame_dig -1 65 | - 66 | frame_bury 0 67 | frame_dig 0 68 | int 256 69 | < 70 | assert 71 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(byte,bool,uint64)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | int 0 19 | getbyte 20 | store 8 21 | load 6 22 | int 8 23 | getbit 24 | store 9 25 | load 6 26 | int 2 27 | extract_uint64 28 | store 10 29 | load 8 30 | callsub numericalcomp_2 31 | store 8 32 | load 9 33 | callsub boolcomp_3 34 | store 9 35 | load 10 36 | callsub numericalcomp_4 37 | store 10 38 | byte 0x00 39 | int 0 40 | load 8 41 | setbyte 42 | byte 0x00 43 | int 0 44 | load 9 45 | setbit 46 | concat 47 | load 10 48 | itob 49 | concat 50 | store 7 51 | load 7 52 | retsub 53 | 54 | // round_tripper 55 | roundtripper_1: 56 | store 2 57 | load 2 58 | callsub tuplecomplement_0 59 | store 4 60 | load 4 61 | callsub tuplecomplement_0 62 | store 5 63 | load 2 64 | load 4 65 | concat 66 | load 5 67 | concat 68 | store 3 69 | load 3 70 | retsub 71 | 72 | // numerical_comp 73 | numericalcomp_2: 74 | store 11 75 | int 255 76 | load 11 77 | - 78 | store 12 79 | load 12 80 | int 256 81 | < 82 | assert 83 | load 12 84 | retsub 85 | 86 | // bool_comp 87 | boolcomp_3: 88 | store 13 89 | load 13 90 | ! 91 | ! 92 | ! 93 | store 14 94 | load 14 95 | retsub 96 | 97 | // numerical_comp 98 | numericalcomp_4: 99 | store 15 100 | int 18446744073709551615 101 | load 15 102 | - 103 | store 16 104 | load 16 105 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(byte,bool,uint64)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 4 20 | byte "" 21 | dup 22 | frame_dig -1 23 | int 0 24 | getbyte 25 | frame_bury 1 26 | frame_dig -1 27 | int 8 28 | getbit 29 | frame_bury 2 30 | frame_dig -1 31 | int 2 32 | extract_uint64 33 | frame_bury 3 34 | frame_dig 1 35 | callsub numericalcomp_2 36 | frame_bury 1 37 | frame_dig 2 38 | callsub boolcomp_3 39 | frame_bury 2 40 | frame_dig 3 41 | callsub numericalcomp_4 42 | frame_bury 3 43 | byte 0x00 44 | int 0 45 | frame_dig 1 46 | setbyte 47 | byte 0x00 48 | int 0 49 | frame_dig 2 50 | setbit 51 | concat 52 | frame_dig 3 53 | itob 54 | concat 55 | frame_bury 0 56 | retsub 57 | 58 | // round_tripper 59 | roundtripper_1: 60 | proto 1 1 61 | byte "" 62 | dupn 2 63 | int 0 64 | dup 65 | byte "" 66 | dup 67 | frame_dig -1 68 | callsub tuplecomplement_0 69 | frame_bury 1 70 | frame_dig 1 71 | callsub tuplecomplement_0 72 | frame_bury 2 73 | frame_dig -1 74 | frame_dig 1 75 | concat 76 | frame_dig 2 77 | concat 78 | frame_bury 0 79 | retsub 80 | 81 | // numerical_comp 82 | numericalcomp_2: 83 | proto 1 1 84 | int 0 85 | int 255 86 | frame_dig -1 87 | - 88 | frame_bury 0 89 | frame_dig 0 90 | int 256 91 | < 92 | assert 93 | retsub 94 | 95 | // bool_comp 96 | boolcomp_3: 97 | proto 1 1 98 | int 0 99 | frame_dig -1 100 | ! 101 | ! 102 | ! 103 | frame_bury 0 104 | retsub 105 | 106 | // numerical_comp 107 | numericalcomp_4: 108 | proto 1 1 109 | int 0 110 | int 18446744073709551615 111 | frame_dig -1 112 | - 113 | frame_bury 0 114 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint16)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | int 0 19 | extract_uint16 20 | store 8 21 | load 8 22 | callsub numericalcomp_2 23 | store 8 24 | load 8 25 | itob 26 | extract 6 0 27 | store 7 28 | load 7 29 | retsub 30 | 31 | // round_tripper 32 | roundtripper_1: 33 | store 2 34 | load 2 35 | callsub tuplecomplement_0 36 | store 4 37 | load 4 38 | callsub tuplecomplement_0 39 | store 5 40 | load 2 41 | load 4 42 | concat 43 | load 5 44 | concat 45 | store 3 46 | load 3 47 | retsub 48 | 49 | // numerical_comp 50 | numericalcomp_2: 51 | store 9 52 | int 65535 53 | load 9 54 | - 55 | store 10 56 | load 10 57 | int 65536 58 | < 59 | assert 60 | load 10 61 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint16)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 2 20 | byte "" 21 | dup 22 | frame_dig -1 23 | int 0 24 | extract_uint16 25 | frame_bury 1 26 | frame_dig 1 27 | callsub numericalcomp_2 28 | frame_bury 1 29 | frame_dig 1 30 | itob 31 | extract 6 0 32 | frame_bury 0 33 | retsub 34 | 35 | // round_tripper 36 | roundtripper_1: 37 | proto 1 1 38 | byte "" 39 | dupn 2 40 | int 0 41 | dup 42 | byte "" 43 | dup 44 | frame_dig -1 45 | callsub tuplecomplement_0 46 | frame_bury 1 47 | frame_dig 1 48 | callsub tuplecomplement_0 49 | frame_bury 2 50 | frame_dig -1 51 | frame_dig 1 52 | concat 53 | frame_dig 2 54 | concat 55 | frame_bury 0 56 | retsub 57 | 58 | // numerical_comp 59 | numericalcomp_2: 60 | proto 1 1 61 | int 0 62 | int 65535 63 | frame_dig -1 64 | - 65 | frame_bury 0 66 | frame_dig 0 67 | int 65536 68 | < 69 | assert 70 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint16,uint8,byte)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | int 0 19 | extract_uint16 20 | store 8 21 | load 6 22 | int 2 23 | getbyte 24 | store 9 25 | load 6 26 | int 3 27 | getbyte 28 | store 10 29 | load 8 30 | callsub numericalcomp_2 31 | store 8 32 | load 9 33 | callsub numericalcomp_3 34 | store 9 35 | load 10 36 | callsub numericalcomp_4 37 | store 10 38 | load 8 39 | itob 40 | extract 6 0 41 | byte 0x00 42 | int 0 43 | load 9 44 | setbyte 45 | concat 46 | byte 0x00 47 | int 0 48 | load 10 49 | setbyte 50 | concat 51 | store 7 52 | load 7 53 | retsub 54 | 55 | // round_tripper 56 | roundtripper_1: 57 | store 2 58 | load 2 59 | callsub tuplecomplement_0 60 | store 4 61 | load 4 62 | callsub tuplecomplement_0 63 | store 5 64 | load 2 65 | load 4 66 | concat 67 | load 5 68 | concat 69 | store 3 70 | load 3 71 | retsub 72 | 73 | // numerical_comp 74 | numericalcomp_2: 75 | store 11 76 | int 65535 77 | load 11 78 | - 79 | store 12 80 | load 12 81 | int 65536 82 | < 83 | assert 84 | load 12 85 | retsub 86 | 87 | // numerical_comp 88 | numericalcomp_3: 89 | store 13 90 | int 255 91 | load 13 92 | - 93 | store 14 94 | load 14 95 | int 256 96 | < 97 | assert 98 | load 14 99 | retsub 100 | 101 | // numerical_comp 102 | numericalcomp_4: 103 | store 15 104 | int 255 105 | load 15 106 | - 107 | store 16 108 | load 16 109 | int 256 110 | < 111 | assert 112 | load 16 113 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint16,uint8,byte)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 4 20 | byte "" 21 | dup 22 | frame_dig -1 23 | int 0 24 | extract_uint16 25 | frame_bury 1 26 | frame_dig -1 27 | int 2 28 | getbyte 29 | frame_bury 2 30 | frame_dig -1 31 | int 3 32 | getbyte 33 | frame_bury 3 34 | frame_dig 1 35 | callsub numericalcomp_2 36 | frame_bury 1 37 | frame_dig 2 38 | callsub numericalcomp_3 39 | frame_bury 2 40 | frame_dig 3 41 | callsub numericalcomp_4 42 | frame_bury 3 43 | frame_dig 1 44 | itob 45 | extract 6 0 46 | byte 0x00 47 | int 0 48 | frame_dig 2 49 | setbyte 50 | concat 51 | byte 0x00 52 | int 0 53 | frame_dig 3 54 | setbyte 55 | concat 56 | frame_bury 0 57 | retsub 58 | 59 | // round_tripper 60 | roundtripper_1: 61 | proto 1 1 62 | byte "" 63 | dupn 2 64 | int 0 65 | dup 66 | byte "" 67 | dup 68 | frame_dig -1 69 | callsub tuplecomplement_0 70 | frame_bury 1 71 | frame_dig 1 72 | callsub tuplecomplement_0 73 | frame_bury 2 74 | frame_dig -1 75 | frame_dig 1 76 | concat 77 | frame_dig 2 78 | concat 79 | frame_bury 0 80 | retsub 81 | 82 | // numerical_comp 83 | numericalcomp_2: 84 | proto 1 1 85 | int 0 86 | int 65535 87 | frame_dig -1 88 | - 89 | frame_bury 0 90 | frame_dig 0 91 | int 65536 92 | < 93 | assert 94 | retsub 95 | 96 | // numerical_comp 97 | numericalcomp_3: 98 | proto 1 1 99 | int 0 100 | int 255 101 | frame_dig -1 102 | - 103 | frame_bury 0 104 | frame_dig 0 105 | int 256 106 | < 107 | assert 108 | retsub 109 | 110 | // numerical_comp 111 | numericalcomp_4: 112 | proto 1 1 113 | int 0 114 | int 255 115 | frame_dig -1 116 | - 117 | frame_bury 0 118 | frame_dig 0 119 | int 256 120 | < 121 | assert 122 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint32)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | int 0 19 | extract_uint32 20 | store 8 21 | load 8 22 | callsub numericalcomp_2 23 | store 8 24 | load 8 25 | itob 26 | extract 4 0 27 | store 7 28 | load 7 29 | retsub 30 | 31 | // round_tripper 32 | roundtripper_1: 33 | store 2 34 | load 2 35 | callsub tuplecomplement_0 36 | store 4 37 | load 4 38 | callsub tuplecomplement_0 39 | store 5 40 | load 2 41 | load 4 42 | concat 43 | load 5 44 | concat 45 | store 3 46 | load 3 47 | retsub 48 | 49 | // numerical_comp 50 | numericalcomp_2: 51 | store 9 52 | int 4294967295 53 | load 9 54 | - 55 | store 10 56 | load 10 57 | int 4294967296 58 | < 59 | assert 60 | load 10 61 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint32)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 2 20 | byte "" 21 | dup 22 | frame_dig -1 23 | int 0 24 | extract_uint32 25 | frame_bury 1 26 | frame_dig 1 27 | callsub numericalcomp_2 28 | frame_bury 1 29 | frame_dig 1 30 | itob 31 | extract 4 0 32 | frame_bury 0 33 | retsub 34 | 35 | // round_tripper 36 | roundtripper_1: 37 | proto 1 1 38 | byte "" 39 | dupn 2 40 | int 0 41 | dup 42 | byte "" 43 | dup 44 | frame_dig -1 45 | callsub tuplecomplement_0 46 | frame_bury 1 47 | frame_dig 1 48 | callsub tuplecomplement_0 49 | frame_bury 2 50 | frame_dig -1 51 | frame_dig 1 52 | concat 53 | frame_dig 2 54 | concat 55 | frame_bury 0 56 | retsub 57 | 58 | // numerical_comp 59 | numericalcomp_2: 60 | proto 1 1 61 | int 0 62 | int 4294967295 63 | frame_dig -1 64 | - 65 | frame_bury 0 66 | frame_dig 0 67 | int 4294967296 68 | < 69 | assert 70 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint32,uint16,uint8)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | int 0 19 | extract_uint32 20 | store 8 21 | load 6 22 | int 4 23 | extract_uint16 24 | store 9 25 | load 6 26 | int 6 27 | getbyte 28 | store 10 29 | load 8 30 | callsub numericalcomp_2 31 | store 8 32 | load 9 33 | callsub numericalcomp_3 34 | store 9 35 | load 10 36 | callsub numericalcomp_4 37 | store 10 38 | load 8 39 | itob 40 | extract 4 0 41 | load 9 42 | itob 43 | extract 6 0 44 | concat 45 | byte 0x00 46 | int 0 47 | load 10 48 | setbyte 49 | concat 50 | store 7 51 | load 7 52 | retsub 53 | 54 | // round_tripper 55 | roundtripper_1: 56 | store 2 57 | load 2 58 | callsub tuplecomplement_0 59 | store 4 60 | load 4 61 | callsub tuplecomplement_0 62 | store 5 63 | load 2 64 | load 4 65 | concat 66 | load 5 67 | concat 68 | store 3 69 | load 3 70 | retsub 71 | 72 | // numerical_comp 73 | numericalcomp_2: 74 | store 11 75 | int 4294967295 76 | load 11 77 | - 78 | store 12 79 | load 12 80 | int 4294967296 81 | < 82 | assert 83 | load 12 84 | retsub 85 | 86 | // numerical_comp 87 | numericalcomp_3: 88 | store 13 89 | int 65535 90 | load 13 91 | - 92 | store 14 93 | load 14 94 | int 65536 95 | < 96 | assert 97 | load 14 98 | retsub 99 | 100 | // numerical_comp 101 | numericalcomp_4: 102 | store 15 103 | int 255 104 | load 15 105 | - 106 | store 16 107 | load 16 108 | int 256 109 | < 110 | assert 111 | load 16 112 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint32,uint16,uint8)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 4 20 | byte "" 21 | dup 22 | frame_dig -1 23 | int 0 24 | extract_uint32 25 | frame_bury 1 26 | frame_dig -1 27 | int 4 28 | extract_uint16 29 | frame_bury 2 30 | frame_dig -1 31 | int 6 32 | getbyte 33 | frame_bury 3 34 | frame_dig 1 35 | callsub numericalcomp_2 36 | frame_bury 1 37 | frame_dig 2 38 | callsub numericalcomp_3 39 | frame_bury 2 40 | frame_dig 3 41 | callsub numericalcomp_4 42 | frame_bury 3 43 | frame_dig 1 44 | itob 45 | extract 4 0 46 | frame_dig 2 47 | itob 48 | extract 6 0 49 | concat 50 | byte 0x00 51 | int 0 52 | frame_dig 3 53 | setbyte 54 | concat 55 | frame_bury 0 56 | retsub 57 | 58 | // round_tripper 59 | roundtripper_1: 60 | proto 1 1 61 | byte "" 62 | dupn 2 63 | int 0 64 | dup 65 | byte "" 66 | dup 67 | frame_dig -1 68 | callsub tuplecomplement_0 69 | frame_bury 1 70 | frame_dig 1 71 | callsub tuplecomplement_0 72 | frame_bury 2 73 | frame_dig -1 74 | frame_dig 1 75 | concat 76 | frame_dig 2 77 | concat 78 | frame_bury 0 79 | retsub 80 | 81 | // numerical_comp 82 | numericalcomp_2: 83 | proto 1 1 84 | int 0 85 | int 4294967295 86 | frame_dig -1 87 | - 88 | frame_bury 0 89 | frame_dig 0 90 | int 4294967296 91 | < 92 | assert 93 | retsub 94 | 95 | // numerical_comp 96 | numericalcomp_3: 97 | proto 1 1 98 | int 0 99 | int 65535 100 | frame_dig -1 101 | - 102 | frame_bury 0 103 | frame_dig 0 104 | int 65536 105 | < 106 | assert 107 | retsub 108 | 109 | // numerical_comp 110 | numericalcomp_4: 111 | proto 1 1 112 | int 0 113 | int 255 114 | frame_dig -1 115 | - 116 | frame_bury 0 117 | frame_dig 0 118 | int 256 119 | < 120 | assert 121 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint64)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | btoi 19 | store 8 20 | load 8 21 | callsub numericalcomp_2 22 | store 8 23 | load 8 24 | itob 25 | store 7 26 | load 7 27 | retsub 28 | 29 | // round_tripper 30 | roundtripper_1: 31 | store 2 32 | load 2 33 | callsub tuplecomplement_0 34 | store 4 35 | load 4 36 | callsub tuplecomplement_0 37 | store 5 38 | load 2 39 | load 4 40 | concat 41 | load 5 42 | concat 43 | store 3 44 | load 3 45 | retsub 46 | 47 | // numerical_comp 48 | numericalcomp_2: 49 | store 9 50 | int 18446744073709551615 51 | load 9 52 | - 53 | store 10 54 | load 10 55 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint64)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 2 20 | byte "" 21 | dup 22 | frame_dig -1 23 | btoi 24 | frame_bury 1 25 | frame_dig 1 26 | callsub numericalcomp_2 27 | frame_bury 1 28 | frame_dig 1 29 | itob 30 | frame_bury 0 31 | retsub 32 | 33 | // round_tripper 34 | roundtripper_1: 35 | proto 1 1 36 | byte "" 37 | dupn 2 38 | int 0 39 | dup 40 | byte "" 41 | dup 42 | frame_dig -1 43 | callsub tuplecomplement_0 44 | frame_bury 1 45 | frame_dig 1 46 | callsub tuplecomplement_0 47 | frame_bury 2 48 | frame_dig -1 49 | frame_dig 1 50 | concat 51 | frame_dig 2 52 | concat 53 | frame_bury 0 54 | retsub 55 | 56 | // numerical_comp 57 | numericalcomp_2: 58 | proto 1 1 59 | int 0 60 | int 18446744073709551615 61 | frame_dig -1 62 | - 63 | frame_bury 0 64 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint64,uint32,uint16)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | int 0 19 | extract_uint64 20 | store 8 21 | load 6 22 | int 8 23 | extract_uint32 24 | store 9 25 | load 6 26 | int 12 27 | extract_uint16 28 | store 10 29 | load 8 30 | callsub numericalcomp_2 31 | store 8 32 | load 9 33 | callsub numericalcomp_3 34 | store 9 35 | load 10 36 | callsub numericalcomp_4 37 | store 10 38 | load 8 39 | itob 40 | load 9 41 | itob 42 | extract 4 0 43 | concat 44 | load 10 45 | itob 46 | extract 6 0 47 | concat 48 | store 7 49 | load 7 50 | retsub 51 | 52 | // round_tripper 53 | roundtripper_1: 54 | store 2 55 | load 2 56 | callsub tuplecomplement_0 57 | store 4 58 | load 4 59 | callsub tuplecomplement_0 60 | store 5 61 | load 2 62 | load 4 63 | concat 64 | load 5 65 | concat 66 | store 3 67 | load 3 68 | retsub 69 | 70 | // numerical_comp 71 | numericalcomp_2: 72 | store 11 73 | int 18446744073709551615 74 | load 11 75 | - 76 | store 12 77 | load 12 78 | retsub 79 | 80 | // numerical_comp 81 | numericalcomp_3: 82 | store 13 83 | int 4294967295 84 | load 13 85 | - 86 | store 14 87 | load 14 88 | int 4294967296 89 | < 90 | assert 91 | load 14 92 | retsub 93 | 94 | // numerical_comp 95 | numericalcomp_4: 96 | store 15 97 | int 65535 98 | load 15 99 | - 100 | store 16 101 | load 16 102 | int 65536 103 | < 104 | assert 105 | load 16 106 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint64,uint32,uint16)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 4 20 | byte "" 21 | dup 22 | frame_dig -1 23 | int 0 24 | extract_uint64 25 | frame_bury 1 26 | frame_dig -1 27 | int 8 28 | extract_uint32 29 | frame_bury 2 30 | frame_dig -1 31 | int 12 32 | extract_uint16 33 | frame_bury 3 34 | frame_dig 1 35 | callsub numericalcomp_2 36 | frame_bury 1 37 | frame_dig 2 38 | callsub numericalcomp_3 39 | frame_bury 2 40 | frame_dig 3 41 | callsub numericalcomp_4 42 | frame_bury 3 43 | frame_dig 1 44 | itob 45 | frame_dig 2 46 | itob 47 | extract 4 0 48 | concat 49 | frame_dig 3 50 | itob 51 | extract 6 0 52 | concat 53 | frame_bury 0 54 | retsub 55 | 56 | // round_tripper 57 | roundtripper_1: 58 | proto 1 1 59 | byte "" 60 | dupn 2 61 | int 0 62 | dup 63 | byte "" 64 | dup 65 | frame_dig -1 66 | callsub tuplecomplement_0 67 | frame_bury 1 68 | frame_dig 1 69 | callsub tuplecomplement_0 70 | frame_bury 2 71 | frame_dig -1 72 | frame_dig 1 73 | concat 74 | frame_dig 2 75 | concat 76 | frame_bury 0 77 | retsub 78 | 79 | // numerical_comp 80 | numericalcomp_2: 81 | proto 1 1 82 | int 0 83 | int 18446744073709551615 84 | frame_dig -1 85 | - 86 | frame_bury 0 87 | retsub 88 | 89 | // numerical_comp 90 | numericalcomp_3: 91 | proto 1 1 92 | int 0 93 | int 4294967295 94 | frame_dig -1 95 | - 96 | frame_bury 0 97 | frame_dig 0 98 | int 4294967296 99 | < 100 | assert 101 | retsub 102 | 103 | // numerical_comp 104 | numericalcomp_4: 105 | proto 1 1 106 | int 0 107 | int 65535 108 | frame_dig -1 109 | - 110 | frame_bury 0 111 | frame_dig 0 112 | int 65536 113 | < 114 | assert 115 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint8)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | int 0 19 | getbyte 20 | store 8 21 | load 8 22 | callsub numericalcomp_2 23 | store 8 24 | byte 0x00 25 | int 0 26 | load 8 27 | setbyte 28 | store 7 29 | load 7 30 | retsub 31 | 32 | // round_tripper 33 | roundtripper_1: 34 | store 2 35 | load 2 36 | callsub tuplecomplement_0 37 | store 4 38 | load 4 39 | callsub tuplecomplement_0 40 | store 5 41 | load 2 42 | load 4 43 | concat 44 | load 5 45 | concat 46 | store 3 47 | load 3 48 | retsub 49 | 50 | // numerical_comp 51 | numericalcomp_2: 52 | store 9 53 | int 255 54 | load 9 55 | - 56 | store 10 57 | load 10 58 | int 256 59 | < 60 | assert 61 | load 10 62 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint8)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 2 20 | byte "" 21 | dup 22 | frame_dig -1 23 | int 0 24 | getbyte 25 | frame_bury 1 26 | frame_dig 1 27 | callsub numericalcomp_2 28 | frame_bury 1 29 | byte 0x00 30 | int 0 31 | frame_dig 1 32 | setbyte 33 | frame_bury 0 34 | retsub 35 | 36 | // round_tripper 37 | roundtripper_1: 38 | proto 1 1 39 | byte "" 40 | dupn 2 41 | int 0 42 | dup 43 | byte "" 44 | dup 45 | frame_dig -1 46 | callsub tuplecomplement_0 47 | frame_bury 1 48 | frame_dig 1 49 | callsub tuplecomplement_0 50 | frame_bury 2 51 | frame_dig -1 52 | frame_dig 1 53 | concat 54 | frame_dig 2 55 | concat 56 | frame_bury 0 57 | retsub 58 | 59 | // numerical_comp 60 | numericalcomp_2: 61 | proto 1 1 62 | int 0 63 | int 255 64 | frame_dig -1 65 | - 66 | frame_bury 0 67 | frame_dig 0 68 | int 256 69 | < 70 | assert 71 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint8,byte,bool)_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | store 6 17 | load 6 18 | int 0 19 | getbyte 20 | store 8 21 | load 6 22 | int 1 23 | getbyte 24 | store 9 25 | load 6 26 | int 16 27 | getbit 28 | store 10 29 | load 8 30 | callsub numericalcomp_2 31 | store 8 32 | load 9 33 | callsub numericalcomp_3 34 | store 9 35 | load 10 36 | callsub boolcomp_4 37 | store 10 38 | byte 0x00 39 | int 0 40 | load 8 41 | setbyte 42 | byte 0x00 43 | int 0 44 | load 9 45 | setbyte 46 | concat 47 | byte 0x00 48 | int 0 49 | load 10 50 | setbit 51 | concat 52 | store 7 53 | load 7 54 | retsub 55 | 56 | // round_tripper 57 | roundtripper_1: 58 | store 2 59 | load 2 60 | callsub tuplecomplement_0 61 | store 4 62 | load 4 63 | callsub tuplecomplement_0 64 | store 5 65 | load 2 66 | load 4 67 | concat 68 | load 5 69 | concat 70 | store 3 71 | load 3 72 | retsub 73 | 74 | // numerical_comp 75 | numericalcomp_2: 76 | store 11 77 | int 255 78 | load 11 79 | - 80 | store 12 81 | load 12 82 | int 256 83 | < 84 | assert 85 | load 12 86 | retsub 87 | 88 | // numerical_comp 89 | numericalcomp_3: 90 | store 13 91 | int 255 92 | load 13 93 | - 94 | store 14 95 | load 14 96 | int 256 97 | < 98 | assert 99 | load 14 100 | retsub 101 | 102 | // bool_comp 103 | boolcomp_4: 104 | store 15 105 | load 15 106 | ! 107 | ! 108 | ! 109 | store 16 110 | load 16 111 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_(uint8,byte,bool)_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // tuple_complement 15 | tuplecomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 4 20 | byte "" 21 | dup 22 | frame_dig -1 23 | int 0 24 | getbyte 25 | frame_bury 1 26 | frame_dig -1 27 | int 1 28 | getbyte 29 | frame_bury 2 30 | frame_dig -1 31 | int 16 32 | getbit 33 | frame_bury 3 34 | frame_dig 1 35 | callsub numericalcomp_2 36 | frame_bury 1 37 | frame_dig 2 38 | callsub numericalcomp_3 39 | frame_bury 2 40 | frame_dig 3 41 | callsub boolcomp_4 42 | frame_bury 3 43 | byte 0x00 44 | int 0 45 | frame_dig 1 46 | setbyte 47 | byte 0x00 48 | int 0 49 | frame_dig 2 50 | setbyte 51 | concat 52 | byte 0x00 53 | int 0 54 | frame_dig 3 55 | setbit 56 | concat 57 | frame_bury 0 58 | retsub 59 | 60 | // round_tripper 61 | roundtripper_1: 62 | proto 1 1 63 | byte "" 64 | dupn 2 65 | int 0 66 | dup 67 | byte "" 68 | dup 69 | frame_dig -1 70 | callsub tuplecomplement_0 71 | frame_bury 1 72 | frame_dig 1 73 | callsub tuplecomplement_0 74 | frame_bury 2 75 | frame_dig -1 76 | frame_dig 1 77 | concat 78 | frame_dig 2 79 | concat 80 | frame_bury 0 81 | retsub 82 | 83 | // numerical_comp 84 | numericalcomp_2: 85 | proto 1 1 86 | int 0 87 | int 255 88 | frame_dig -1 89 | - 90 | frame_bury 0 91 | frame_dig 0 92 | int 256 93 | < 94 | assert 95 | retsub 96 | 97 | // numerical_comp 98 | numericalcomp_3: 99 | proto 1 1 100 | int 0 101 | int 255 102 | frame_dig -1 103 | - 104 | frame_bury 0 105 | frame_dig 0 106 | int 256 107 | < 108 | assert 109 | retsub 110 | 111 | // bool_comp 112 | boolcomp_4: 113 | proto 1 1 114 | int 0 115 | frame_dig -1 116 | ! 117 | ! 118 | ! 119 | frame_bury 0 120 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_bool[1]_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_2 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // bool_comp 15 | boolcomp_0: 16 | store 9 17 | load 9 18 | ! 19 | ! 20 | ! 21 | store 10 22 | load 10 23 | retsub 24 | 25 | // array_complement 26 | arraycomplement_1: 27 | store 6 28 | load 6 29 | int 0 30 | getbit 31 | store 8 32 | load 8 33 | callsub boolcomp_0 34 | store 8 35 | byte 0x00 36 | int 0 37 | load 8 38 | setbit 39 | store 7 40 | load 7 41 | retsub 42 | 43 | // round_tripper 44 | roundtripper_2: 45 | store 2 46 | load 2 47 | callsub arraycomplement_1 48 | store 4 49 | load 4 50 | callsub arraycomplement_1 51 | store 5 52 | load 2 53 | load 4 54 | concat 55 | load 5 56 | concat 57 | store 3 58 | load 3 59 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_bool[1]_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_2 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // bool_comp 15 | boolcomp_0: 16 | proto 1 1 17 | int 0 18 | frame_dig -1 19 | ! 20 | ! 21 | ! 22 | frame_bury 0 23 | retsub 24 | 25 | // array_complement 26 | arraycomplement_1: 27 | proto 1 1 28 | byte "" 29 | int 0 30 | dupn 2 31 | byte "" 32 | dup 33 | frame_dig -1 34 | int 0 35 | getbit 36 | frame_bury 1 37 | frame_dig 1 38 | callsub boolcomp_0 39 | frame_bury 1 40 | byte 0x00 41 | int 0 42 | frame_dig 1 43 | setbit 44 | frame_bury 0 45 | retsub 46 | 47 | // round_tripper 48 | roundtripper_2: 49 | proto 1 1 50 | byte "" 51 | dupn 2 52 | int 0 53 | dup 54 | byte "" 55 | dup 56 | frame_dig -1 57 | callsub arraycomplement_1 58 | frame_bury 1 59 | frame_dig 1 60 | callsub arraycomplement_1 61 | frame_bury 2 62 | frame_dig -1 63 | frame_dig 1 64 | concat 65 | frame_dig 2 66 | concat 67 | frame_bury 0 68 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_bool[]_0_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // array_complement 15 | arraycomplement_0: 16 | store 6 17 | int 0 18 | store 8 19 | load 8 20 | itob 21 | extract 6 0 22 | byte "" 23 | concat 24 | store 7 25 | load 7 26 | retsub 27 | 28 | // round_tripper 29 | roundtripper_1: 30 | store 2 31 | load 2 32 | callsub arraycomplement_0 33 | store 4 34 | load 4 35 | callsub arraycomplement_0 36 | store 5 37 | load 2 38 | store 12 39 | load 12 40 | store 11 41 | int 6 42 | store 9 43 | load 9 44 | load 12 45 | len 46 | + 47 | store 10 48 | load 10 49 | int 65536 50 | < 51 | assert 52 | load 9 53 | itob 54 | extract 6 0 55 | load 4 56 | store 12 57 | load 11 58 | load 12 59 | concat 60 | store 11 61 | load 10 62 | store 9 63 | load 9 64 | load 12 65 | len 66 | + 67 | store 10 68 | load 10 69 | int 65536 70 | < 71 | assert 72 | load 9 73 | itob 74 | extract 6 0 75 | concat 76 | load 5 77 | store 12 78 | load 11 79 | load 12 80 | concat 81 | store 11 82 | load 10 83 | store 9 84 | load 9 85 | itob 86 | extract 6 0 87 | concat 88 | load 11 89 | concat 90 | store 3 91 | load 3 92 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_bool[]_0_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // array_complement 15 | arraycomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dup 20 | byte "" 21 | dup 22 | int 0 23 | int 0 24 | frame_bury 5 25 | frame_dig 5 26 | itob 27 | extract 6 0 28 | byte "" 29 | concat 30 | frame_bury 0 31 | retsub 32 | 33 | // round_tripper 34 | roundtripper_1: 35 | proto 1 1 36 | byte "" 37 | dupn 2 38 | int 0 39 | dup 40 | byte "" 41 | dup 42 | frame_dig -1 43 | callsub arraycomplement_0 44 | frame_bury 1 45 | frame_dig 1 46 | callsub arraycomplement_0 47 | frame_bury 2 48 | frame_dig -1 49 | frame_bury 6 50 | frame_dig 6 51 | frame_bury 5 52 | int 6 53 | frame_bury 3 54 | frame_dig 3 55 | frame_dig 6 56 | len 57 | + 58 | frame_bury 4 59 | frame_dig 4 60 | int 65536 61 | < 62 | assert 63 | frame_dig 3 64 | itob 65 | extract 6 0 66 | frame_dig 1 67 | frame_bury 6 68 | frame_dig 5 69 | frame_dig 6 70 | concat 71 | frame_bury 5 72 | frame_dig 4 73 | frame_bury 3 74 | frame_dig 3 75 | frame_dig 6 76 | len 77 | + 78 | frame_bury 4 79 | frame_dig 4 80 | int 65536 81 | < 82 | assert 83 | frame_dig 3 84 | itob 85 | extract 6 0 86 | concat 87 | frame_dig 2 88 | frame_bury 6 89 | frame_dig 5 90 | frame_dig 6 91 | concat 92 | frame_bury 5 93 | frame_dig 4 94 | frame_bury 3 95 | frame_dig 3 96 | itob 97 | extract 6 0 98 | concat 99 | frame_dig 5 100 | concat 101 | frame_bury 0 102 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_bool[]_1_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_2 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // bool_comp 15 | boolcomp_0: 16 | store 9 17 | load 9 18 | ! 19 | ! 20 | ! 21 | store 10 22 | load 10 23 | retsub 24 | 25 | // array_complement 26 | arraycomplement_1: 27 | store 6 28 | load 6 29 | int 0 30 | int 16 31 | + 32 | getbit 33 | store 8 34 | load 8 35 | callsub boolcomp_0 36 | store 8 37 | int 1 38 | store 11 39 | load 11 40 | itob 41 | extract 6 0 42 | byte 0x00 43 | int 0 44 | load 8 45 | setbit 46 | concat 47 | store 7 48 | load 7 49 | retsub 50 | 51 | // round_tripper 52 | roundtripper_2: 53 | store 2 54 | load 2 55 | callsub arraycomplement_1 56 | store 4 57 | load 4 58 | callsub arraycomplement_1 59 | store 5 60 | load 2 61 | store 15 62 | load 15 63 | store 14 64 | int 6 65 | store 12 66 | load 12 67 | load 15 68 | len 69 | + 70 | store 13 71 | load 13 72 | int 65536 73 | < 74 | assert 75 | load 12 76 | itob 77 | extract 6 0 78 | load 4 79 | store 15 80 | load 14 81 | load 15 82 | concat 83 | store 14 84 | load 13 85 | store 12 86 | load 12 87 | load 15 88 | len 89 | + 90 | store 13 91 | load 13 92 | int 65536 93 | < 94 | assert 95 | load 12 96 | itob 97 | extract 6 0 98 | concat 99 | load 5 100 | store 15 101 | load 14 102 | load 15 103 | concat 104 | store 14 105 | load 13 106 | store 12 107 | load 12 108 | itob 109 | extract 6 0 110 | concat 111 | load 14 112 | concat 113 | store 3 114 | load 3 115 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_bool[]_1_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_2 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // bool_comp 15 | boolcomp_0: 16 | proto 1 1 17 | int 0 18 | frame_dig -1 19 | ! 20 | ! 21 | ! 22 | frame_bury 0 23 | retsub 24 | 25 | // array_complement 26 | arraycomplement_1: 27 | proto 1 1 28 | byte "" 29 | int 0 30 | dupn 2 31 | byte "" 32 | dup 33 | int 0 34 | frame_dig -1 35 | int 0 36 | int 16 37 | + 38 | getbit 39 | frame_bury 1 40 | frame_dig 1 41 | callsub boolcomp_0 42 | frame_bury 1 43 | int 1 44 | frame_bury 6 45 | frame_dig 6 46 | itob 47 | extract 6 0 48 | byte 0x00 49 | int 0 50 | frame_dig 1 51 | setbit 52 | concat 53 | frame_bury 0 54 | retsub 55 | 56 | // round_tripper 57 | roundtripper_2: 58 | proto 1 1 59 | byte "" 60 | dupn 2 61 | int 0 62 | dup 63 | byte "" 64 | dup 65 | frame_dig -1 66 | callsub arraycomplement_1 67 | frame_bury 1 68 | frame_dig 1 69 | callsub arraycomplement_1 70 | frame_bury 2 71 | frame_dig -1 72 | frame_bury 6 73 | frame_dig 6 74 | frame_bury 5 75 | int 6 76 | frame_bury 3 77 | frame_dig 3 78 | frame_dig 6 79 | len 80 | + 81 | frame_bury 4 82 | frame_dig 4 83 | int 65536 84 | < 85 | assert 86 | frame_dig 3 87 | itob 88 | extract 6 0 89 | frame_dig 1 90 | frame_bury 6 91 | frame_dig 5 92 | frame_dig 6 93 | concat 94 | frame_bury 5 95 | frame_dig 4 96 | frame_bury 3 97 | frame_dig 3 98 | frame_dig 6 99 | len 100 | + 101 | frame_bury 4 102 | frame_dig 4 103 | int 65536 104 | < 105 | assert 106 | frame_dig 3 107 | itob 108 | extract 6 0 109 | concat 110 | frame_dig 2 111 | frame_bury 6 112 | frame_dig 5 113 | frame_dig 6 114 | concat 115 | frame_bury 5 116 | frame_dig 4 117 | frame_bury 3 118 | frame_dig 3 119 | itob 120 | extract 6 0 121 | concat 122 | frame_dig 5 123 | concat 124 | frame_bury 0 125 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_bool_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | int 0 4 | int 8 5 | * 6 | getbit 7 | store 1 8 | load 1 9 | callsub roundtripper_1 10 | store 0 11 | byte 0x151f7c75 12 | load 0 13 | concat 14 | log 15 | int 1 16 | return 17 | 18 | // bool_comp 19 | boolcomp_0: 20 | store 6 21 | load 6 22 | ! 23 | ! 24 | ! 25 | store 7 26 | load 7 27 | retsub 28 | 29 | // round_tripper 30 | roundtripper_1: 31 | store 2 32 | load 2 33 | callsub boolcomp_0 34 | store 4 35 | load 4 36 | callsub boolcomp_0 37 | store 5 38 | byte 0x00 39 | int 0 40 | load 2 41 | setbit 42 | int 1 43 | load 4 44 | setbit 45 | int 2 46 | load 5 47 | setbit 48 | store 3 49 | load 3 50 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_bool_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | int 0 4 | int 8 5 | * 6 | getbit 7 | store 1 8 | load 1 9 | callsub roundtripper_1 10 | store 0 11 | byte 0x151f7c75 12 | load 0 13 | concat 14 | log 15 | int 1 16 | return 17 | 18 | // bool_comp 19 | boolcomp_0: 20 | proto 1 1 21 | int 0 22 | frame_dig -1 23 | ! 24 | ! 25 | ! 26 | frame_bury 0 27 | retsub 28 | 29 | // round_tripper 30 | roundtripper_1: 31 | proto 1 1 32 | byte "" 33 | int 0 34 | dupn 3 35 | byte "" 36 | dup 37 | frame_dig -1 38 | callsub boolcomp_0 39 | frame_bury 1 40 | frame_dig 1 41 | callsub boolcomp_0 42 | frame_bury 2 43 | byte 0x00 44 | int 0 45 | frame_dig -1 46 | setbit 47 | int 1 48 | frame_dig 1 49 | setbit 50 | int 2 51 | frame_dig 2 52 | setbit 53 | frame_bury 0 54 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_byte_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | int 0 4 | getbyte 5 | store 1 6 | load 1 7 | callsub roundtripper_1 8 | store 0 9 | byte 0x151f7c75 10 | load 0 11 | concat 12 | log 13 | int 1 14 | return 15 | 16 | // numerical_comp 17 | numericalcomp_0: 18 | store 6 19 | int 255 20 | load 6 21 | - 22 | store 7 23 | load 7 24 | int 256 25 | < 26 | assert 27 | load 7 28 | retsub 29 | 30 | // round_tripper 31 | roundtripper_1: 32 | store 2 33 | load 2 34 | callsub numericalcomp_0 35 | store 4 36 | load 4 37 | callsub numericalcomp_0 38 | store 5 39 | byte 0x00 40 | int 0 41 | load 2 42 | setbyte 43 | byte 0x00 44 | int 0 45 | load 4 46 | setbyte 47 | concat 48 | byte 0x00 49 | int 0 50 | load 5 51 | setbyte 52 | concat 53 | store 3 54 | load 3 55 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_byte_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | int 0 4 | getbyte 5 | store 1 6 | load 1 7 | callsub roundtripper_1 8 | store 0 9 | byte 0x151f7c75 10 | load 0 11 | concat 12 | log 13 | int 1 14 | return 15 | 16 | // numerical_comp 17 | numericalcomp_0: 18 | proto 1 1 19 | int 0 20 | int 255 21 | frame_dig -1 22 | - 23 | frame_bury 0 24 | frame_dig 0 25 | int 256 26 | < 27 | assert 28 | retsub 29 | 30 | // round_tripper 31 | roundtripper_1: 32 | proto 1 1 33 | byte "" 34 | int 0 35 | dupn 3 36 | byte "" 37 | dup 38 | frame_dig -1 39 | callsub numericalcomp_0 40 | frame_bury 1 41 | frame_dig 1 42 | callsub numericalcomp_0 43 | frame_bury 2 44 | byte 0x00 45 | int 0 46 | frame_dig -1 47 | setbyte 48 | byte 0x00 49 | int 0 50 | frame_dig 1 51 | setbyte 52 | concat 53 | byte 0x00 54 | int 0 55 | frame_dig 2 56 | setbyte 57 | concat 58 | frame_bury 0 59 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_string_0_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // string_reverse 15 | stringreverse_0: 16 | store 6 17 | int 0 18 | store 8 19 | load 8 20 | itob 21 | extract 6 0 22 | byte "" 23 | concat 24 | store 7 25 | load 7 26 | retsub 27 | 28 | // round_tripper 29 | roundtripper_1: 30 | store 2 31 | load 2 32 | callsub stringreverse_0 33 | store 4 34 | load 4 35 | callsub stringreverse_0 36 | store 5 37 | load 2 38 | store 12 39 | load 12 40 | store 11 41 | int 6 42 | store 9 43 | load 9 44 | load 12 45 | len 46 | + 47 | store 10 48 | load 10 49 | int 65536 50 | < 51 | assert 52 | load 9 53 | itob 54 | extract 6 0 55 | load 4 56 | store 12 57 | load 11 58 | load 12 59 | concat 60 | store 11 61 | load 10 62 | store 9 63 | load 9 64 | load 12 65 | len 66 | + 67 | store 10 68 | load 10 69 | int 65536 70 | < 71 | assert 72 | load 9 73 | itob 74 | extract 6 0 75 | concat 76 | load 5 77 | store 12 78 | load 11 79 | load 12 80 | concat 81 | store 11 82 | load 10 83 | store 9 84 | load 9 85 | itob 86 | extract 6 0 87 | concat 88 | load 11 89 | concat 90 | store 3 91 | load 3 92 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_string_0_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // string_reverse 15 | stringreverse_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dup 20 | byte "" 21 | dup 22 | int 0 23 | int 0 24 | frame_bury 5 25 | frame_dig 5 26 | itob 27 | extract 6 0 28 | byte "" 29 | concat 30 | frame_bury 0 31 | retsub 32 | 33 | // round_tripper 34 | roundtripper_1: 35 | proto 1 1 36 | byte "" 37 | dupn 2 38 | int 0 39 | dup 40 | byte "" 41 | dup 42 | frame_dig -1 43 | callsub stringreverse_0 44 | frame_bury 1 45 | frame_dig 1 46 | callsub stringreverse_0 47 | frame_bury 2 48 | frame_dig -1 49 | frame_bury 6 50 | frame_dig 6 51 | frame_bury 5 52 | int 6 53 | frame_bury 3 54 | frame_dig 3 55 | frame_dig 6 56 | len 57 | + 58 | frame_bury 4 59 | frame_dig 4 60 | int 65536 61 | < 62 | assert 63 | frame_dig 3 64 | itob 65 | extract 6 0 66 | frame_dig 1 67 | frame_bury 6 68 | frame_dig 5 69 | frame_dig 6 70 | concat 71 | frame_bury 5 72 | frame_dig 4 73 | frame_bury 3 74 | frame_dig 3 75 | frame_dig 6 76 | len 77 | + 78 | frame_bury 4 79 | frame_dig 4 80 | int 65536 81 | < 82 | assert 83 | frame_dig 3 84 | itob 85 | extract 6 0 86 | concat 87 | frame_dig 2 88 | frame_bury 6 89 | frame_dig 5 90 | frame_dig 6 91 | concat 92 | frame_bury 5 93 | frame_dig 4 94 | frame_bury 3 95 | frame_dig 3 96 | itob 97 | extract 6 0 98 | concat 99 | frame_dig 5 100 | concat 101 | frame_bury 0 102 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_string_1_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // string_reverse 15 | stringreverse_0: 16 | store 6 17 | load 6 18 | int 1 19 | int 0 20 | * 21 | int 2 22 | + 23 | getbyte 24 | store 8 25 | int 1 26 | store 9 27 | load 9 28 | itob 29 | extract 6 0 30 | byte 0x00 31 | int 0 32 | load 8 33 | setbyte 34 | concat 35 | store 7 36 | load 7 37 | retsub 38 | 39 | // round_tripper 40 | roundtripper_1: 41 | store 2 42 | load 2 43 | callsub stringreverse_0 44 | store 4 45 | load 4 46 | callsub stringreverse_0 47 | store 5 48 | load 2 49 | store 13 50 | load 13 51 | store 12 52 | int 6 53 | store 10 54 | load 10 55 | load 13 56 | len 57 | + 58 | store 11 59 | load 11 60 | int 65536 61 | < 62 | assert 63 | load 10 64 | itob 65 | extract 6 0 66 | load 4 67 | store 13 68 | load 12 69 | load 13 70 | concat 71 | store 12 72 | load 11 73 | store 10 74 | load 10 75 | load 13 76 | len 77 | + 78 | store 11 79 | load 11 80 | int 65536 81 | < 82 | assert 83 | load 10 84 | itob 85 | extract 6 0 86 | concat 87 | load 5 88 | store 13 89 | load 12 90 | load 13 91 | concat 92 | store 12 93 | load 11 94 | store 10 95 | load 10 96 | itob 97 | extract 6 0 98 | concat 99 | load 12 100 | concat 101 | store 3 102 | load 3 103 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_string_1_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // string_reverse 15 | stringreverse_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dupn 3 20 | byte "" 21 | dup 22 | int 0 23 | frame_dig -1 24 | int 1 25 | int 0 26 | * 27 | int 2 28 | + 29 | getbyte 30 | frame_bury 1 31 | int 1 32 | frame_bury 7 33 | frame_dig 7 34 | itob 35 | extract 6 0 36 | byte 0x00 37 | int 0 38 | frame_dig 1 39 | setbyte 40 | concat 41 | frame_bury 0 42 | retsub 43 | 44 | // round_tripper 45 | roundtripper_1: 46 | proto 1 1 47 | byte "" 48 | dupn 2 49 | int 0 50 | dup 51 | byte "" 52 | dup 53 | frame_dig -1 54 | callsub stringreverse_0 55 | frame_bury 1 56 | frame_dig 1 57 | callsub stringreverse_0 58 | frame_bury 2 59 | frame_dig -1 60 | frame_bury 6 61 | frame_dig 6 62 | frame_bury 5 63 | int 6 64 | frame_bury 3 65 | frame_dig 3 66 | frame_dig 6 67 | len 68 | + 69 | frame_bury 4 70 | frame_dig 4 71 | int 65536 72 | < 73 | assert 74 | frame_dig 3 75 | itob 76 | extract 6 0 77 | frame_dig 1 78 | frame_bury 6 79 | frame_dig 5 80 | frame_dig 6 81 | concat 82 | frame_bury 5 83 | frame_dig 4 84 | frame_bury 3 85 | frame_dig 3 86 | frame_dig 6 87 | len 88 | + 89 | frame_bury 4 90 | frame_dig 4 91 | int 65536 92 | < 93 | assert 94 | frame_dig 3 95 | itob 96 | extract 6 0 97 | concat 98 | frame_dig 2 99 | frame_bury 6 100 | frame_dig 5 101 | frame_dig 6 102 | concat 103 | frame_bury 5 104 | frame_dig 4 105 | frame_bury 3 106 | frame_dig 3 107 | itob 108 | extract 6 0 109 | concat 110 | frame_dig 5 111 | concat 112 | frame_bury 0 113 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint16_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | int 0 4 | extract_uint16 5 | store 1 6 | load 1 7 | callsub roundtripper_1 8 | store 0 9 | byte 0x151f7c75 10 | load 0 11 | concat 12 | log 13 | int 1 14 | return 15 | 16 | // numerical_comp 17 | numericalcomp_0: 18 | store 6 19 | int 65535 20 | load 6 21 | - 22 | store 7 23 | load 7 24 | int 65536 25 | < 26 | assert 27 | load 7 28 | retsub 29 | 30 | // round_tripper 31 | roundtripper_1: 32 | store 2 33 | load 2 34 | callsub numericalcomp_0 35 | store 4 36 | load 4 37 | callsub numericalcomp_0 38 | store 5 39 | load 2 40 | itob 41 | extract 6 0 42 | load 4 43 | itob 44 | extract 6 0 45 | concat 46 | load 5 47 | itob 48 | extract 6 0 49 | concat 50 | store 3 51 | load 3 52 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint16_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | int 0 4 | extract_uint16 5 | store 1 6 | load 1 7 | callsub roundtripper_1 8 | store 0 9 | byte 0x151f7c75 10 | load 0 11 | concat 12 | log 13 | int 1 14 | return 15 | 16 | // numerical_comp 17 | numericalcomp_0: 18 | proto 1 1 19 | int 0 20 | int 65535 21 | frame_dig -1 22 | - 23 | frame_bury 0 24 | frame_dig 0 25 | int 65536 26 | < 27 | assert 28 | retsub 29 | 30 | // round_tripper 31 | roundtripper_1: 32 | proto 1 1 33 | byte "" 34 | int 0 35 | dupn 3 36 | byte "" 37 | dup 38 | frame_dig -1 39 | callsub numericalcomp_0 40 | frame_bury 1 41 | frame_dig 1 42 | callsub numericalcomp_0 43 | frame_bury 2 44 | frame_dig -1 45 | itob 46 | extract 6 0 47 | frame_dig 1 48 | itob 49 | extract 6 0 50 | concat 51 | frame_dig 2 52 | itob 53 | extract 6 0 54 | concat 55 | frame_bury 0 56 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint32_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | int 0 4 | extract_uint32 5 | store 1 6 | load 1 7 | callsub roundtripper_1 8 | store 0 9 | byte 0x151f7c75 10 | load 0 11 | concat 12 | log 13 | int 1 14 | return 15 | 16 | // numerical_comp 17 | numericalcomp_0: 18 | store 6 19 | int 4294967295 20 | load 6 21 | - 22 | store 7 23 | load 7 24 | int 4294967296 25 | < 26 | assert 27 | load 7 28 | retsub 29 | 30 | // round_tripper 31 | roundtripper_1: 32 | store 2 33 | load 2 34 | callsub numericalcomp_0 35 | store 4 36 | load 4 37 | callsub numericalcomp_0 38 | store 5 39 | load 2 40 | itob 41 | extract 4 0 42 | load 4 43 | itob 44 | extract 4 0 45 | concat 46 | load 5 47 | itob 48 | extract 4 0 49 | concat 50 | store 3 51 | load 3 52 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint32_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | int 0 4 | extract_uint32 5 | store 1 6 | load 1 7 | callsub roundtripper_1 8 | store 0 9 | byte 0x151f7c75 10 | load 0 11 | concat 12 | log 13 | int 1 14 | return 15 | 16 | // numerical_comp 17 | numericalcomp_0: 18 | proto 1 1 19 | int 0 20 | int 4294967295 21 | frame_dig -1 22 | - 23 | frame_bury 0 24 | frame_dig 0 25 | int 4294967296 26 | < 27 | assert 28 | retsub 29 | 30 | // round_tripper 31 | roundtripper_1: 32 | proto 1 1 33 | byte "" 34 | int 0 35 | dupn 3 36 | byte "" 37 | dup 38 | frame_dig -1 39 | callsub numericalcomp_0 40 | frame_bury 1 41 | frame_dig 1 42 | callsub numericalcomp_0 43 | frame_bury 2 44 | frame_dig -1 45 | itob 46 | extract 4 0 47 | frame_dig 1 48 | itob 49 | extract 4 0 50 | concat 51 | frame_dig 2 52 | itob 53 | extract 4 0 54 | concat 55 | frame_bury 0 56 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint64[1]_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_2 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // numerical_comp 15 | numericalcomp_0: 16 | store 9 17 | int 18446744073709551615 18 | load 9 19 | - 20 | store 10 21 | load 10 22 | retsub 23 | 24 | // array_complement 25 | arraycomplement_1: 26 | store 6 27 | load 6 28 | int 8 29 | int 0 30 | * 31 | extract_uint64 32 | store 8 33 | load 8 34 | callsub numericalcomp_0 35 | store 8 36 | load 8 37 | itob 38 | store 7 39 | load 7 40 | retsub 41 | 42 | // round_tripper 43 | roundtripper_2: 44 | store 2 45 | load 2 46 | callsub arraycomplement_1 47 | store 4 48 | load 4 49 | callsub arraycomplement_1 50 | store 5 51 | load 2 52 | load 4 53 | concat 54 | load 5 55 | concat 56 | store 3 57 | load 3 58 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint64[1]_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_2 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // numerical_comp 15 | numericalcomp_0: 16 | proto 1 1 17 | int 0 18 | int 18446744073709551615 19 | frame_dig -1 20 | - 21 | frame_bury 0 22 | retsub 23 | 24 | // array_complement 25 | arraycomplement_1: 26 | proto 1 1 27 | byte "" 28 | int 0 29 | dupn 2 30 | byte "" 31 | dup 32 | frame_dig -1 33 | int 8 34 | int 0 35 | * 36 | extract_uint64 37 | frame_bury 1 38 | frame_dig 1 39 | callsub numericalcomp_0 40 | frame_bury 1 41 | frame_dig 1 42 | itob 43 | frame_bury 0 44 | retsub 45 | 46 | // round_tripper 47 | roundtripper_2: 48 | proto 1 1 49 | byte "" 50 | dupn 2 51 | int 0 52 | dup 53 | byte "" 54 | dup 55 | frame_dig -1 56 | callsub arraycomplement_1 57 | frame_bury 1 58 | frame_dig 1 59 | callsub arraycomplement_1 60 | frame_bury 2 61 | frame_dig -1 62 | frame_dig 1 63 | concat 64 | frame_dig 2 65 | concat 66 | frame_bury 0 67 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint64[]_0_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // array_complement 15 | arraycomplement_0: 16 | store 6 17 | int 0 18 | store 8 19 | load 8 20 | itob 21 | extract 6 0 22 | byte "" 23 | concat 24 | store 7 25 | load 7 26 | retsub 27 | 28 | // round_tripper 29 | roundtripper_1: 30 | store 2 31 | load 2 32 | callsub arraycomplement_0 33 | store 4 34 | load 4 35 | callsub arraycomplement_0 36 | store 5 37 | load 2 38 | store 12 39 | load 12 40 | store 11 41 | int 6 42 | store 9 43 | load 9 44 | load 12 45 | len 46 | + 47 | store 10 48 | load 10 49 | int 65536 50 | < 51 | assert 52 | load 9 53 | itob 54 | extract 6 0 55 | load 4 56 | store 12 57 | load 11 58 | load 12 59 | concat 60 | store 11 61 | load 10 62 | store 9 63 | load 9 64 | load 12 65 | len 66 | + 67 | store 10 68 | load 10 69 | int 65536 70 | < 71 | assert 72 | load 9 73 | itob 74 | extract 6 0 75 | concat 76 | load 5 77 | store 12 78 | load 11 79 | load 12 80 | concat 81 | store 11 82 | load 10 83 | store 9 84 | load 9 85 | itob 86 | extract 6 0 87 | concat 88 | load 11 89 | concat 90 | store 3 91 | load 3 92 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint64[]_0_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_1 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // array_complement 15 | arraycomplement_0: 16 | proto 1 1 17 | byte "" 18 | int 0 19 | dup 20 | byte "" 21 | dup 22 | int 0 23 | int 0 24 | frame_bury 5 25 | frame_dig 5 26 | itob 27 | extract 6 0 28 | byte "" 29 | concat 30 | frame_bury 0 31 | retsub 32 | 33 | // round_tripper 34 | roundtripper_1: 35 | proto 1 1 36 | byte "" 37 | dupn 2 38 | int 0 39 | dup 40 | byte "" 41 | dup 42 | frame_dig -1 43 | callsub arraycomplement_0 44 | frame_bury 1 45 | frame_dig 1 46 | callsub arraycomplement_0 47 | frame_bury 2 48 | frame_dig -1 49 | frame_bury 6 50 | frame_dig 6 51 | frame_bury 5 52 | int 6 53 | frame_bury 3 54 | frame_dig 3 55 | frame_dig 6 56 | len 57 | + 58 | frame_bury 4 59 | frame_dig 4 60 | int 65536 61 | < 62 | assert 63 | frame_dig 3 64 | itob 65 | extract 6 0 66 | frame_dig 1 67 | frame_bury 6 68 | frame_dig 5 69 | frame_dig 6 70 | concat 71 | frame_bury 5 72 | frame_dig 4 73 | frame_bury 3 74 | frame_dig 3 75 | frame_dig 6 76 | len 77 | + 78 | frame_bury 4 79 | frame_dig 4 80 | int 65536 81 | < 82 | assert 83 | frame_dig 3 84 | itob 85 | extract 6 0 86 | concat 87 | frame_dig 2 88 | frame_bury 6 89 | frame_dig 5 90 | frame_dig 6 91 | concat 92 | frame_bury 5 93 | frame_dig 4 94 | frame_bury 3 95 | frame_dig 3 96 | itob 97 | extract 6 0 98 | concat 99 | frame_dig 5 100 | concat 101 | frame_bury 0 102 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint64[]_1_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_2 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // numerical_comp 15 | numericalcomp_0: 16 | store 9 17 | int 18446744073709551615 18 | load 9 19 | - 20 | store 10 21 | load 10 22 | retsub 23 | 24 | // array_complement 25 | arraycomplement_1: 26 | store 6 27 | load 6 28 | int 8 29 | int 0 30 | * 31 | int 2 32 | + 33 | extract_uint64 34 | store 8 35 | load 8 36 | callsub numericalcomp_0 37 | store 8 38 | int 1 39 | store 11 40 | load 11 41 | itob 42 | extract 6 0 43 | load 8 44 | itob 45 | concat 46 | store 7 47 | load 7 48 | retsub 49 | 50 | // round_tripper 51 | roundtripper_2: 52 | store 2 53 | load 2 54 | callsub arraycomplement_1 55 | store 4 56 | load 4 57 | callsub arraycomplement_1 58 | store 5 59 | load 2 60 | store 15 61 | load 15 62 | store 14 63 | int 6 64 | store 12 65 | load 12 66 | load 15 67 | len 68 | + 69 | store 13 70 | load 13 71 | int 65536 72 | < 73 | assert 74 | load 12 75 | itob 76 | extract 6 0 77 | load 4 78 | store 15 79 | load 14 80 | load 15 81 | concat 82 | store 14 83 | load 13 84 | store 12 85 | load 12 86 | load 15 87 | len 88 | + 89 | store 13 90 | load 13 91 | int 65536 92 | < 93 | assert 94 | load 12 95 | itob 96 | extract 6 0 97 | concat 98 | load 5 99 | store 15 100 | load 14 101 | load 15 102 | concat 103 | store 14 104 | load 13 105 | store 12 106 | load 12 107 | itob 108 | extract 6 0 109 | concat 110 | load 14 111 | concat 112 | store 3 113 | load 3 114 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint64[]_1_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | store 1 4 | load 1 5 | callsub roundtripper_2 6 | store 0 7 | byte 0x151f7c75 8 | load 0 9 | concat 10 | log 11 | int 1 12 | return 13 | 14 | // numerical_comp 15 | numericalcomp_0: 16 | proto 1 1 17 | int 0 18 | int 18446744073709551615 19 | frame_dig -1 20 | - 21 | frame_bury 0 22 | retsub 23 | 24 | // array_complement 25 | arraycomplement_1: 26 | proto 1 1 27 | byte "" 28 | int 0 29 | dupn 3 30 | byte "" 31 | dup 32 | int 0 33 | frame_dig -1 34 | int 8 35 | int 0 36 | * 37 | int 2 38 | + 39 | extract_uint64 40 | frame_bury 1 41 | frame_dig 1 42 | callsub numericalcomp_0 43 | frame_bury 1 44 | int 1 45 | frame_bury 7 46 | frame_dig 7 47 | itob 48 | extract 6 0 49 | frame_dig 1 50 | itob 51 | concat 52 | frame_bury 0 53 | retsub 54 | 55 | // round_tripper 56 | roundtripper_2: 57 | proto 1 1 58 | byte "" 59 | dupn 2 60 | int 0 61 | dup 62 | byte "" 63 | dup 64 | frame_dig -1 65 | callsub arraycomplement_1 66 | frame_bury 1 67 | frame_dig 1 68 | callsub arraycomplement_1 69 | frame_bury 2 70 | frame_dig -1 71 | frame_bury 6 72 | frame_dig 6 73 | frame_bury 5 74 | int 6 75 | frame_bury 3 76 | frame_dig 3 77 | frame_dig 6 78 | len 79 | + 80 | frame_bury 4 81 | frame_dig 4 82 | int 65536 83 | < 84 | assert 85 | frame_dig 3 86 | itob 87 | extract 6 0 88 | frame_dig 1 89 | frame_bury 6 90 | frame_dig 5 91 | frame_dig 6 92 | concat 93 | frame_bury 5 94 | frame_dig 4 95 | frame_bury 3 96 | frame_dig 3 97 | frame_dig 6 98 | len 99 | + 100 | frame_bury 4 101 | frame_dig 4 102 | int 65536 103 | < 104 | assert 105 | frame_dig 3 106 | itob 107 | extract 6 0 108 | concat 109 | frame_dig 2 110 | frame_bury 6 111 | frame_dig 5 112 | frame_dig 6 113 | concat 114 | frame_bury 5 115 | frame_dig 4 116 | frame_bury 3 117 | frame_dig 3 118 | itob 119 | extract 6 0 120 | concat 121 | frame_dig 5 122 | concat 123 | frame_bury 0 124 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint64_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | btoi 4 | store 1 5 | load 1 6 | callsub roundtripper_1 7 | store 0 8 | byte 0x151f7c75 9 | load 0 10 | concat 11 | log 12 | int 1 13 | return 14 | 15 | // numerical_comp 16 | numericalcomp_0: 17 | store 6 18 | int 18446744073709551615 19 | load 6 20 | - 21 | store 7 22 | load 7 23 | retsub 24 | 25 | // round_tripper 26 | roundtripper_1: 27 | store 2 28 | load 2 29 | callsub numericalcomp_0 30 | store 4 31 | load 4 32 | callsub numericalcomp_0 33 | store 5 34 | load 2 35 | itob 36 | load 4 37 | itob 38 | concat 39 | load 5 40 | itob 41 | concat 42 | store 3 43 | load 3 44 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint64_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | btoi 4 | store 1 5 | load 1 6 | callsub roundtripper_1 7 | store 0 8 | byte 0x151f7c75 9 | load 0 10 | concat 11 | log 12 | int 1 13 | return 14 | 15 | // numerical_comp 16 | numericalcomp_0: 17 | proto 1 1 18 | int 0 19 | int 18446744073709551615 20 | frame_dig -1 21 | - 22 | frame_bury 0 23 | retsub 24 | 25 | // round_tripper 26 | roundtripper_1: 27 | proto 1 1 28 | byte "" 29 | int 0 30 | dupn 3 31 | byte "" 32 | dup 33 | frame_dig -1 34 | callsub numericalcomp_0 35 | frame_bury 1 36 | frame_dig 1 37 | callsub numericalcomp_0 38 | frame_bury 2 39 | frame_dig -1 40 | itob 41 | frame_dig 1 42 | itob 43 | concat 44 | frame_dig 2 45 | itob 46 | concat 47 | frame_bury 0 48 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint8_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | int 0 4 | getbyte 5 | store 1 6 | load 1 7 | callsub roundtripper_1 8 | store 0 9 | byte 0x151f7c75 10 | load 0 11 | concat 12 | log 13 | int 1 14 | return 15 | 16 | // numerical_comp 17 | numericalcomp_0: 18 | store 6 19 | int 255 20 | load 6 21 | - 22 | store 7 23 | load 7 24 | int 256 25 | < 26 | assert 27 | load 7 28 | retsub 29 | 30 | // round_tripper 31 | roundtripper_1: 32 | store 2 33 | load 2 34 | callsub numericalcomp_0 35 | store 4 36 | load 4 37 | callsub numericalcomp_0 38 | store 5 39 | byte 0x00 40 | int 0 41 | load 2 42 | setbyte 43 | byte 0x00 44 | int 0 45 | load 4 46 | setbyte 47 | concat 48 | byte 0x00 49 | int 0 50 | load 5 51 | setbyte 52 | concat 53 | store 3 54 | load 3 55 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/roundtrip/app_roundtrip_uint8_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txna ApplicationArgs 0 3 | int 0 4 | getbyte 5 | store 1 6 | load 1 7 | callsub roundtripper_1 8 | store 0 9 | byte 0x151f7c75 10 | load 0 11 | concat 12 | log 13 | int 1 14 | return 15 | 16 | // numerical_comp 17 | numericalcomp_0: 18 | proto 1 1 19 | int 0 20 | int 255 21 | frame_dig -1 22 | - 23 | frame_bury 0 24 | frame_dig 0 25 | int 256 26 | < 27 | assert 28 | retsub 29 | 30 | // round_tripper 31 | roundtripper_1: 32 | proto 1 1 33 | byte "" 34 | int 0 35 | dupn 3 36 | byte "" 37 | dup 38 | frame_dig -1 39 | callsub numericalcomp_0 40 | frame_bury 1 41 | frame_dig 1 42 | callsub numericalcomp_0 43 | frame_bury 2 44 | byte 0x00 45 | int 0 46 | frame_dig -1 47 | setbyte 48 | byte 0x00 49 | int 0 50 | frame_dig 1 51 | setbyte 52 | concat 53 | byte 0x00 54 | int 0 55 | frame_dig 2 56 | setbyte 57 | concat 58 | frame_bury 0 59 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/app_exp.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub exp_0 3 | store 0 4 | load 0 5 | itob 6 | log 7 | load 0 8 | return 9 | 10 | // exp 11 | exp_0: 12 | pushint 2 // 2 13 | pushint 10 // 10 14 | exp 15 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/app_oldfac.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | intcblock 1 3 | txna ApplicationArgs 0 4 | btoi 5 | callsub oldfac_0 6 | store 0 7 | load 0 8 | itob 9 | log 10 | load 0 11 | return 12 | 13 | // oldfac 14 | oldfac_0: 15 | store 1 16 | load 1 17 | pushint 2 // 2 18 | < 19 | bnz oldfac_0_l2 20 | load 1 21 | load 1 22 | intc_0 // 1 23 | - 24 | load 1 25 | swap 26 | callsub oldfac_0 27 | swap 28 | store 1 29 | * 30 | b oldfac_0_l3 31 | oldfac_0_l2: 32 | intc_0 // 1 33 | oldfac_0_l3: 34 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/app_slow_fibonacci.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | intcblock 1 3 | txna ApplicationArgs 0 4 | btoi 5 | callsub slowfibonacci_0 6 | store 0 7 | load 0 8 | itob 9 | log 10 | load 0 11 | return 12 | 13 | // slow_fibonacci 14 | slowfibonacci_0: 15 | store 1 16 | load 1 17 | intc_0 // 1 18 | <= 19 | bnz slowfibonacci_0_l2 20 | load 1 21 | pushint 2 // 2 22 | - 23 | load 1 24 | swap 25 | callsub slowfibonacci_0 26 | swap 27 | store 1 28 | load 1 29 | intc_0 // 1 30 | - 31 | load 1 32 | swap 33 | callsub slowfibonacci_0 34 | swap 35 | store 1 36 | + 37 | b slowfibonacci_0_l3 38 | slowfibonacci_0_l2: 39 | load 1 40 | slowfibonacci_0_l3: 41 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/app_square.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | btoi 4 | callsub square_0 5 | store 0 6 | load 0 7 | itob 8 | log 9 | load 0 10 | return 11 | 12 | // square 13 | square_0: 14 | store 1 15 | load 1 16 | pushint 2 // 2 17 | exp 18 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/app_square_byref.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | btoi 4 | store 1 5 | pushint 1 // 1 6 | callsub squarebyref_0 7 | pushint 1337 // 1337 8 | store 0 9 | load 0 10 | itob 11 | log 12 | load 0 13 | return 14 | 15 | // square_byref 16 | squarebyref_0: 17 | store 2 18 | load 2 19 | load 2 20 | loads 21 | load 2 22 | loads 23 | * 24 | stores 25 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/app_string_mult.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | intcblock 1 3 | txna ApplicationArgs 0 4 | store 1 5 | intc_0 // 1 6 | txna ApplicationArgs 1 7 | btoi 8 | callsub stringmult_0 9 | store 0 10 | load 0 11 | log 12 | load 0 13 | len 14 | return 15 | 16 | // string_mult 17 | stringmult_0: 18 | store 3 19 | store 2 20 | intc_0 // 1 21 | store 4 22 | load 2 23 | loads 24 | store 5 25 | load 2 26 | pushbytes 0x // "" 27 | stores 28 | stringmult_0_l1: 29 | load 4 30 | load 3 31 | <= 32 | bz stringmult_0_l3 33 | load 2 34 | load 2 35 | loads 36 | load 5 37 | concat 38 | stores 39 | load 4 40 | intc_0 // 1 41 | + 42 | store 4 43 | b stringmult_0_l1 44 | stringmult_0_l3: 45 | load 2 46 | loads 47 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/app_swap.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | store 1 4 | txna ApplicationArgs 1 5 | store 2 6 | pushint 1 // 1 7 | pushint 2 // 2 8 | callsub swap_0 9 | pushint 1337 // 1337 10 | store 0 11 | load 0 12 | itob 13 | log 14 | load 0 15 | return 16 | 17 | // swap 18 | swap_0: 19 | store 4 20 | store 3 21 | load 3 22 | loads 23 | store 5 24 | load 3 25 | load 4 26 | loads 27 | stores 28 | load 4 29 | load 5 30 | stores 31 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/lsig_exp.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub exp_0 3 | return 4 | 5 | // exp 6 | exp_0: 7 | pushint 2 // 2 8 | pushint 10 // 10 9 | exp 10 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/lsig_oldfac.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | intcblock 1 3 | arg 0 4 | btoi 5 | callsub oldfac_0 6 | return 7 | 8 | // oldfac 9 | oldfac_0: 10 | store 0 11 | load 0 12 | pushint 2 // 2 13 | < 14 | bnz oldfac_0_l2 15 | load 0 16 | load 0 17 | intc_0 // 1 18 | - 19 | load 0 20 | swap 21 | callsub oldfac_0 22 | swap 23 | store 0 24 | * 25 | b oldfac_0_l3 26 | oldfac_0_l2: 27 | intc_0 // 1 28 | oldfac_0_l3: 29 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/lsig_slow_fibonacci.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | intcblock 1 3 | arg 0 4 | btoi 5 | callsub slowfibonacci_0 6 | return 7 | 8 | // slow_fibonacci 9 | slowfibonacci_0: 10 | store 0 11 | load 0 12 | intc_0 // 1 13 | <= 14 | bnz slowfibonacci_0_l2 15 | load 0 16 | pushint 2 // 2 17 | - 18 | load 0 19 | swap 20 | callsub slowfibonacci_0 21 | swap 22 | store 0 23 | load 0 24 | intc_0 // 1 25 | - 26 | load 0 27 | swap 28 | callsub slowfibonacci_0 29 | swap 30 | store 0 31 | + 32 | b slowfibonacci_0_l3 33 | slowfibonacci_0_l2: 34 | load 0 35 | slowfibonacci_0_l3: 36 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/lsig_square.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | btoi 4 | callsub square_0 5 | return 6 | 7 | // square 8 | square_0: 9 | store 0 10 | load 0 11 | pushint 2 // 2 12 | exp 13 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/lsig_square_byref.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | btoi 4 | store 1 5 | pushint 1 // 1 6 | callsub squarebyref_0 7 | pushint 1337 // 1337 8 | return 9 | 10 | // square_byref 11 | squarebyref_0: 12 | store 0 13 | load 0 14 | load 0 15 | loads 16 | load 0 17 | loads 18 | * 19 | stores 20 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/lsig_string_mult.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | intcblock 1 3 | arg 0 4 | store 4 5 | pushint 4 // 4 6 | arg 1 7 | btoi 8 | callsub stringmult_0 9 | len 10 | return 11 | 12 | // string_mult 13 | stringmult_0: 14 | store 1 15 | store 0 16 | intc_0 // 1 17 | store 2 18 | load 0 19 | loads 20 | store 3 21 | load 0 22 | pushbytes 0x // "" 23 | stores 24 | stringmult_0_l1: 25 | load 2 26 | load 1 27 | <= 28 | bz stringmult_0_l3 29 | load 0 30 | load 0 31 | loads 32 | load 3 33 | concat 34 | stores 35 | load 2 36 | intc_0 // 1 37 | + 38 | store 2 39 | b stringmult_0_l1 40 | stringmult_0_l3: 41 | load 0 42 | loads 43 | retsub -------------------------------------------------------------------------------- /tests/integration/teal/stability/lsig_swap.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | store 3 4 | arg 1 5 | store 4 6 | pushint 3 // 3 7 | pushint 4 // 4 8 | callsub swap_0 9 | pushint 1337 // 1337 10 | return 11 | 12 | // swap 13 | swap_0: 14 | store 1 15 | store 0 16 | load 0 17 | loads 18 | store 2 19 | load 0 20 | load 1 21 | loads 22 | stores 23 | load 1 24 | load 2 25 | stores 26 | retsub -------------------------------------------------------------------------------- /tests/mock_version.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from importlib import metadata 3 | 4 | 5 | @pytest.fixture 6 | def mock_version(version: str, monkeypatch: pytest.MonkeyPatch): 7 | def mocked_version(name: str): 8 | if ( 9 | name == "pyteal" 10 | and version is not None # don't mock if no version is specified 11 | ): 12 | return version 13 | else: 14 | return metadata.version(name) 15 | 16 | monkeypatch.setattr(metadata, "version", mocked_version) 17 | -------------------------------------------------------------------------------- /tests/teal/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorand/pyteal/9a610281df4f306f2a0f94483f4a009320a5c63c/tests/teal/__init__.py -------------------------------------------------------------------------------- /tests/teal/router/nontriv_clear_clear_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txn NumAppArgs 3 | int 2 4 | < 5 | bnz main_l8 6 | txna ApplicationArgs 0 7 | byte "CLEANUP" 8 | != 9 | bnz main_l7 10 | txna ApplicationArgs 1 11 | byte "ABORTING" 12 | != 13 | bnz main_l6 14 | int 1 15 | bnz main_l5 16 | err 17 | main_l5: 18 | int 0 19 | return 20 | main_l6: 21 | int 1 22 | return 23 | main_l7: 24 | int 1 25 | return 26 | main_l8: 27 | int 1 28 | return -------------------------------------------------------------------------------- /tests/teal/router/nontriv_clear_clear_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | txn NumAppArgs 3 | int 2 4 | < 5 | bnz main_l8 6 | txna ApplicationArgs 0 7 | byte "CLEANUP" 8 | != 9 | bnz main_l7 10 | txna ApplicationArgs 1 11 | byte "ABORTING" 12 | != 13 | bnz main_l6 14 | int 1 15 | bnz main_l5 16 | err 17 | main_l5: 18 | int 0 19 | return 20 | main_l6: 21 | int 1 22 | return 23 | main_l7: 24 | int 1 25 | return 26 | main_l8: 27 | int 1 28 | return -------------------------------------------------------------------------------- /tests/teal/router/questionableFP_clear_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | int 1 3 | return -------------------------------------------------------------------------------- /tests/teal/router/questionable_clear_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | int 1 3 | return -------------------------------------------------------------------------------- /tests/teal/router/yaccFP_clear_v8.teal: -------------------------------------------------------------------------------- 1 | #pragma version 8 2 | int 1 3 | return -------------------------------------------------------------------------------- /tests/teal/router/yacc_clear_v6.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | int 1 3 | return -------------------------------------------------------------------------------- /tests/teal/user_guide_snippet_dynamic_scratch_var.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | int 0 3 | store 1 4 | int 7 5 | store 0 6 | load 1 7 | load 1 8 | loads 9 | int 3 10 | + 11 | stores 12 | load 0 13 | int 10 14 | == 15 | assert 16 | int 1 17 | return -------------------------------------------------------------------------------- /tests/teal/user_guide_snippet_recursiveIsEven.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | int 15 3 | callsub recursiveIsEven_0 4 | return 5 | 6 | // recursiveIsEven 7 | recursiveIsEven_0: 8 | store 0 9 | load 0 10 | int 0 11 | == 12 | bnz recursiveIsEven_0_l4 13 | load 0 14 | int 1 15 | == 16 | bnz recursiveIsEven_0_l3 17 | load 0 18 | int 2 19 | - 20 | load 0 21 | swap 22 | callsub recursiveIsEven_0 23 | swap 24 | store 0 25 | b recursiveIsEven_0_l5 26 | recursiveIsEven_0_l3: 27 | int 0 28 | b recursiveIsEven_0_l5 29 | recursiveIsEven_0_l4: 30 | int 1 31 | recursiveIsEven_0_l5: 32 | retsub -------------------------------------------------------------------------------- /tests/unit/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algorand/pyteal/9a610281df4f306f2a0f94483f4a009320a5c63c/tests/unit/__init__.py -------------------------------------------------------------------------------- /tests/unit/feature_gates_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from feature_gates import FeatureGates 4 | 5 | 6 | @pytest.mark.serial 7 | def test_feature_gates(): 8 | with pytest.raises(ValueError, match="Unknown feature='foo'"): 9 | FeatureGates.get("foo") 10 | 11 | with pytest.raises(ValueError, match="Cannot set unknown feature='foo'"): 12 | FeatureGates.set("foo", 42) 13 | 14 | default_sourcemap_gate: bool = FeatureGates._gates.sourcemap_enabled 15 | default_sourcemap_debug_gate: bool = FeatureGates._gates.sourcemap_debug 16 | assert FeatureGates.get("sourcemap_enabled") is default_sourcemap_gate 17 | assert FeatureGates.get("sourcemap_debug") is default_sourcemap_debug_gate 18 | assert FeatureGates.sourcemap_enabled() is default_sourcemap_gate 19 | assert FeatureGates.sourcemap_debug() is default_sourcemap_debug_gate 20 | 21 | from pyteal import stack_frame 22 | 23 | assert stack_frame.NatalStackFrame.sourcemapping_is_off() is True 24 | 25 | # enable source mapping: 26 | FeatureGates.set("sourcemap_enabled", True) 27 | FeatureGates.set("sourcemap_debug", True) 28 | assert FeatureGates._gates.sourcemap_enabled is True 29 | assert FeatureGates._gates.sourcemap_debug is True 30 | assert FeatureGates.get("sourcemap_enabled") is True 31 | assert FeatureGates.get("sourcemap_debug") is True 32 | assert FeatureGates.sourcemap_enabled() is True 33 | assert FeatureGates.sourcemap_debug() is True 34 | 35 | assert stack_frame.NatalStackFrame.sourcemapping_is_off() is False 36 | 37 | # disable source mapping: 38 | FeatureGates.set("sourcemap_enabled", False) 39 | FeatureGates.set("sourcemap_debug", False) 40 | assert FeatureGates._gates.sourcemap_enabled is False 41 | assert FeatureGates._gates.sourcemap_debug is False 42 | assert FeatureGates.get("sourcemap_enabled") is False 43 | assert FeatureGates.get("sourcemap_debug") is False 44 | assert FeatureGates.sourcemap_enabled() is False 45 | assert FeatureGates.sourcemap_debug() is False 46 | -------------------------------------------------------------------------------- /tests/unit/module_test.py: -------------------------------------------------------------------------------- 1 | from pyteal import * 2 | 3 | 4 | def test_export_int(): 5 | from pyteal import ast 6 | 7 | assert int != ast.int 8 | -------------------------------------------------------------------------------- /tests/unit/pre_v6_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | import pyteal as pt 4 | 5 | from tests.compile_asserts import assert_new_v_old 6 | 7 | # ---- TESTS FOR PyTEAL THAT PREDATE PASS-BY-REF - assert that changes to compiler don't affect the generated TEAL ---- # 8 | 9 | 10 | @pt.Subroutine(pt.TealType.bytes) 11 | def logcat(some_bytes, an_int): 12 | catted = pt.ScratchVar(pt.TealType.bytes) 13 | return pt.Seq( 14 | catted.store(pt.Concat(some_bytes, pt.Itob(an_int))), 15 | pt.Log(catted.load()), 16 | catted.load(), 17 | ) 18 | 19 | 20 | def sub_logcat(): 21 | return pt.Seq( 22 | pt.Assert(logcat(pt.Bytes("hello"), pt.Int(42)) == pt.Bytes("hello42")), 23 | pt.Int(1), 24 | ) 25 | 26 | 27 | @pt.Subroutine(pt.TealType.uint64) 28 | def slow_fibonacci(n): 29 | return ( 30 | pt.If(n <= pt.Int(1)) 31 | .Then(n) 32 | .Else(slow_fibonacci(n - pt.Int(2)) + slow_fibonacci(n - pt.Int(1))) 33 | ) 34 | 35 | 36 | def sub_slowfib(): 37 | return slow_fibonacci(pt.Int(3)) 38 | 39 | 40 | @pt.Subroutine(pt.TealType.uint64) 41 | def fast_fibonacci(n): 42 | i = pt.ScratchVar(pt.TealType.uint64) 43 | a = pt.ScratchVar(pt.TealType.uint64) 44 | b = pt.ScratchVar(pt.TealType.uint64) 45 | return pt.Seq( 46 | a.store(pt.Int(0)), 47 | b.store(pt.Int(1)), 48 | pt.For(i.store(pt.Int(1)), i.load() <= n, i.store(i.load() + pt.Int(1))).Do( 49 | pt.Seq( 50 | b.store(a.load() + b.load()), 51 | a.store(b.load() - a.load()), 52 | ) 53 | ), 54 | a.load(), 55 | ) 56 | 57 | 58 | def sub_fastfib(): 59 | return fast_fibonacci(pt.Int(3)) 60 | 61 | 62 | @pt.Subroutine(pt.TealType.uint64) 63 | def recursiveIsEven(i): 64 | return ( 65 | pt.If(i == pt.Int(0)) 66 | .Then(pt.Int(1)) 67 | .ElseIf(i == pt.Int(1)) 68 | .Then(pt.Int(0)) 69 | .Else(recursiveIsEven(i - pt.Int(2))) 70 | ) 71 | 72 | 73 | def sub_even(): 74 | return pt.Seq( 75 | pt.Pop(recursiveIsEven(pt.Int(1000))), 76 | recursiveIsEven(pt.Int(1001)), 77 | ) 78 | 79 | 80 | PT_CASES = (sub_logcat, sub_slowfib, sub_fastfib, sub_even) 81 | 82 | 83 | @pytest.mark.parametrize("pt_case", PT_CASES) 84 | def test_old(pt_case): 85 | assert_new_v_old(pt_case, 5, "pre_v6") 86 | -------------------------------------------------------------------------------- /tests/unit/sourcemap_constructs_allpy_test.py: -------------------------------------------------------------------------------- 1 | from feature_gates import FeatureGates 2 | 3 | import pytest 4 | 5 | from tests.unit.sourcemap_constructs311_test import ( 6 | CONSTRUCTS, 7 | CONSTRUCTS_LATEST_VERSION, 8 | constructs_test, 9 | ) 10 | 11 | 12 | @pytest.fixture 13 | def sourcemap_enabled(): 14 | previous = FeatureGates.sourcemap_enabled() 15 | FeatureGates.set_sourcemap_enabled(True) 16 | yield 17 | FeatureGates.set_sourcemap_enabled(previous) 18 | 19 | 20 | @pytest.mark.slow 21 | @pytest.mark.serial 22 | @pytest.mark.parametrize("i, test_case", enumerate(CONSTRUCTS)) 23 | @pytest.mark.parametrize("mode", ["Application", "Signature"]) 24 | @pytest.mark.parametrize("version", range(2, CONSTRUCTS_LATEST_VERSION + 1)) 25 | def test_constructs_very_slow(sourcemap_enabled, i, test_case, mode, version): 26 | constructs_test(i, test_case, mode, version) 27 | -------------------------------------------------------------------------------- /tests/unit/sourcemap_monkey_raises_test.py: -------------------------------------------------------------------------------- 1 | from contextlib import contextmanager 2 | 3 | import pytest 4 | 5 | from feature_gates import FeatureGates 6 | 7 | 8 | @contextmanager 9 | def sourcemap_disabled(): 10 | previous = FeatureGates.sourcemap_enabled() 11 | FeatureGates.set_sourcemap_enabled(False) 12 | yield 13 | FeatureGates.set_sourcemap_enabled(previous) 14 | 15 | 16 | @pytest.mark.serial 17 | def test_sourcemap_fails_elegantly_when_disabled(): 18 | from examples.application.abi.algobank import router 19 | from pyteal import OptimizeOptions 20 | from pyteal.errors import SourceMapDisabledError 21 | 22 | with sourcemap_disabled(): 23 | with pytest.raises( 24 | SourceMapDisabledError, match="because stack frame discovery is turned off" 25 | ): 26 | router.compile( 27 | version=6, 28 | optimize=OptimizeOptions(scratch_slots=True), 29 | with_sourcemaps=True, 30 | ) 31 | -------------------------------------------------------------------------------- /tests/unit/teal/abi/app_fn_0arg_0ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub fn0arg0ret_0 3 | int 1 4 | return 5 | 6 | // fn_0arg_0ret 7 | fn0arg0ret_0: 8 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/app_fn_0arg_uint64_ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub fn0arguint64ret_0 3 | store 1 4 | byte 0x151f7c75 5 | load 1 6 | itob 7 | concat 8 | log 9 | int 1 10 | return 11 | 12 | // fn_0arg_uint64_ret 13 | fn0arguint64ret_0: 14 | int 1 15 | store 0 16 | load 0 17 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/app_fn_1arg_0ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | btoi 4 | store 1 5 | load 1 6 | callsub fn1arg0ret_0 7 | int 1 8 | return 9 | 10 | // fn_1arg_0ret 11 | fn1arg0ret_0: 12 | store 0 13 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/app_fn_1arg_1ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | btoi 4 | store 3 5 | load 3 6 | callsub fn1arg1ret_0 7 | store 2 8 | byte 0x151f7c75 9 | load 2 10 | itob 11 | concat 12 | log 13 | int 1 14 | return 15 | 16 | // fn_1arg_1ret 17 | fn1arg1ret_0: 18 | store 0 19 | load 0 20 | store 1 21 | load 1 22 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/app_fn_1tt_arg_uint64_ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | callsub fn1ttarguint64ret_0 4 | store 2 5 | byte 0x151f7c75 6 | load 2 7 | itob 8 | concat 9 | log 10 | int 1 11 | return 12 | 13 | // fn_1tt_arg_uint64_ret 14 | fn1ttarguint64ret_0: 15 | store 0 16 | int 1 17 | store 1 18 | load 1 19 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/app_fn_2arg_0ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | btoi 4 | store 2 5 | txna ApplicationArgs 1 6 | store 3 7 | load 2 8 | load 3 9 | callsub fn2arg0ret_0 10 | int 1 11 | return 12 | 13 | // fn_2arg_0ret 14 | fn2arg0ret_0: 15 | store 1 16 | store 0 17 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/app_fn_2mixed_arg_1ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | btoi 4 | store 4 5 | txna ApplicationArgs 1 6 | store 5 7 | load 4 8 | int 5 9 | callsub fn2mixedarg1ret_0 10 | store 3 11 | byte 0x151f7c75 12 | load 3 13 | itob 14 | concat 15 | log 16 | int 1 17 | return 18 | 19 | // fn_2mixed_arg_1ret 20 | fn2mixedarg1ret_0: 21 | store 1 22 | store 0 23 | load 1 24 | load 0 25 | itob 26 | stores 27 | load 0 28 | store 2 29 | load 2 30 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/app_fn_3mixed_args_0ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | btoi 4 | store 3 5 | txna ApplicationArgs 1 6 | btoi 7 | store 4 8 | txna ApplicationArgs 2 9 | store 5 10 | load 3 11 | int 4 12 | load 5 13 | callsub fn3mixedargs0ret_0 14 | int 1 15 | return 16 | 17 | // fn_3mixed_args_0ret 18 | fn3mixedargs0ret_0: 19 | store 2 20 | store 1 21 | store 0 22 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/lsig_fn_0arg_0ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub fn0arg0ret_0 3 | int 1 4 | return 5 | 6 | // fn_0arg_0ret 7 | fn0arg0ret_0: 8 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/lsig_fn_0arg_uint64_ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub fn0arguint64ret_0 3 | store 0 4 | load 0 5 | itob 6 | pop 7 | int 1 8 | return 9 | 10 | // fn_0arg_uint64_ret 11 | fn0arguint64ret_0: 12 | int 1 13 | store 1 14 | load 1 15 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/lsig_fn_1arg_0ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | btoi 4 | store 0 5 | load 0 6 | callsub fn1arg0ret_0 7 | int 1 8 | return 9 | 10 | // fn_1arg_0ret 11 | fn1arg0ret_0: 12 | store 1 13 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/lsig_fn_1arg_1ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | btoi 4 | store 1 5 | load 1 6 | callsub fn1arg1ret_0 7 | store 0 8 | load 0 9 | itob 10 | pop 11 | int 1 12 | return 13 | 14 | // fn_1arg_1ret 15 | fn1arg1ret_0: 16 | store 2 17 | load 2 18 | store 3 19 | load 3 20 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/lsig_fn_1tt_arg_uint64_ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | callsub fn1ttarguint64ret_0 4 | store 0 5 | load 0 6 | itob 7 | pop 8 | int 1 9 | return 10 | 11 | // fn_1tt_arg_uint64_ret 12 | fn1ttarguint64ret_0: 13 | store 1 14 | int 1 15 | store 2 16 | load 2 17 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/lsig_fn_2arg_0ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | btoi 4 | store 0 5 | arg 1 6 | store 1 7 | load 0 8 | load 1 9 | callsub fn2arg0ret_0 10 | int 1 11 | return 12 | 13 | // fn_2arg_0ret 14 | fn2arg0ret_0: 15 | store 3 16 | store 2 17 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/lsig_fn_2mixed_arg_1ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | btoi 4 | store 1 5 | arg 1 6 | store 2 7 | load 1 8 | int 2 9 | callsub fn2mixedarg1ret_0 10 | store 0 11 | load 0 12 | itob 13 | pop 14 | int 1 15 | return 16 | 17 | // fn_2mixed_arg_1ret 18 | fn2mixedarg1ret_0: 19 | store 4 20 | store 3 21 | load 4 22 | load 3 23 | itob 24 | stores 25 | load 3 26 | store 5 27 | load 5 28 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/abi/lsig_fn_3mixed_args_0ret.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | btoi 4 | store 0 5 | arg 1 6 | btoi 7 | store 1 8 | arg 2 9 | store 2 10 | load 0 11 | int 1 12 | load 2 13 | callsub fn3mixedargs0ret_0 14 | int 1 15 | return 16 | 17 | // fn_3mixed_args_0ret 18 | fn3mixedargs0ret_0: 19 | store 5 20 | store 4 21 | store 3 22 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/app_utest_any.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub utestany_0 3 | store 1 4 | byte "nada" 5 | log 6 | load 1 7 | store 2 8 | int 1337 9 | return 10 | 11 | // utest_any 12 | utestany_0: 13 | int 0 14 | store 0 15 | load 0 16 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/app_utest_any_args.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | btoi 4 | txna ApplicationArgs 1 5 | txna ApplicationArgs 2 6 | callsub utestanyargs_0 7 | store 4 8 | byte "nada" 9 | log 10 | load 4 11 | store 5 12 | int 1337 13 | return 14 | 15 | // utest_any_args 16 | utestanyargs_0: 17 | store 2 18 | store 1 19 | store 0 20 | int 0 21 | store 3 22 | load 3 23 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/app_utest_bytes.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub utestbytes_0 3 | store 0 4 | load 0 5 | log 6 | load 0 7 | len 8 | return 9 | 10 | // utest_bytes 11 | utestbytes_0: 12 | byte "" 13 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/app_utest_bytes_args.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | btoi 4 | txna ApplicationArgs 1 5 | txna ApplicationArgs 2 6 | callsub utestbytesargs_0 7 | store 3 8 | load 3 9 | log 10 | load 3 11 | len 12 | return 13 | 14 | // utest_bytes_args 15 | utestbytesargs_0: 16 | store 2 17 | store 1 18 | store 0 19 | byte "" 20 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/app_utest_int.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub utestint_0 3 | store 0 4 | load 0 5 | itob 6 | log 7 | load 0 8 | return 9 | 10 | // utest_int 11 | utestint_0: 12 | int 0 13 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/app_utest_int_args.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | btoi 4 | txna ApplicationArgs 1 5 | txna ApplicationArgs 2 6 | callsub utestintargs_0 7 | store 3 8 | load 3 9 | itob 10 | log 11 | load 3 12 | return 13 | 14 | // utest_int_args 15 | utestintargs_0: 16 | store 2 17 | store 1 18 | store 0 19 | int 0 20 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/app_utest_noop.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub utestnoop_0 3 | int 1337 4 | store 0 5 | load 0 6 | itob 7 | log 8 | load 0 9 | return 10 | 11 | // utest_noop 12 | utestnoop_0: 13 | int 0 14 | pop 15 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/app_utest_noop_args.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 0 3 | btoi 4 | txna ApplicationArgs 1 5 | txna ApplicationArgs 2 6 | callsub utestnoopargs_0 7 | int 1337 8 | store 3 9 | load 3 10 | itob 11 | log 12 | load 3 13 | return 14 | 15 | // utest_noop_args 16 | utestnoopargs_0: 17 | store 2 18 | store 1 19 | store 0 20 | int 0 21 | pop 22 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/lsig_utest_any.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub utestany_0 3 | store 0 4 | int 1337 5 | return 6 | 7 | // utest_any 8 | utestany_0: 9 | int 0 10 | store 1 11 | load 1 12 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/lsig_utest_any_args.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | btoi 4 | arg 1 5 | arg 2 6 | callsub utestanyargs_0 7 | store 0 8 | int 1337 9 | return 10 | 11 | // utest_any_args 12 | utestanyargs_0: 13 | store 3 14 | store 2 15 | store 1 16 | int 0 17 | store 4 18 | load 4 19 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/lsig_utest_bytes.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub utestbytes_0 3 | len 4 | return 5 | 6 | // utest_bytes 7 | utestbytes_0: 8 | byte "" 9 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/lsig_utest_bytes_args.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | btoi 4 | arg 1 5 | arg 2 6 | callsub utestbytesargs_0 7 | len 8 | return 9 | 10 | // utest_bytes_args 11 | utestbytesargs_0: 12 | store 2 13 | store 1 14 | store 0 15 | byte "" 16 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/lsig_utest_int.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub utestint_0 3 | return 4 | 5 | // utest_int 6 | utestint_0: 7 | int 0 8 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/lsig_utest_int_args.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | btoi 4 | arg 1 5 | arg 2 6 | callsub utestintargs_0 7 | return 8 | 9 | // utest_int_args 10 | utestintargs_0: 11 | store 2 12 | store 1 13 | store 0 14 | int 0 15 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/lsig_utest_noop.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | callsub utestnoop_0 3 | int 1337 4 | return 5 | 6 | // utest_noop 7 | utestnoop_0: 8 | int 0 9 | pop 10 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/blackbox/lsig_utest_noop_args.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | arg 0 3 | btoi 4 | arg 1 5 | arg 2 6 | callsub utestnoopargs_0 7 | int 1337 8 | return 9 | 10 | // utest_noop_args 11 | utestnoopargs_0: 12 | store 2 13 | store 1 14 | store 0 15 | int 0 16 | pop 17 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/pre_v6/sub_even.teal: -------------------------------------------------------------------------------- 1 | #pragma version 5 2 | int 1000 3 | callsub recursiveIsEven_0 4 | pop 5 | int 1001 6 | callsub recursiveIsEven_0 7 | return 8 | 9 | // recursiveIsEven 10 | recursiveIsEven_0: 11 | store 0 12 | load 0 13 | int 0 14 | == 15 | bnz recursiveIsEven_0_l4 16 | load 0 17 | int 1 18 | == 19 | bnz recursiveIsEven_0_l3 20 | load 0 21 | int 2 22 | - 23 | load 0 24 | swap 25 | callsub recursiveIsEven_0 26 | swap 27 | store 0 28 | b recursiveIsEven_0_l5 29 | recursiveIsEven_0_l3: 30 | int 0 31 | b recursiveIsEven_0_l5 32 | recursiveIsEven_0_l4: 33 | int 1 34 | recursiveIsEven_0_l5: 35 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/pre_v6/sub_fastfib.teal: -------------------------------------------------------------------------------- 1 | #pragma version 5 2 | int 3 3 | callsub fastfibonacci_0 4 | return 5 | 6 | // fast_fibonacci 7 | fastfibonacci_0: 8 | store 0 9 | int 0 10 | store 2 11 | int 1 12 | store 3 13 | int 1 14 | store 1 15 | fastfibonacci_0_l1: 16 | load 1 17 | load 0 18 | <= 19 | bz fastfibonacci_0_l3 20 | load 2 21 | load 3 22 | + 23 | store 3 24 | load 3 25 | load 2 26 | - 27 | store 2 28 | load 1 29 | int 1 30 | + 31 | store 1 32 | b fastfibonacci_0_l1 33 | fastfibonacci_0_l3: 34 | load 2 35 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/pre_v6/sub_logcat.teal: -------------------------------------------------------------------------------- 1 | #pragma version 5 2 | byte "hello" 3 | int 42 4 | callsub logcat_0 5 | byte "hello42" 6 | == 7 | assert 8 | int 1 9 | return 10 | 11 | // logcat 12 | logcat_0: 13 | store 1 14 | store 0 15 | load 0 16 | load 1 17 | itob 18 | concat 19 | store 2 20 | load 2 21 | log 22 | load 2 23 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/pre_v6/sub_slowfib.teal: -------------------------------------------------------------------------------- 1 | #pragma version 5 2 | int 3 3 | callsub slowfibonacci_0 4 | return 5 | 6 | // slow_fibonacci 7 | slowfibonacci_0: 8 | store 0 9 | load 0 10 | int 1 11 | <= 12 | bnz slowfibonacci_0_l2 13 | load 0 14 | int 2 15 | - 16 | load 0 17 | swap 18 | callsub slowfibonacci_0 19 | swap 20 | store 0 21 | load 0 22 | int 1 23 | - 24 | load 0 25 | swap 26 | callsub slowfibonacci_0 27 | swap 28 | store 0 29 | + 30 | b slowfibonacci_0_l3 31 | slowfibonacci_0_l2: 32 | load 0 33 | slowfibonacci_0_l3: 34 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/unchanged/empty_scratches.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | int 0 3 | store 6 4 | load 6 5 | int 0 6 | stores 7 | int 1 8 | store 6 9 | load 6 10 | byte "" 11 | stores 12 | int 2 13 | store 6 14 | load 6 15 | int 0 16 | stores 17 | int 3 18 | store 6 19 | load 6 20 | byte "" 21 | stores 22 | int 4 23 | store 6 24 | load 6 25 | int 0 26 | stores 27 | int 5 28 | store 6 29 | load 6 30 | byte "" 31 | stores 32 | int 42 33 | return -------------------------------------------------------------------------------- /tests/unit/teal/unchanged/sub_logcat_dynamic.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | byte "hello" 3 | store 0 // 0: "hello" 4 | int 0 5 | int 42 // >@0,42 6 | callsub logcatdynamic_0 // <> 7 | byte "hello42" // >"hello42" 8 | load 0 // >"hello42","hello42" 9 | == // >1 10 | assert // <> 11 | int 1 // >1 12 | return // < 13 | 14 | // logcat_dynamic 15 | logcatdynamic_0: // >@0,42 16 | store 2 // 2: 42 17 | store 1 // 1: @0 18 | load 1 19 | load 1 // >@0,@0 20 | loads // >@0,"hello" 21 | load 2 // >@0,"hello",42 22 | itob // >@0,"hello","42" 23 | concat // >@0,"hello42" 24 | stores // 0: "hello42" 25 | load 1 // >@0 26 | loads // >"hello42" 27 | log 28 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/unchanged/sub_mixed.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | int 42 // >42 3 | byte "x" // >42,"x" 4 | int 0 // >42,"x",0 5 | callsub mixedannotations_0 // >42 6 | return // <> 7 | 8 | // mixed_annotations 9 | mixedannotations_0: // >42,"x",0 10 | store 3 // 3:0 11 | store 2 // 2:"x" 12 | store 1 // 1:42 13 | load 3 // >0 14 | load 1 // >0,42 15 | stores // 0:42 16 | load 2 // >"x" 17 | byte "=" // >"x","=" 18 | concat // >"x=" 19 | load 1 // >"x=",42 20 | itob // >"x=","42" 21 | concat // >"x=42" 22 | log // LOG 23 | load 1 // >42 24 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/unchanged/swapper.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | byte "hello" 3 | store 5 // 5: hello // x 4 | byte "goodbye" 5 | store 6 // 6: goodbye // y 6 | load 5 7 | load 6 8 | callsub cat_1 // <> 9 | int 5 10 | int 6 11 | callsub swap_0 // >5,6 12 | load 5 // >goodbye 13 | byte "goodbye" 14 | == 15 | assert // <> 16 | load 6 // >hello 17 | byte "hello" 18 | == 19 | assert // <> 20 | int 1000 // >1000 21 | return // <> 22 | 23 | // swap 24 | swap_0: 25 | store 1 // 1: 6 // @y 26 | store 0 // 0: 5 // @x 27 | load 0 // >5 28 | loads // >hello 29 | store 2 // 2: hello // z 30 | load 0 // >5 31 | load 1 // >5,6 32 | loads // >5,goodbye 33 | stores // 5: goodbye 34 | load 1 // >6 35 | load 2 // >6,hello 36 | stores // 6: hello 37 | retsub 38 | 39 | // cat 40 | cat_1: 41 | store 4 // 4: goodbye 42 | store 3 // 3: hello 43 | load 3 // >hello 44 | load 4 // >hello,goodbye 45 | concat // >hellogoodbye 46 | pop // > 47 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/unchanged/wilt_the_stilt.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | int 129 3 | store 0 // 0: @129 // pointer to wilt's address 4 | load 0 5 | int 100 6 | stores // 129: 100 // set wilt's value 7 | int 1 8 | store 0 // 0: @1 // pointer to kobe's address (compiler assigned) 9 | load 0 10 | int 81 11 | stores // 1: 81 // set kobe's value 12 | int 131 13 | store 0 // 0: @131 // pointer to dt's address 14 | load 0 15 | int 73 16 | stores // 131: 73 // set dt's value 17 | load 0 18 | loads 19 | int 73 // >73,73 20 | == // >1 21 | assert // <> 22 | load 0 23 | int 131 // >131,131 24 | == // >1 25 | assert // <> 26 | int 129 27 | store 0 // 0: @129 28 | load 0 29 | loads 30 | int 100 // >100,100 31 | == // >1 32 | assert // <> 33 | load 0 34 | int 129 // >129,129 35 | == // >1 36 | assert // <> 37 | int 100 38 | return -------------------------------------------------------------------------------- /tests/unit/teal/user_guide/user_guide_snippet_ABIReturnSubroutine.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | txna ApplicationArgs 1 3 | store 0 4 | load 0 5 | callsub abisum_0 6 | store 1 7 | byte 0x151f7c75 8 | load 1 9 | itob 10 | concat 11 | log 12 | int 1 13 | return 14 | 15 | // abi_sum 16 | abisum_0: 17 | store 2 18 | int 0 19 | store 3 20 | int 0 21 | store 4 22 | abisum_0_l1: 23 | load 4 24 | load 2 25 | int 0 26 | extract_uint16 27 | store 6 28 | load 6 29 | < 30 | bz abisum_0_l3 31 | load 2 32 | int 8 33 | load 4 34 | * 35 | int 2 36 | + 37 | extract_uint64 38 | store 5 39 | load 3 40 | load 5 41 | + 42 | store 3 43 | load 4 44 | int 1 45 | + 46 | store 4 47 | b abisum_0_l1 48 | abisum_0_l3: 49 | load 3 50 | retsub -------------------------------------------------------------------------------- /tests/unit/teal/user_guide/user_guide_snippet_dynamic_scratch_var.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | int 0 3 | store 1 4 | int 7 5 | store 0 6 | load 1 7 | load 1 8 | loads 9 | int 3 10 | + 11 | stores 12 | load 0 13 | int 10 14 | == 15 | assert 16 | int 1 17 | return -------------------------------------------------------------------------------- /tests/unit/teal/user_guide/user_guide_snippet_recursiveIsEven.teal: -------------------------------------------------------------------------------- 1 | #pragma version 6 2 | int 15 3 | callsub recursiveIsEven_0 4 | return 5 | 6 | // recursiveIsEven 7 | recursiveIsEven_0: 8 | store 0 9 | load 0 10 | int 0 11 | == 12 | bnz recursiveIsEven_0_l4 13 | load 0 14 | int 1 15 | == 16 | bnz recursiveIsEven_0_l3 17 | load 0 18 | int 2 19 | - 20 | load 0 21 | swap 22 | callsub recursiveIsEven_0 23 | swap 24 | store 0 25 | b recursiveIsEven_0_l5 26 | recursiveIsEven_0_l3: 27 | int 0 28 | b recursiveIsEven_0_l5 29 | recursiveIsEven_0_l4: 30 | int 1 31 | recursiveIsEven_0_l5: 32 | retsub --------------------------------------------------------------------------------