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

Failed transfer with low-level call will not revert #167

Closed
code423n4 opened this issue Mar 10, 2023 · 3 comments
Closed

Failed transfer with low-level call will not revert #167

code423n4 opened this issue Mar 10, 2023 · 3 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue grade-c QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-03-aragon/blob/4db573870aa4e1f40a3381cdd4ec006222e471fe/packages/contracts/src/core/dao/DAO.sol#L186

Vulnerability details

Impact

In DAO.sol, the function execute uses a low-level function .call to perform _actions:

(bool success, bytes memory response) = to.call{value: _actions[i].value}(_actions[i].data);

The code is executing a low-level call to a (potential) contract without verifying if the contract exists. If there is no code at the provided address, the call will succeed and the sender will lose the sent funds.
According to the solidity docs: The low-level functions call, delegatecall and staticcall return true as their first return value if the account called is non-existent, as part of the design of the EVM. Account existence must be checked prior to calling if needed.

Proof of Concept

https://docs.soliditylang.org/en/develop/control-structures.html#error-handling-assert-require-revert-and-exceptions

contract Test {
    function testCall() public payable returns (bool) {
        address nonExistentAccount = 0x0000000000000000000000000000000000000000;
        (bool success,) = nonExistentAccount.call{value: msg.value}("");
        return success;
    }
}

REMIX IDE can be used to test PoC. msg.value will be lost.

Tools Used

Manual Analysis

Recommended Mitigation Steps

require(to.code.length > 0, "Contract doesn't exists");

Before executing the low-level call, it is important to verify the existence of the code. However, implementing this check may cause issues when transferring funds to an EOA address. To address this problem, we can prompt the user to specify whether the address is for an EOA or a contract. If the address is for an EOA, then the existence check is not necessary. However, if it is for a contract, the check is crucial to ensure the safety of the transaction.
For that we need to add a bool in the struct Actions:

    struct Action {
        address to;
+       bool isAddressEOA;
        uint256 value;
        bytes data;
    }

And then code existence check inside an If statement in the execute function:

for (uint256 i = 0; i < _actions.length; ) {
            address to = _actions[i].to;
+           if(!_actions[i].isAddressEOA){
+               require(to.code.length > 0, "Contract doesn't exists");
+           }
            (bool success, bytes memory response) = to.call{value: _actions[i].value}(
                _actions[i].data
            );

            if (!success) {
                // If the call failed and wasn't allowed in allowFailureMap, revert.
                if (!hasBit(_allowFailureMap, uint8(i))) {
                    revert ActionFailed(i);
                }

                // If the call failed, but was allowed in allowFailureMap, store that
                // this specific action has actually failed.
                failureMap = flipBit(failureMap, uint8(i));
            }

            execResults[i] = response;

            unchecked {
                ++i;
            }
        }
@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Mar 10, 2023
code423n4 added a commit that referenced this issue Mar 10, 2023
@0xean
Copy link

0xean commented Mar 12, 2023

payloads are verified ahead of execution by the DAO, QA.

@c4-judge
Copy link

0xean changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Mar 12, 2023
@c4-judge
Copy link

0xean marked the issue as grade-c

@c4-judge c4-judge added grade-c unsatisfactory does not satisfy C4 submission criteria; not eligible for awards labels Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue grade-c QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

3 participants