Skip to content

Contract Metadata - Check storage metadata type

Nicolas Phan requested to merge metadata into dev

Motivation and Context

Related Issue : #1788 (closed) (see point 1)

This MR adds a check of storage metadata type (check if it's a (string, bytes) big_map). The idea is that, if a contract contains a metadata field, it's probably meant to be TZIP-16 compliant, thus should be a (string, bytes) big_map according to the TZIP-16 specification.

This MR also adds an "escape-latch" CLI flag to disable then check (namely, --no-metadata-check)

Note : The MR is non-breaking since the check only throws a warning an not an error.

Description

Component

  • compiler
  • website
  • webide
  • vscode-plugin
  • debugger

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement (non-breaking change that improves performance)
  • None (change with no changelog)

Changelog

For a contract with TZIP-16 non-compliant metadata, such as the following :

// metadata with incorrect format
type storage = {
  data     : int,
  metadata : nat, // Should be big_map<string, bytes>
};
type param = int;
type ret = [list<operation>, storage];

// Dummy entrypoint
const main  = (_p : param, s : storage) : ret =>
  [list([]), s];

The compiler will now throw a warning on ligo compile contract and ligo compile storage.

The warning is suppressible using the --no-metadata-check flag.

Before

> ligo compile contract 'example.jsligo'
{ parameter int ;
  storage (pair (int %data) (nat %metadata)) ;
  code { CDR ; NIL operation ; PAIR } }

After

> ligo compile contract 'example.jsligo' --no-color
File "example.jsligo", line 4, characters 13-16:
  3 |   data     : int,
  4 |   metadata : nat, // Should be big_map<string, bytes>
  5 | };
:
Warning: If the following metadata is meant to be TZIP-16 compliant,
then it should be a 'big_map' from 'string' to 'bytes'.
Hint: The corresponding type should be :
  big_map<string, bytes>
You can disable this warning with the '--no-metadata-check' flag.

{ parameter int ;
  storage (pair (int %data) (nat %metadata)) ;
  code { CDR ; NIL operation ; PAIR } }
> ligo compile contract --no-metadata-check 'example.jsligo'
{ parameter int ;
  storage (pair (int %data) (nat %metadata)) ;
  code { CDR ; NIL operation ; PAIR } }

Checklist:

  • Changes follow the existing coding style (use dune @fmt to check).
  • Tests for the changes have been added (for bug fixes / feature).
  • Documentation has been updated.
  • Changelog description has been added (if appropriate).
  • Start titles under ## Changelog section with #### (if appropriate).
  • There is no image or uploaded file in changelog
  • Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by E. Rivas

Merge request reports