Skip to content

Assignment to immutable and constant variables #11

@bitbart

Description

@bitbart

Extend the interpreter so that it reverts a transaction whenever a state variable with mutability declared as constant is assigned.

For example, consider the contract:

contract C {
    int constant N=1;
    int x;
    function f(int n) external { if (n>0) x+=1; else N=0; }
  }

A call to f(0) should revert, since it would trigger an assignment to the constant N.

State variables declared as immutable can be assigned, but only in the constructor. For example, in the contract:

contract C {
    int immutable x;
    constructor(int n) { x = n; }
    function f(int n) external { if (n==0) x=0; }
  }

The assignment in the constructor does not revert, but a call to f(0) should revert, since it would trigger an assignment to the immutable variable x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions