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

For loop prevents reentrancy detection #1019

Closed
Tracked by #1252
frangio opened this issue Jan 20, 2022 · 3 comments
Closed
Tracked by #1252

For loop prevents reentrancy detection #1019

frangio opened this issue Jan 20, 2022 · 3 comments

Comments

@frangio
Copy link

frangio commented Jan 20, 2022

This was reported before in #940 but wasn't answered, so I wanted to bring attention to it again and give simple reproduction instructions.

In the following code I expect reentrancy-no-eth to detect both r1 and r2 as errors, but only r1 is detected.

Is this a known limitation? Is it documented? Are there any plans to fix it? Thanks.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract ITarget {
    function exec() public {}
}

contract Reenter {
    uint x;

    function r1(ITarget target) public {
        if (x > 0) {
            target.exec();
            x = 0;
        }
    }

    function r2(ITarget target) public {
        if (x > 0) {
            for (uint i = 0; i < 1; i++) {
                target.exec();
            }
            x = 0;
        }
    }
}
@montyly
Copy link
Member

montyly commented Jan 21, 2022

Hi @frangio, thanks for pointing this out, somehow #940 was missed for the 0.8.2 release.

We will investigate why it happens

@Jaime-Iglesias
Copy link
Contributor

Jaime-Iglesias commented Jan 23, 2022

Hi @frangio, thanks for pointing this out, somehow #940 was missed for the 0.8.2 release.

We will investigate why it happens

The issue also affects reentrancy-eth as the detector code is very similar.

    function bad3(ITarget target) public payable {
        if (balance >= 10) {
            for (uint256 i = 0; i < 10; i++) {
                target.exec{ value: 1 ether }();
            }
        }
        balance -= 10;
    }

@0xalpharush
Copy link
Contributor

0xalpharush commented Apr 7, 2022

I found another instance of this. Slither detects that nftCount is updated after _safeMint, but it would miss it otherwise (It doesn't alert if a postfix operator is used so that may be a quirk to look into as well).
Test case: https://github.com/FrankieIsLost/smart-batched-auction/blob/dccadf0fdee5859f637ee29f46eb832e10a84b05/contracts/BatchAuction.sol#L102-L107
Patched: FrankieIsLost/smart-batched-auction#1

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

4 participants