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

IR, code within modifiers seem to always appear at the end of functions. #372

Open
AnonymousMonkey2021 opened this issue Nov 18, 2019 · 2 comments

Comments

@AnonymousMonkey2021
Copy link

The code for the function being modified is inserted where the _ is placed in the modifier.

RequireExample.sol file:


pragma solidity ^0.5.11;
contract RequireExample {
    
    address public owner;
    
    constructor() public {
        owner = msg.sender;
    }
    
    uint public number = 0;
    bool public a = true;
    bool public b = true;
    bool public c = false;
    bool public d = true;

    modifier checka(){
        c = true;
        require(a);
        _;
    }

    function requireb() public{
        if (d){
            d = false;
        }


        require(b);
    }
    
    function test(uint _n, bool _b) checka public {
        requireb();
    }
    
}

And this is the result from IR.

Function RequireExample.test(uint256,bool)
		Expression: requireb()
		IRs:
			INTERNAL_CALL, RequireExample.requireb()()
		Expression: checka()
		IRs:
			INTERNAL_CALL, RequireExample.checka()()
		Modifier Call None

I'm not sure if the problem I'm seen is supposed to be like this.
Since the _; appeared at the end of the modifier, the code within the modifier should be added at the beginning of the function, right?
Otherwise, if modifiers are always placed at the end of the function, how do we know whether the modifier is doing pre-condition or post-condition checking?

@AnonymousMonkey2021 AnonymousMonkey2021 changed the title IR, requires within modifiers seem to appear at the end. IR, code within modifiers seem to always appear at the end of function. Nov 18, 2019
@AnonymousMonkey2021 AnonymousMonkey2021 changed the title IR, code within modifiers seem to always appear at the end of function. IR, code within modifiers seem to always appear at the end of functions. Nov 18, 2019
@montyly
Copy link
Member

montyly commented Nov 18, 2019

Hi @JackHFeng. Thank you for your interest in Slither.

This is actually an output artifact.
Currently, Slither does not have a straightforward API to output properly the modfier's cfg into in the function using it (which requires some control-flow tricks to handle the _ placeholder). The modifiers calls are kept into function.modifiers_statements.

The IRs nodes generated by these calls are kept into a separate CFG. When the slithir printer outputs the information, it shows all the nodes without any order:

image

To get the pre-condition/post-condition, an analysis must iterate over the function.modifiers_statements, and properly extract them. There is a specific node type for the modifier's placeholder: NodeType.PLACEHOLDER.

We are working towards a better API to handle modifiers calls at the analysis level, but right now it's documentation is not up to date. Feel free to join our slack (#ethereum) if you want direct support on this API.

@AnonymousMonkey2021
Copy link
Author

Thank you @montyly !

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

No branches or pull requests

3 participants