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_originationto 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.initto re-unparse the storage (but why??) - in the interpreter
- in
applyto 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
transferto build an untyped parameter for the internalTransaction - in
create_contractto build an untyped storage for the internalOrigination - in
ifailwiththough the Micheline is really useful to indexers only - in
executeto re-unparse the storage (but why??)
- in
- in the elaborator
- in
pack_data - in
diff_of_big_map
- in
- in
ticket_balance_keyto 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_instrforPUSH - in
parse_storage - in
unparse_codeto normalize lambdas- in
unparse_data - in
apply_origination
- in
- in
big_map_get_by_hash
- in
- in the interpreter
- in
unpack - in
executeto parse the parameter (now of external operations only)
- in
- in the ticket scanner
- in
tickets_of_big_map - in
tickets_of_nodeused incollect_token_diffs_of_nodeused to collect tickets of big map diffs
- in
- in
apply/Tx_rollup_withdraw- to parse the user-provided contents of a ticket that is later unparsed...
So:
-
PUSHwill be OK if all scripts are normalized -
parse_storagewill be OK if all storages are normalized -
unparse_codewon't be necessary any more if all scripts are normalized -
big_map_get_by_hash,tickets_of_big_map,tickets_of_nodeare OK because big map values are built indiff_of_big_map -
executeandapply/Tx_rollup_withdrawwill be OK if all external parameters are normalized unpackneeds 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
- already stored storages should be normalized already
- 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.