C3N
Last month saw the first smart contract deployed on Tezos by a government authority (French cybercrime unit)
Below is the Michelson of the contract (see it on better call dev):
1
{
2
{ { DUP ; CAR ; DIP { CDR } } ; { DUP ; CAR @newadmin ; DIP { CDR } } ; DIP { { DUP ; CAR @oldhash ; DIP { CDR @newhash } } } ; DIP { DIP { DIP { { DUP ; CAR @storedadmin ; DIP { CDR @storedhash } } } } } } ;
3
SWAP ;
4
{ DIP { DIP { DIP { SWAP } } } } ;
5
{ DIP { DIP { SWAP } } } ;
6
DIP { SWAP } ;
7
{ DIP { DIP { DIP { SWAP } } } } ;
8
{ DIP { DIP { SWAP ; DUP ; DIP { SWAP } } } } ;
9
{
10
{ COMPARE ; EQ } ;
11
IF { }
12
$ELSE { { UNIT ; FAILWITH } }
13
} ;
14
SENDER ;
15
SWAP ;
16
{ DIP { DIP { PUSH @admin bool false } } } ;
17
ITER { DIP { DUP } ; { COMPARE ; EQ } ; SWAP ; DIP { OR @admin } } ;
18
DROP ;
19
{
20
IF { }
21
$ELSE { { UNIT ; FAILWITH } }
22
} ;
23
IF_NONE { }
24
$ELSE { DIP { DROP } } ;
25
NIL operation ;
26
{ DIP { PAIR %admin %hash } ; PAIR %op }
27
}
Copied!
For those who are not fluent in stack machine, here is the transcription to Archetype:
1
archetype c3n
2
3
asset admins {
4
addr : address;
5
}
6
variable hash : string = "..." (* to set to initial value *)
7
action register (newadmins : admins collection option,
8
oldhash : string,
9
newhash : string) {
10
require {
11
r1 : oldhash = hash;
12
r2 : admins.contains(caller);
13
}
14
effect {
15
hash := newhash;
16
let some newa = newadmins in
17
admins := newa
18
otherwise
19
()
20
}
21
}
Copied!
Quite straightforward, isn’t it?
Last modified 1mo ago
Export as PDF
Copy link
Edit on GitHub