Skip to content

Michelson: allow multiple big maps in contracts

Alain Mebsout requested to merge alain/multiple-big-maps into master

This is a proposal to allow multiple big maps in the storage of a contract. This MR allows for 4 different big maps although this number can be easily changed (but is hard-coded).

Big map types must be followed by an integer id, they are written (e.g.):

(bigmap 0 int unit)
(bigmap 1 int unit)
(bigmap 2 string timestamp)
(bigmap 3 bytes key_hash)

instead of just (bigmap <key> <val>) previously.

The different bigmap types are incompatible. Big maps can only appear as a top-level components of the storage type, i.e. as the storage type itself or in a (possibly nested) pair at top-level, and each big map id must appear at most once. These constraints guarantee that diffs (the internal representation in the interpreter) cannot be applied on the wrong maps.

For instance, the following storage types are allowed:

storage (bigmap 1 int unit) ;
storage (pair (bigmap 0 int unit) (bigmap 1 int unit)) ;
storage (pair (pair (bigmap 3 int unit) string) (bigmap 0 int unit)) ;

while the following ones are forbidden:

storage (or (bigmap 0 int unit) (bigmap 1 int unit)) ;
storage (pair (bigmap 1 int unit) (bigmap 1 int unit)) ;
storage (pair (bigmap 1 int unit) (bigmap 1 int string)) ;
storage (bigmap 0 int (bigmap 1 int unit)) ;

As of now, the syntax and semantic of big maps is not retro-compatible with current Michelson but it can be made so. We could keep the type (bigmap <key> <val) as sugar for (bigmap 0 <key> <val) and store values for big map 0 in the contract's storage by just hashing the key, instead of the pair (0, key).

Merge request reports