Coder Social home page Coder Social logo

juliateal's Introduction

juliaTEAL

Translate julia -> TEAL as follows:

  1. Translate julia to ARM assembly
  2. Translate ARM assembly to TEAL
  3. Check TEAL rules (e.g. no backward branching) - Some checks can be performed on julia directly (before step 1.

Example 1

Consider the "Simple PyTeal Example" (https://developer.algorand.org/docs/features/asc1/teal/pyteal/)

The following TEAL code...

txn TypeEnum
int 1
==
txn Receiver
addr ZZAF5ARA4MEC5PVDOP64JM5O5MQST63Q2KOY2FLYFLXXD3PFSNJJBYAFZM
==
&&
txn CloseRemainderTo
global ZeroAddress
==
&&
txn AssetCloseTo
global ZeroAddress
==
&&

...could be translated from the following julia code

function main(transaction, args)
    
    # checks
    transaction.TypeEnum ≠ 1 && return false
    transaction.Receiver ≠ "ZZAF5ARA4MEC5PVDOP64JM5O5MQST63Q2KOY2FLYFLXXD3PFSNJJBYAFZM" && return false
    transaction.CloseRemainderTo ≠ ZeroAddress && return false
    transaction.AssetCloseTo ≠ ZeroAddress && return false

    # all good
    return true
end

or from the following

function main(transaction, args)
    typeEnumCheck = transaction.TypeEnum ≠ 1
    receiverCheck = transaction.Receiver ≠ "ZZAF5ARA4MEC5PVDOP64JM5O5MQST63Q2KOY2FLYFLXXD3PFSNJJBYAFZM"
    closeRemainderToCheck = transaction.CloseRemainderTo ≠ ZeroAddress
    assetCloseToCheck = transaction.AssetCloseTo ≠ ZeroAddress

    return typeEnumCheck && receiverCheck && closeRemainderToCheck && assetCloseToCheck
end

or in many other ways according to julia.

Example 2

Consider the example provided at the bottom of https://developer.algorand.org/docs/features/asc1/teal/

The following TEAL code...

txn CloseRemainderTo
addr SOEI4UA72A7ZL5P25GNISSVWW724YABSGZ7GHW5ERV4QKK2XSXLXGXPG5Y
==
txn Receiver
addr SOEI4UA72A7ZL5P25GNISSVWW724YABSGZ7GHW5ERV4QKK2XSXLXGXPG5Y
==
&&
arg 0
len
int 46
==
&&
arg 0
sha256
byte base64 QzYhq9JlYbn2QdOMrhyxVlNtNjeyvyJc/I8d8VAGfGc=
==
&&
txn CloseRemainderTo
addr RFGEHKTFSLPIEGZYNVYALM6J4LJX4RPWERDWYS2PFKNVDWW3NG7MECQTJY
==
txn Receiver
addr RFGEHKTFSLPIEGZYNVYALM6J4LJX4RPWERDWYS2PFKNVDWW3NG7MECQTJY
==
&&
txn FirstValid
int 67240
>
&&
||
txn Fee
int 1000000
<
txn RekeyTo
global ZeroAddress
==
&&
&&

...could be translated from the following julia code

function addr2_and_secret(transaction, args)
    # check transaction properties
    transaction.CloseRemainderTo ≠ "SOEI4UA72A7ZL5P25GNISSVWW724YABSGZ7GHW5ERV4QKK2XSXLXGXPG5Y" && return false
    transaction.Receiver ≠ "SOEI4UA72A7ZL5P25GNISSVWW724YABSGZ7GHW5ERV4QKK2XSXLXGXPG5Y" && return false

    # check provided secret
    lenght(args[0]) ≠ 46 && return false
    sha256(args[0]) ≠ "QzYhq9JlYbn2QdOMrhyxVlNtNjeyvyJc/I8d8VAGfGc=" && return false

    # all good
    return true
end

function addr1_and_timeout(transaction, args)
    # check transaction properties
    transaction.CloseRemainderTo ≠ "RFGEHKTFSLPIEGZYNVYALM6J4LJX4RPWERDWYS2PFKNVDWW3NG7MECQTJY" && return false
    transaction.Receiver ≠ "RFGEHKTFSLPIEGZYNVYALM6J4LJX4RPWERDWYS2PFKNVDWW3NG7MECQTJY" && return false

    # check timeout
    return 67240 < transaction.FirstValid
end

function main(transaction, args)

    !addr2_and_secret(transaction, args) && return false
    !addr1_and_timeout(transaction, args) && return false

    # check fee
    1000000 < transaction.Fee && return false

    # check ReKey
    transaction.RekeyTo ≠ ZeroAddress && return false

    # all good
    return true
end

juliateal's People

Contributors

1m1-github avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.