Skip to content

Global constants: add `compile constant` sub-command

E. Rivas requested to merge er433/constants/compile-constants into dev

This MR adds a new sub-command compile constant, that compiles a constant:

$ ligo compile constant cameligo "fun (x : int) -> if x > 3 then x * 2 else x * String.length \"fja\" + 1"
Michelson consant as JSON string:
"{ PUSH int 3 ;\n  SWAP ;\n  DUP ;\n  DUG 2 ;\n  COMPARE ;\n  GT ;\n  IF { PUSH int 2 ; SWAP ; MUL }\n     { PUSH int 1 ; PUSH string \"fja\" ; SIZE ; DIG 2 ; MUL ; ADD } }"
This string can be passed in `--constants` argument when compiling a contract.

Remember to register it in the network, e.g.:
> tezos-client register global constant "{ PUSH int 3 ;
  SWAP ;
  DUP ;
  DUG 2 ;
  COMPARE ;
  GT ;
  IF { PUSH int 2 ; SWAP ; MUL }
     { PUSH int 1 ; PUSH string \"fja\" ; SIZE ; DIG 2 ; MUL ; ADD } }" from bootstrap1

Constant hash:
expruVivewmRtHKQn7h986tVPUzB65Z8w7QM1WP1X6DxcVWNs85USK

It is expected to be used by LIGO users as an easier alternative to compiling the expression and then calculating the constant hash by hand.

Side-effect: we enable a Michelson opt. to turn PUSH constant ; SWAP ; EXEC into constant (see discussion below with Tom)

  • has a changelog entry
Edited by E. Rivas

Merge request reports