Quantum Computing on a Commodore 64 in 200 Lines of BASIC
In an age where companies are selling two-qubit quantum computers for a sum of money that would make your wallet recoil in horror, here we are, stepping off ...
While writing a new programming language, it is often useful to write some real use-cases to test the syntax, the language expressiveness and the code cleanness comparing to other languages.
So I did for yallo-lang, a (still experimental) smart contract language for Tezos; for starting I chose a contract already existing on ethereum, king_of_ether (that’s right guys, a smart-ponzi).
Our minimal implementation is very simple: a single endpoint which allow the caller to become the king if he sends the contract balance * 2; the old king is then dismissed, but he receives in exchange twice the amount he sent to become a king. And so on.
We start with the yallo contract:
contract KingOfTezos {
field theKing: address;
field currentPrice: mutez;
entry beTheKing() {
assert (Tezos.amount() >= this.currentPrice);
let op = Tezos.transfer (this.theKing, this.currentPrice);
this.theKing = Tezos.sender();
this.currentPrice = Tezos.amount() * 2n;
[ op ]
}
}
We transpile it to ligo:
yallo.exe compile king_of_tezos.yallo -target ligo
At that is the result:
type storage = { theKing: address; currentPrice: tez; }
type action = | BeTheKing of unit
let beTheKing (s: storage) =
let ovverraidable = if ((Tezos.amount) >= (s.currentPrice)) then () else failwith "Assertion" in
let op: operation = Tezos.transaction (unit) (s.currentPrice) (match (Tezos.get_contract_opt s.theKing : unit contract option) with| None -> (failwith "invalid contract": unit contract) | Some(c) -> c) in
let s = { s with theKing=Tezos.sender } in
let s = { s with currentPrice=(Tezos.amount) * (2n) } in
(([op]: operation list), (s: storage))
let main(a, s: action * storage): (operation list * storage) =
match a with | BeTheKing (arg) -> beTheKing(s)
Then ligo compiler does the rest, and we got king.tz:
{ parameter unit ;
storage (pair (mutez %currentPrice) (address %theKing)) ;
code { DUP ;
CDR ;
DUP ;
CAR ;
AMOUNT ;
COMPARE ;
GE ;
IF { PUSH unit Unit } { PUSH string "Assertion" ; FAILWITH } ;
DIG 1 ;
DUP ;
DUG 2 ;
CDR ;
CONTRACT unit ;
IF_NONE
{ PUSH string "invalid contract" ; FAILWITH }
{ DUP ; DIP { DROP } } ;
DIG 2 ;
DUP ;
DUG 3 ;
CAR ;
UNIT ;
TRANSFER_TOKENS ;
DIG 2 ;
DUP ;
DUG 3 ;
CAR ;
SENDER ;
SWAP ;
PAIR ;
DUP ;
PUSH nat 2 ;
AMOUNT ;
MUL ;
SWAP ;
CDR ;
SWAP ;
PAIR ;
DUP ;
NIL operation ;
DIG 4 ;
DUP ;
DUG 5 ;
CONS ;
PAIR ;
DIP { DROP 6 } } }
We then try it on carthagenet:
tezos-client originate contract kot transferring 1 from my_account running king.tz --init "(Pair 2000000 \"tz1VnNQMNQ796WrY2TyWDaFpwsRTP41mKXWH\")" --force --burn-cap 0.555
tezos-client transfer 1 from my_account2 to kot --arg "Unit" --burn-cap 0.004
Obviusly the simulation fails with: script reached FAILWITH instruction
tezos-client transfer 2 from my_account to kot --arg "Unit" --burn-cap 0.004
And now we are the king of tezos. We can send further transactions doubling the amount every time.
You can inspect the contract and few beTheKing call transactions on bettercalldev.
In an age where companies are selling two-qubit quantum computers for a sum of money that would make your wallet recoil in horror, here we are, stepping off ...
This June I emerged as one of the top participants with 9 bounties collected (alongside another exceptional contributor) in the #UnitaryHack Hackathon, hoste...
A few days ago I came across a yt video discussing the ESA Copernicus program, a European initiative for monitoring earth via a satellite constellation. This...
Qiskit is a python SDK developed by IBM and allows everyone to create quantum circuits, simulate them locally and also run the quantum circuit on a real quan...
As someone noticed from the previous post, last weeks I started to write a new programming language for Tezos smart contracts. This project was initially int...
While writing a new programming language, it is often useful to write some real use-cases to test the syntax, the language expressiveness and the code cleann...
Documentation is like sex: when it is good, it is very, very good; and when it is bad, it is better than nothing
This is my new blog, based on jekyll. I’ll soon import old posts from my old blog.
Contractvm is a general-purpose decentralized framework based on blockchain. The framework allows to implement arbitrary decentralized applications in an eas...
Most of bitcoin dice software use a system to prove the fair play of the server for each bet. Most of them implement this mechanism using two seed (server se...
In the aim to merge two of my server on digitalocean, today I tried to write a mod_rewrite rule to redirect a secondary domain to a subfolder. After one hour...
MineML is a multithread CPU based bitcoin miner written in F#. At the moment it’s a slow implementation, but the class structure offers the possibility to im...