Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

false warning: Function state mutability can be restricted to pure [v0.57.3] #89

Open
ilyar opened this issue Feb 23, 2022 · 3 comments

Comments

@ilyar
Copy link

ilyar commented Feb 23, 2022

App.sol

pragma ton-solidity = 0.57.3;

contract App {
    uint public owner;

    modifier onlyOwner() {
        require(msg.pubkey() == owner);
        _;
    }

    modifier checkPubKey() {
        require(msg.pubkey() == tvm.pubkey());
        _;
    }

    constructor() public checkPubKey {
        tvm.accept();
        owner = msg.pubkey();
    }

    function foo(string bar) public view onlyOwner returns(string out) {
        tvm.accept();
        out = format('42{}', bar);
    }
}
npx everdev sol set --compiler 0.57.3
npx everdev sol compile --code --output-dir build App.sol
Warning: Function state mutability can be restricted to pure
  --> App.sol:21:5:
   |
21 |     function foo(string bar) public view onlyOwner returns(string out) {
   |     ^ (Relevant source part starts here and spans across multiple lines).
@IgorKoval
Copy link
Collaborator

Why is it wrong warning?

@ilyar
Copy link
Author

ilyar commented Mar 1, 2022

broxus/ever-contracts#4 (comment) This method can't be pure because the onlyOwner modifier must have access to the contract state which is not loaded for pure methods. It is a known bug in compiler which still exists. @Rexagon

@pavlovdog
Copy link

Hi @IgorKoval ! How's it going? For me, it seems like a critical bug. onlyOwner is a well-known pattern in Solidity development. Probably every second developer will see the compiler hint and insert the pure modifier, which leads to unexpected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants