Skip to content

Multi-entries may cause more storage consumptions. #131

@catsigma

Description

@catsigma
type storage = unit

contract type X = sig
  type storage
  val%entry entry_a : nat -> storage -> operation list * storage
  val%entry entry_b : int -> storage -> operation list * storage
end

contract type Y = sig
  type storage
  type pt = 
  | A of nat
  | B of int

  val%entry main : pt -> storage -> operation list * storage
end

(* 1 : Using entry syntax *)
let%entry main (parameter : nat * X.instance) s =
  let num, c = parameter in
  let op = 
    if num < 50p then
      Contract.call c 0tz entry_a 1p
    else
      Contract.call c 0tz entry_b 1
  in
  ([op], s)

(* 2 : Using entry manually *)
(* let%entry main (parameter : nat * Y.instance) s =
  let num, c = parameter in
  let arg = 
    if num < 50p then
      Y.A 1p
    else
      Y.B 1
  in
  let op = Contract.call c 0tz arg in
  ([op], s) *)

For code block 1, it will compile to

parameter
  (pair nat
        (contract :X (or :_entries (nat %_Liq_entry_entry_a) (int %_Liq_entry_entry_b))));
storage unit;
code { DUP ;
       DIP { CDR } ;
       CAR ;
       DUP @parameter ;
       DUP ;
       CDR @c ;
       DUUUUP @s ;
       NIL operation ;
       PUSH nat 50 ;
       DUUUUUP ;
       CAR @num ;
       COMPARE ;
       LT ;
       IF { DUUUP @c ;
            PUSH mutez 0 ;
            PUSH nat 1 ;
            LEFT %_Liq_entry_entry_a % (int %_Liq_entry_entry_b) ;
            TRANSFER_TOKENS }
          { DUUUP @c ;
            PUSH mutez 0 ;
            PUSH int 1 ;
            RIGHT % %_Liq_entry_entry_b nat ;
            TRANSFER_TOKENS } ;
       DIIIP { DROP ; DROP ; DROP ; DROP } ;
       RENAME @op ;
       CONS ;
       PAIR };

For code block 2, it will compile to

parameter (pair nat (contract :Y (or :Y.pt (nat %Y.A) (int %Y.B))));
storage unit;
code { DUP ;
       DIP { CDR } ;
       CAR ;
       DUP @parameter ;
       DUP ;
       CDR @c ;
       PUSH mutez 0 ;
       PUSH nat 50 ;
       DUUUUP ;
       CAR @num ;
       COMPARE ;
       LT ;
       IF { PUSH (or :Y.pt (nat %Y.A) (int %Y.B)) (Left 1) }
          { PUSH (or :Y.pt (nat %Y.A) (int %Y.B)) (Right 1) } ;
       DIIIP { DROP ; DROP } ;
       RENAME @arg ;
       TRANSFER_TOKENS @op ;
       SWAP ;
       NIL operation ;
       DUUUP ;
       DIIIP { DROP } ;
       CONS ;
       PAIR };

Using multiple entries will generate larger size of code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions