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

Not checking the return state of the calls in UTBExecutor::execute can cause loss/locking of funds #544

Closed
c4-bot-2 opened this issue Jan 23, 2024 · 3 comments
Labels
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 duplicate-25 edited-by-warden insufficient quality report This report is not of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-bot-2
Copy link
Contributor

c4-bot-2 commented Jan 23, 2024

Lines of code

https://github.com/code-423n4/2024-01-decent/blob/011f62059f3a0b1f3577c8ccd1140f0cf3e7bb29/src/UTBExecutor.sol#L54
https://github.com/code-423n4/2024-01-decent/blob/011f62059f3a0b1f3577c8ccd1140f0cf3e7bb29/src/UTBExecutor.sol#L67

Vulnerability details

Impact

The function UTBExecutor::execute does not handle the return value of the calls refund.call{value: amount}("") and refund.call{value: extraNative}(""), which could lead to a loss of funds for users. This is because if the refund call fails, the contract does not revert the transaction, and the funds intended for refund remain in the contract.

This behavior violates one of the protocol's invariants which is the prevention of the accumulation of funds in contracts other than UTBFeeCollector and DcntEth :

Fund Accumulation: Other than the UTBFeeCollector, and DcntEth, the contracts are not intended to hold on to any funds or unnecessary approvals. Any native value or erc20 flowing through the protocol should either get delivered or refunded.

Proof of Concept

The issue lies in the following line of code:

    function execute(
        address target,
        address paymentOperator,
        bytes memory payload,
        address token,
        uint amount,
        address payable refund,
        uint extraNative
    ) public onlyOwner {
        bool success;
        if (token == address(0)) {
            (success, ) = target.call{value: amount}(payload);
            if (!success) {
@>              (refund.call{value: amount}(""));
            }
            return;
        }

        uint initBalance = IERC20(token).balanceOf(address(this));

        IERC20(token).transferFrom(msg.sender, address(this), amount);
        IERC20(token).approve(paymentOperator, amount);

        if (extraNative > 0) {
            (success, ) = target.call{value: extraNative}(payload);
            if (!success) {
@>              (refund.call{value: extraNative}(""));//@audit not check success state
            }
        } else {
            (success, ) = target.call(payload);
        }

        uint remainingBalance = IERC20(token).balanceOf(address(this)) -
            initBalance;

        if (remainingBalance == 0) {
            return;
        }

        IERC20(token).transfer(refund, remainingBalance);
    }

In both calls, if the call to the refund address fails, the contract does not revert or handle the failure. This can result in the funds being unintentionally locked in the contract.

Tools Used

Manual review

Recommended Mitigation Steps

Check and handle the success state of the call :

diff --git a/src/UTBExecutor.sol b/src/UTBExecutor.sol
index 38c3f8a..d1049d5 100644
--- a/src/UTBExecutor.sol
+++ b/src/UTBExecutor.sol
@@ -51,7 +51,8 @@ contract UTBExecutor is Owned {
         if (token == address(0)) {
             (success, ) = target.call{value: amount}(payload);
             if (!success) {
-                (refund.call{value: amount}(""));
+                (success, ) = (refund.call{value: amount}(""));
+                require(success, "Refund failed");
             }
             return;
         }
@@ -64,7 +65,8 @@ contract UTBExecutor is Owned {
         if (extraNative > 0) {
             (success, ) = target.call{value: extraNative}(payload);
             if (!success) {
-                (refund.call{value: extraNative}(""));
+                (success, ) =  (refund.call{value: extraNative}(""));
+                require(success, "Refund failed");
             }
         } else {
             (success, ) = target.call(payload);

Assessed type

call/delegatecall

@c4-bot-2 c4-bot-2 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 Jan 23, 2024
c4-bot-2 added a commit that referenced this issue Jan 23, 2024
@c4-pre-sort c4-pre-sort added the insufficient quality report This report is not of sufficient quality label Jan 25, 2024
@c4-pre-sort
Copy link

raymondfam marked the issue as insufficient quality report

@c4-pre-sort
Copy link

raymondfam marked the issue as duplicate of #25

@c4-judge
Copy link

c4-judge commented Feb 2, 2024

alex-ppg marked the issue as unsatisfactory:
Invalid

@c4-judge c4-judge added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 duplicate-25 edited-by-warden insufficient quality report This report is not of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

4 participants