[go: up one dir, main page]

Get rid of Readable in the protocol

We have 3 parsing/unparsing modes of Michelson data into Micheline in the protocol: Readable, Optimized, and Optimized_legacy.

It means we have several ways to represent the same thing, which led and will keep leading to issues.

I am interested only in the operation validation paths so I will deliberately ignore RPCs.

We should get rid of Readable in the protocol, it is meant to read/display data in the client. Anything else in the protocol should use Optimized or Optimized_legacy (let's not discuss the difference or removal of one of them here).

!3852 (merged) adds a normalization of scripts at origination time. This is very sad. Ideally it should not happen.

Currently unparse_(comparable_)data is used:

  • in apply_origination to normalize the storage
  • in apply/Tx_rollup_withdraw
    • to build a Micheline node for the ticketer
    • to build an untyped parameter for an internal Transaction
  • in Main.init to re-unparse the storage (but why??)
  • in the interpreter
    • in apply to generate Micheline for the parameter of the partial application for the Micheline version of the lambda (useful only if the partially applied lambda is later packed or stored)
    • in transfer to build an untyped parameter for the internal Transaction
    • in create_contract to build an untyped storage for the internal Origination
    • in ifailwith though the Micheline is really useful to indexers only
    • in execute to re-unparse the storage (but why??)
  • in the elaborator
    • in pack_data
    • in diff_of_big_map
  • in ticket_balance_key to produce a ticket hash from a ticketer address, a content and an owner address

Fortunately Readable is never used to unparse. But parse allows Readable values.

I propose to forbid it. Obviously it may break parsing values. Let's have a look:

Currently, parse_(comparable_)data is used:

  • in the elaborator
    • in parse_instr for PUSH
    • in parse_storage
    • in unparse_code to normalize lambdas
      • in unparse_data
      • in apply_origination
    • in big_map_get_by_hash
  • in the interpreter
    • in unpack
    • in execute to parse the parameter (now of external operations only)
  • in the ticket scanner
    • in tickets_of_big_map
    • in tickets_of_node used in collect_token_diffs_of_node used to collect tickets of big map diffs
  • in apply/Tx_rollup_withdraw
    • to parse the user-provided contents of a ticket that is later unparsed...

So:

  • PUSH will be OK if all scripts are normalized
  • parse_storage will be OK if all storages are normalized
  • unparse_code won't be necessary any more if all scripts are normalized
  • big_map_get_by_hash, tickets_of_big_map, tickets_of_node are OK because big map values are built in diff_of_big_map
  • execute and apply/Tx_rollup_withdraw will be OK if all external parameters are normalized
  • unpack needs to be discussed

We need to make sure:

  • all scripts are normalized
    • we need to normalize already stored scripts
    • internally originated scripts should be no problem (by induction)
    • we need to forbid non-normalized externally originated scripts (instead of doing the normalization in the protocol, the client must take care of it)
  • all storages are normalized
    • already stored storages should be normalized already
      • but let's make sure they are
    • the storage of internally originated scripts should be no problem (by induction)
    • we should forbid non-normalized storages for external originations
  • all external parameters are normalized
    • the parameter of internal transfers should be no problem (by induction)
    • we should forbid non-normalized external parameters

To help us, we can use a type to represent Micheline expressions which are provably unparsed Michelson values with Optimized mode.

Cc @naih @sventimir @tomjack @rafoo_