Cyfrin / 2023-07-escrow

17 stars 12 forks source link

Any residual funds after all the transactions get stuck in the contract #874

Closed codehawks-bot closed 11 months ago

codehawks-bot commented 11 months ago

Any residual funds after all the transactions get stuck in the contract

Severity

Medium Risk

Relevant GitHub Links

https://github.com/Cyfrin/2023-07-escrow/blob/main/src/Escrow.sol#L94

Summary

Any residual funds after all the transactions get stuck in the contract

Vulnerability Details

After the payment is done using confirmReceipt, the residual funds should be transferred to the buyer. Otherwise, if the escrow contract was funded multiple times, or something wrong happened which could have led to the initialization of the contract with more balance than needed, then that fun never leaves the contract and the buyer may never be able to recover the funds.

Impact

Residual balances can get stuck in the Escrow contract

Tools Used

Manual Code Review

Recommendations

The code can be changed to send the residual funds back to the buyer.

   function confirmReceipt() external onlyBuyer inState(State.Created) {
        ...
        ...
        uint256 totalBalance = i_tokenContract.balanceOf(address(this));
        i_tokenContract.safeTransfer(i_seller, i_price);
        i_tokenContract.safeTransfer(i_buyer,  totalBalance - i_price);
    }
0kage-eth commented 11 months ago