Optz is an optimizer of Michelson programs, the base language for Tezos smart contract. It takes a Michelson code as input and then returns a smaller and more efficient equivalent code.
Optimization of Michelson opcode sequences The optimization consists of 2 parts: rule-based transformation and optimal stack manipulation search by A* algorithm.
Rule based code transformation Dozens of rewriting rules replace opcodes with better ones, such as:
PAIR; CDR => DROP DIP n { a }; DIP n { b } => DIP n { a; b } SWAP; op => op // when op is a commutative binary operator NOT; IF { a } { b } => IF { b } { a } Search for the optimal stack manipulation sequences After the rule-based transformation, A* algorithm finds the most optimal sequence of stack manipulation opcodes such as DROP, SWAP, DIG, DUG, DIP, DUP, CAR, CDR, PAIR, UNPAIR, and the push only opcodes like PUSH and EMPTY_SET.
[続きを読む]