Image for post
Image for post

Algorand Smart Contract Layer1 (ASC1) and Oracles

Overview

General Logic

ASC Creation

ASC1 Transactions

Lease String

Oracles

Example: Oracle Using ed25519verify

Code

// Parameters:
// - TMPL_ADDRA: Address beting for Team A.
// - TMPL_ADDRB: Address beting for Team B.
// - TMPL_ADDR_ORACLE: Oracle Address.
// - TMPL_FEE: maximum fee used by the limit order transaction.
txn TypeEnum
int 1 // Payment (either Algos-out in trade or Algos redeemed at timeout)
==
global GroupSize
int 1
==
&&
// if arg 0 == 0 then send to TMPL_ADDRA
arg 0
byte base64 MA==
==
txn CloseRemainderTo
addr TMPL_ADDRA
==
&&
txn Receiver
addr TMPL_ADDRA
==
&&
// if arg 0 == 1 then send to TMPL_ADDRB
arg 0
byte base64 MQ==
==
txn CloseRemainderTo
addr TMPL_ADDRB
==
&&
txn Receiver
addr TMPL_ADDRB
==
&&
||
// global verifications
&&
txn Fee
int TMPL_FEE
<=
&&
// verify oracle signature
arg 0
arg 1
addr TMPL_ADDR_ORACLE
ed25519verify
&&

Logic

tx type == Pay && GroupSize == 1 &&
((data == 0 && to == TMPL_ADDRA && close == TMPL_ADDRA) ||
(data == 1 && to == TMPL_ADDRB && close == TMPL_ADDRB)) &&
ed25519verify(data, signature, oracle TMPL_ADDR_ORACLE) &&
ok fee

Oracle Keys

$ ./algokey generate -f testkey.key | grep “Public key”Public key: SVDICE2QVOMQPYCYRJGRBOZPLYGF5DQOK3FFHL26FUOBQLWBKDH3EAQS3U

Compilation

TMPL_ADDRA:
BKJX2U52PKL27XS42VO4SJW5BBFBYDCN7NYAW6BUEKF7EBYX5XV5CKAPT4
TMPL_ADDRB:
36WZVNA6YA77V2MGGLJBT2YQG3RQVX6UWJ3P6E7FWNAV4IGMK3ZVVNBLVQ
TMPL_ADDR_ORACLE:
SVDICE2QVOMQPYCYRJGRBOZPLYGF5DQOK3FFHL26FUOBQLWBKDH3EAQS3U
TMPL_FEE:
10000
$ ./goal clerk compile oracle.teal
oracle.teal:
JDYOTGQ6D2CLH4EBOJLUNV5TYJS3DZSJHNQV6ESEEHFF76I6OUI53JR7H4

Signing to Verify with ed25519verify

Case 1: ADDRA Wins

$ ~/go/bin/dsign testkey.key ~/node/oracle.teal msg LjbN+UgzmYG6vWKQuOkJKk69DBrJFY7IM0yblgeiZl5OOtZPlAf/ujTVl4FTAA5oa0/1npNtNDHvhxmY4pb/BA==
$ ./goal clerk tealsign --keyfile oracle.key --contract-addr JDYOTGQ6D2CLH4EBOJLUNV5TYJS3DZSJHNQV6ESEEHFF76I6OUI53JR7H4 --data-b64 MA==
$ ./goal clerk send -a 0 --from-program oracle.teal -t BKJX2U52PKL27XS42VO4SJW5BBFBYDCN7NYAW6BUEKF7EBYX5XV5CKAPT4 -c BKJX2U52PKL27XS42VO4SJW5BBFBYDCN7NYAW6BUEKF7EBYX5XV5CKAPT4 --fee 1000 -d testnet --argb64 MA== --argb64 LjbN+UgzmYG6vWKQuOkJKk69DBrJFY7IM0yblgeiZl5OOtZPlAf/ujTVl4FTAA5oa0/1npNtNDHvhxmY4pb/BA==Sent 0 MicroAlgos from account JDYOTGQ6D2CLH4EBOJLUNV5TYJS3DZSJHNQV6ESEEHFF76I6OUI53JR7H4 to address BKJX2U52PKL27XS42VO4SJW5BBFBYDCN7NYAW6BUEKF7EBYX5XV5CKAPT4, 
transaction ID: XWZLK6YBQ4H6BZUSONDOE5A66B4MASVBGVTL6B4HNWMBYQ7GHTBA. Fee set to 1000
Transaction XWZLK6YBQ4H6BZUSONDOE5A66B4MASVBGVTL6B4HNWMBYQ7GHTBA committed in round 4451591

Case 2: ADDRB Wins

$ ~/go/bin/dsign testkey.key ~/node/oracle.teal msg 
DJ0FtmIaLCksr5WhPczcHIwn9ye4CGHFPn64z38ChorZ6r0Dvj6z1n2bV9gIMUe+UrN5lzNDYK7u3Cxh1SiQBg==
$ ./goal clerk tealsign --keyfile oracle.key --contract-addr JDYOTGQ6D2CLH4EBOJLUNV5TYJS3DZSJHNQV6ESEEHFF76I6OUI53JR7H4 --data-b64 MQ==
$ ./goal clerk send -a 0 --from-program oracle.teal -t 36WZVNA6YA77V2MGGLJBT2YQG3RQVX6UWJ3P6E7FWNAV4IGMK3ZVVNBLVQ -c 36WZVNA6YA77V2MGGLJBT2YQG3RQVX6UWJ3P6E7FWNAV4IGMK3ZVVNBLVQ --fee 1000 -d testnet --argb64 MQ== --argb64 DJ0FtmIaLCksr5WhPczcHIwn9ye4CGHFPn64z38ChorZ6r0Dvj6z1n2bV9gIMUe+UrN5lzNDYK7u3Cxh1SiQBg==Sent 0 MicroAlgos from account JDYOTGQ6D2CLH4EBOJLUNV5TYJS3DZSJHNQV6ESEEHFF76I6OUI53JR7H4 to address 36WZVNA6YA77V2MGGLJBT2YQG3RQVX6UWJ3P6E7FWNAV4IGMK3ZVVNBLVQ, transaction ID: 2SKTS2SAQ2QTDV3PR45WV4NO6TQHT7S2BR73W6T3OJJHT7LVXKPQ. Fee set to 1000
Transaction 2SKTS2SAQ2QTDV3PR45WV4NO6TQHT7S2BR73W6T3OJJHT7LVXKPQ still pending as of round 4451877
Transaction 2SKTS2SAQ2QTDV3PR45WV4NO6TQHT7S2BR73W6T3OJJHT7LVXKPQ committed in round 4451879

Leading with Technological Innovation

Coding next blockchain technologies at RandLabs.io

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store