Skip to content

[TM-85] Restrict operations scope

Konstantin Ivanov requested to merge martoon/tm85-restrict-operations into master

Description

Problem: 1. There is hacky unsafeValToValue; 2. Actually we don't check that operations appear only in allowed scope.

There is a special error message in ./alphanet.sh:

operation type forbidden in parameter, storage and constants

So, your contract becomes ill-typed if one of the following holds:

  • Contract's parameter type is operation, or contains it (e.g. list operation);
  • Contract's storage type contains operation;
  • You define a constant, type of which contains operation (e.g. PUSH (map int operation) {}).

The only thing you can do with operations is to directly put them on stack. Moreover, as an immediate consequence, type of every contract code must contain operations only in the second argument of the returned pair; neither contract input, nor the first argument of the returned pair can contain it. However, lambdas are allowed to accept and return operations (because lambdas' argument and returned result lie on stack).

Solution: add HasNoOp constraint, and require it in corresponding places (parameter, storage, PUSH argument, contract creating operations). This way we ensure that typechecker does prevent operations from appearing where they are not permitted to be.

As a moment of pleasure, under HasNoOp constraint our Val to Value converter becomes total. This allows turning unsafeValToValue into safe function.

Related issue(s)

https://issues.serokell.io/issue/TM-85

Checklist for your Merge Request

Related changes (conditional)

  • Tests

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
  • Documentation

    • I checked whether I should update the docs and did so if necessary:

Stylistic guide (mandatory)

Edited by Konstantin Ivanov

Merge request reports