- #1
fluidistic
Gold Member
- 3,945
- 263
I am sinking deeply into the cryptocurrencies world. There is a website that shows a "smart contract", a piece of code that is supposed to provide rewards for "staking" a particular token, where the rewards is two different tokens (I am not even sure in which proportion). Usually people who wants to join the "staking pool" have to agree/sign the contract, and they are free to look up at the code.
If there is some problem with the display, the original code can be found there: https://algoexplorer.io/application/233725850.
I have a very hard time to understand even the slightest thing out of this code (I know some Python, a little bit of Fortran), I am not even sure whether this corresponds to a programming language (doesn't look like entirely as assembly, isn't it?). Any pointer on how to understand the code is welcome.
Code:
#pragma version 3
int 0
txn ApplicationID
==
bz label1
byte base64 Qw==
txn Sender
app_global_put
byte base64 R1Q=
global LatestTimestamp
app_global_put
byte base64 R0E=
int 0
app_global_put
byte base64 R1NT
int 0
app_global_put
bytec 4
int 0
app_global_put
bytec 5
int 0
app_global_put
int 1
return
label1:
int 5
txn OnCompletion
==
bz label2
int 0
return
label2:
int 4
txn OnCompletion
==
bz label3
byte base64 Qw==
app_global_get
txn Sender
==
txn NumAppArgs
int 4
==
&&
assert
bytec 6
txna ApplicationArgs 0
app_global_put
bytec 7
txna ApplicationArgs 1
btoi
app_global_put
bytec 8
txna ApplicationArgs 2
btoi
app_global_put
bytec 9
txna ApplicationArgs 3
btoi
app_global_put
int 1
return
label3:
intc 4
txn OnCompletion
==
bnz label4
int 0
txn NumAppArgs
==
bz label5
int 1
txn OnCompletion
==
assert
int 1
return
label5:
txna ApplicationArgs 0
bytec 10
==
bnz label6
txna ApplicationArgs 0
bytec 11
==
bnz label7
txna ApplicationArgs 0
bytec 12
==
bnz label8
txna ApplicationArgs 0
bytec 13
==
bnz label9
txna ApplicationArgs 0
bytec 14
==
bnz label10
txna ApplicationArgs 0
bytec 15
==
bnz label11
txna ApplicationArgs 0
bytec 16
==
bnz label12
int 0
return
label10:
byte base64 Qw==
app_global_get
txn Sender
==
assert
int 1
bytec 17
app_global_get_ex
assert
intc 4
bytec 18
app_global_get_ex
assert
*
intc 5
/
store 1
bytec 4
bytec 4
app_global_get
load 1
intc 6
intc 4
bytec 19
app_global_get_ex
assert
-
*
intc 6
/
+
app_global_put
int 1
return
label11:
gtxn 0 ApplicationID
bytec 9
app_global_get
==
assert
byte base64 R0E=
app_global_get
store 1
global LatestTimestamp
byte base64 R1Q=
app_global_get
-
intc 7
/
store 8
load 8
load 1
*
byte base64 R1NT
app_global_get
+
store 2
int 0
bytec 20
app_local_get
store 1
global LatestTimestamp
int 0
bytec 21
app_local_get
-
intc 7
/
store 8
load 8
load 1
*
int 0
bytec 22
app_local_get
+
store 3
bytec 4
app_global_get
load 2
load 3
/
/
store 6
load 6
gtxn 3 AssetAmount
>=
assert
bytec 4
bytec 4
app_global_get
gtxn 3 AssetAmount
-
app_global_put
int 1
return
label6:
gtxn 0 ApplicationID
bytec 9
app_global_get
==
assert
byte base64 R0E=
app_global_get
store 1
global LatestTimestamp
byte base64 R1Q=
app_global_get
-
intc 7
/
store 8
load 8
load 1
*
byte base64 R1NT
app_global_get
+
store 2
byte base64 R1NT
load 2
app_global_put
byte base64 R0E=
app_global_get
gtxn 2 AssetAmount
+
store 3
byte base64 R0E=
load 3
app_global_put
load 8
int 1
>=
bz label13
byte base64 R1Q=
byte base64 R1Q=
app_global_get
load 8
intc 7
*
+
app_global_put
label13:
int 0
txn ApplicationID
bytec 20
app_local_get_ex
bz label14
int 0
bytec 20
app_local_get
store 1
global LatestTimestamp
int 0
bytec 21
app_local_get
-
intc 7
/
store 8
load 8
load 1
*
int 0
bytec 22
app_local_get
+
store 2
int 0
bytec 22
load 2
app_local_put
int 0
bytec 20
app_local_get
gtxn 2 AssetAmount
+
store 3
int 0
bytec 20
load 3
app_local_put
load 8
int 1
>=
bz label15
int 0
bytec 21
int 0
bytec 21
app_local_get
load 8
intc 7
*
+
app_local_put
label15:
int 1
return
label7:
gtxn 0 ApplicationID
bytec 9
app_global_get
==
assert
byte base64 R0E=
app_global_get
store 1
global LatestTimestamp
byte base64 R1Q=
app_global_get
-
intc 7
/
store 8
load 8
load 1
*
byte base64 R1NT
app_global_get
+
store 2
byte base64 R1NT
load 2
app_global_put
byte base64 R0E=
app_global_get
gtxn 2 AssetAmount
-
store 3
byte base64 R0E=
load 3
app_global_put
load 8
int 1
>=
bz label16
byte base64 R1Q=
byte base64 R1Q=
app_global_get
load 8
intc 7
*
+
app_global_put
label16:
int 0
bytec 20
app_local_get
store 1
global LatestTimestamp
int 0
bytec 21
app_local_get
-
intc 7
/
store 8
load 8
load 1
*
int 0
bytec 22
app_local_get
+
store 2
int 0
bytec 22
load 2
app_local_put
int 0
bytec 20
app_local_get
gtxn 2 AssetAmount
-
store 3
int 0
bytec 20
load 3
app_local_put
load 8
int 1
>=
bz label17
int 0
bytec 21
int 0
bytec 21
app_local_get
load 8
intc 7
*
+
app_local_put
label17:
int 1
return
label9:
global GroupSize
int 5
==
bytec 23
bytec 5
app_global_get
app_global_put
byte base64 Qw==
app_global_get
txn Sender
==
&&
assert
int 1
balance
int 1
min_balance
-
int 1
byte base64 R0E=
app_global_get_ex
assert
bytec 5
app_global_get
+
-
intc 8
*
intc 6
/
store 1
bytec 5
bytec 5
app_global_get
load 1
+
app_global_put
int 1
return
label8:
gtxn 0 ApplicationID
bytec 9
app_global_get
==
assert
byte base64 R0E=
app_global_get
store 1
global LatestTimestamp
byte base64 R1Q=
app_global_get
-
intc 7
/
store 8
load 8
load 1
*
byte base64 R1NT
app_global_get
+
store 2
byte base64 R1NT
load 2
app_global_put
load 8
int 1
>=
bz label18
byte base64 R1Q=
byte base64 R1Q=
app_global_get
load 8
intc 7
*
+
app_global_put
label18:
int 0
bytec 20
app_local_get
store 1
global LatestTimestamp
int 0
bytec 21
app_local_get
-
intc 7
/
store 8
load 8
load 1
*
int 0
bytec 22
app_local_get
+
store 2
int 0
bytec 22
load 2
app_local_put
bytec 5
app_global_get
byte base64 R1NT
app_global_get
int 0
bytec 22
app_local_get
/
/
store 4
load 4
gtxn 4 Amount
>=
assert
bytec 5
bytec 5
app_global_get
gtxn 4 Amount
-
app_global_put
byte base64 R1NT
byte base64 R1NT
app_global_get
int 0
bytec 22
app_local_get
-
app_global_put
int 0
bytec 22
int 0
app_local_put
load 8
int 1
>=
bz label19
int 0
bytec 21
int 0
bytec 21
app_local_get
load 8
intc 7
*
+
app_local_put
label19:
int 1
return
label14:
int 0
bytec 20
gtxn 2 AssetAmount
app_local_put
int 0
bytec 21
byte base64 R1Q=
app_global_get
app_local_put
int 0
bytec 22
int 0
app_local_put
int 1
return
label12:
byte base64 Qw==
app_global_get
txn Sender
==
assert
byte base64 Qw==
txna ApplicationArgs 1
app_global_put
int 1
return
label4:
int 1
return
If there is some problem with the display, the original code can be found there: https://algoexplorer.io/application/233725850.
I have a very hard time to understand even the slightest thing out of this code (I know some Python, a little bit of Fortran), I am not even sure whether this corresponds to a programming language (doesn't look like entirely as assembly, isn't it?). Any pointer on how to understand the code is welcome.