After having written the following rough draft for an eject button in some contract:

function triggerReturnAll() public override onlyAfterDelayAndUnderTarget {
    require(msg.sender == _projectLead, "Someone other than projectLead tried to return all investments.");
    uint256 nrOfTierInvestments = _tierInvestments.length;
    for (uint256 i = 0; i < nrOfTierInvestments; ++i) {
      // Transfer the amount to the PaymentSplitter contract
    require(address(this).balance == 0, "After returning investments, there is still money in the contract.");

I get the warning:

DecentralisedInvestmentManager.triggerReturnAll() (src/DecentralisedInvestmentManager.sol#367-375) uses a dangerous strict equality:
    - require(bool,string)(address(this).balance == 0,After returning investments, there is still money in the contract.) (src/DecentralisedInvestmentManager.sol#374)
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#dangerous-strict-equalities

From Slither.


That makes me wonder, is it possible to have this contract receive currency while this triggerReturnAll() function is being executed? I assume it is not possible, as I would expect the incoming transaction to be processed before or after the function.

That also makes me wonder whether this require(address(this).balance == 0,) is superfluous to the logic of the function, whether I should instead just assert the outgoing transfers are all successful, whether I should ignore Slither warning and/or whether I should verify the correct return of all funds differently in that function. What would be the best practice here?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.