Skip to content

Instantly share code, notes, and snippets.

@yoshihiro503
Created January 10, 2020 09:16
Show Gist options
  • Save yoshihiro503/9372153b94b8c133dc81314182cc85c4 to your computer and use it in GitHub Desktop.
Save yoshihiro503/9372153b94b8c133dc81314182cc85c4 to your computer and use it in GitHub Desktop.
An example scaml code to fail `tezos-client typecheck script`
open SCaml
type parameter = nat * unit contract * unit
type storage = nat
let main (param: parameter) (storage: storage) =
let (counter, contr, sigs) = param in
(* let counter = counter in *) (* If this line is available then the typecheck will be passed. *)
if counter <> Nat 1 then failwith "0" else
let op = Operation.transfer_tokens () (Tz 1.) contr in
([op], counter)
@yoshihiro503
Copy link
Author

The tz code by scaml typeerror.ml.

parameter (pair nat (pair (contract unit) unit)) ;
storage nat ;
code { { /* defs */ } ;
       { /* entry point init */ DUP ; CDR ; DIP { CAR } } ;
       { /* entry point */
         { /* entry main_1152 */
           { /* __v_1175 */
             { /* = __x_1170, = __param_1184, = param_1153, = __v_1185, = __param_1164 */
               { /* var global_param_1163 */ DIG 1 ; DUP ; DUG 2 } } } ;
           { /* __r_1176 */ { /* var __v_1175 */ DUP } ; CDR } ;
           { /* __counter_1172 */
             { /* = counter_1155, = __l_1177 */ { /* var __v_1175 */ DIG 1 ; DUP ; DUG 2 } ; CAR } } ;
           LAMBDA
             (pair nat (contract unit))
             (lambda unit (pair (list operation) nat))
             { { /* fvar __counter_1172 */ DUP ; DIP { CAR } ; CDR } ;
               LAMBDA
                 (pair (contract unit) (pair nat unit))
                 (pair (list operation) nat)
                 { { /* fvar __contr_1173 */ DUP ; DIP { CAR } ; CDR } ;
                   { /* fvar __counter_1172 */ DUP ; DIP { CAR } ; CDR } ;
                   PUSH nat 1 ;
                   { /* var __counter_1172 */ DIG 2 ; DUP ; DUG 3 } ;
                   COMPARE ;
                   NEQ ;
                   IF { PUSH string "0" ; FAILWITH }
                      { { /* var __counter_1172 */ DIG 1 ; DUP ; DUG 2 } ;
                        NIL operation ;
                        { /* = __op_1168, = op_1158, = __v_1169, = __x_1166 */
                          { /* var __contr_1173 */ DIG 4 ; DUP ; DUG 5 } ;
                          PUSH mutez 1000000 ;
                          PUSH unit Unit ;
                          TRANSFER_TOKENS } ;
                        CONS ;
                        PAIR } ;
                   { /* lambda clean up */ DIP { DROP 3 } } } ;
               { /* partial app __contr_1173 */
                 { /* var __contr_1173 */ DIG 1 ; DUP ; DUG 2 } ;
                 APPLY } ;
               { /* partial app __counter_1172 */
                 { /* var __counter_1172 */ DIG 2 ; DUP ; DUG 3 } ;
                 APPLY } ;
               { /* lambda clean up */ DIP { DROP 2 } } } ;
           { /* partial app __counter_1172 */
             { /* var __counter_1172 */ DIG 1 ; DUP ; DUG 2 } ;
             APPLY } ;
           { /* clean __counter_1172 */ DIP { DROP } } ;
           { /* = contr_1156, = __l_1179 */ { /* var __r_1176 */ DIG 1 ; DUP ; DUG 2 } ; CAR } ;
           EXEC ;
           { /* = sigs_1157, = __r_1178 */ { /* var __r_1176 */ DIG 1 ; DUP ; DUG 2 } ; CDR } ;
           EXEC ;
           { /* clean __r_1176 */ DIP { DROP } } ;
           { /* clean __v_1175 */ DIP { DROP } } } } ;
       { /* final clean up */ DIP { DROP 2 } } } ;

@yoshihiro503
Copy link
Author

The iml by scaml --dump-iml typeerror.ml.

(fun global_param_1163 ->
   (fun storage_1162 ->
      (let __v_1175
         = (global_param_1163 </* = __x_1170 *//* = __param_1184 *//* = param_1153 *//* = __v_1185 *//* = __param_1164 */> : pair nat (pair (contract unit) unit))
       in
       (let __r_1176
          = (snd (__v_1175 : pair nat (pair (contract unit) unit)) : pair (contract unit) unit)
        in
        ((let __counter_1172
            = (fst (__v_1175 : pair nat (pair (contract unit) unit)) </* = counter_1155 *//* = __l_1177 */> : nat)
          in
          (fun __contr_1173 ->
             (fun __sigs_1174 ->
                (if (<> (__counter_1172 : nat) (1 : nat) : bool)
                 then (failwith ("0" : string) : pair (list operation) nat)
                 else (((Operation.transfer_tokens (() : unit) (1000000 : mutez) (__contr_1173 : contract unit) </* = __op_1168 *//* = op_1158 *//* = __v_1169 *//* = __x_1166 */> : operation) :: ([] : list operation) : list operation),
                       (__counter_1172 : nat) : pair (list operation) nat) : pair (list operation) nat) : lambda unit (pair (list operation) nat)) : lambda (contract unit) (lambda unit (pair (list operation) nat))) : lambda (contract unit) (lambda unit (pair (list operation) nat))) 
        (fst (__r_1176 : pair (contract unit) unit) </* = contr_1156 *//* = __l_1179 */> : contract unit) (snd (__r_1176 : pair (contract unit) unit) </* = sigs_1157 *//* = __r_1178 */> : unit) : pair (list operation) nat) : pair (list operation) nat) </* entry main_1152 */> : pair (list operation) nat) : lambda nat (pair (list operation) nat)) : lambda (pair nat (pair (contract unit) unit)) (lambda nat (pair (list operation) nat)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment