Skip to main content

Version 1.5.2

· 2 min read
Benoit Rognier
Guillaume Duhamel

We are pleased to announce the initial beta release of the Michelson decompiler. The purpose is to decompile any contract to Archetype in order to know what a contract does.

Example

Consider the following mainnet contract KT1Ly9NLfDb2DESnysqfQpAaB3r9x497TZoY whose code is reproduced below:

{
parameter (or (nat %divide) (or (unit %double) (nat %replace)));
storage (pair (int %nbVotes) (nat %storedValue));
code { DUP ;
CDR ;
SWAP ;
CAR ;
IF_LEFT
{ DUP ;
PUSH nat 5 ;
COMPARE ;
LT ;
IF {} { PUSH string "WrongCondition: params.divisor > 5" ; FAILWITH } ;
SWAP ;
DUP ;
CAR ;
SWAP ;
CDR ;
DIG 2 ;
SWAP ;
EDIV ;
IF_NONE { PUSH int 26 ; FAILWITH } { CAR } ;
SWAP ;
PAIR }
{ IF_LEFT
{ DROP ; DUP ; CAR ; SWAP ; CDR ; PUSH nat 2 ; MUL ; SWAP ; PAIR }
{ SWAP ; DUP ; CDR ; SWAP ; CAR ; PUSH int 1 ; ADD ; PAIR ; CAR ; PAIR } } ;
NIL operation ;
PAIR }
}

Store te code in avv.tzfile for example and run the following command:

$ archetype -d avv.tz

Use additional -ij option when dealing with json Michelson.

It generates the following Archetype code:

archetype avv(
nbVotes : int,
storedValue : nat
)

entry divide (arg : nat) {
do_require ((5 < arg), "WrongCondition: params.divisor > 5");
match storedValue /% arg with
| some (x76, x77) -> (storedValue := x76)
| none -> (fail (26i))
end
}

entry double () {
storedValue := 2 * storedValue
}

entry replace (arg : nat) {
storedValue := arg;
nbVotes := 1i + nbVotes
}

Limits

danger

The decompiler is still in beta. In this version, we do not garantee that the decompiled version is equivalent to the Michelson contract.

This is Work Under Progress and some contracts may not decompile yet. Unsupported instructions are for example:

  • EXEC
  • APPLY
  • CREATE_CONTRACT
  • TICKET
  • MAP