Beginner FriendlyDeFiFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

The Laundrette::withdrawMoney function does not check the balance of the account before attempting to withdraw money.

Description
Insufficient balance checks result in arithmetic underflow errors when balance is less than the withdraw amount.

Impact
The impact is low as there does not appear to be an impact on GAS and the balance uses a uint256 so it cannot become negative. However insufficient error handling can make debugging more difficult and should be considered a code smell.

Proof of Concept

This is the diff showing the change needed.

File:: Laundrette.sol

function withdrawMoney(
address account,
address to,
uint256 amount
)
external
onlyRole("gangmember")
isAuthorizedOrRevert(account)
{
+ // Without this check we will get an underflow error if the amount
+ // exceeds the amount in the account
+ require(moneyShelf.getAccountAmount(account) >= amount,
+ "Laundrette::withdrawMoney insufficient balance");
moneyShelf.withdrawUSDC(account, to, amount);
}

The following shows the error without the require check shown above.

// test exceeding member2's balance
vm.prank(member2);
laundrette.withdrawMoney(member2, member1, 2);

Output:

├─ [6795] Laundrette::withdrawMoney(member2: [0xbD405055317EF6089a771008453365060BB97aC1], member1: [0x86fEa303737F5219d7b5E4f30Cb7268Bec1775Fa], 2)
│ ├─ [707] Kernel::hasRole(member2: [0xbD405055317EF6089a771008453365060BB97aC1], 0x67616e676d656d62657200000000000000000000000000000000000000000000) [staticcall]
│ │ └─ ← [Return] true
│ ├─ [4437] MoneyShelf::withdrawUSDC(member2: [0xbD405055317EF6089a771008453365060BB97aC1], member1: [0x86fEa303737F5219d7b5E4f30Cb7268Bec1775Fa], 2)
│ │ ├─ [2917] Kernel::modulePermissions(0x4d4f4e4559000000000000000000000000000000000000000000000000000000, Laundrette: [0xD76ffbd1eFF76C510C3a509fE22864688aC3A588], 0x7922620900000000000000000000000000000000000000000000000000000000) [staticcall]
│ │ │ └─ ← [Return] true
│ │ └─ ← [Revert] panic: arithmetic underflow or overflow (0x11)
│ └─ ← [Revert] panic: arithmetic underflow or overflow (0x11)
└─ ← [Revert] panic: arithmetic underflow or overflow (0x11)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 5.43ms (1.63ms CPU time)
[FAIL. Reason: panic: arithmetic underflow or overflow (0x11)] test_depositInternalAccountingBalance() (gas: 367795)

Recommended mitigation

  • Add the require check as shown in the diff above to prevent and handle the error.

References
N/A

Tools Used

  • Manual review

  • Unit Test

Updates

Lead Judging Commences

n0kto Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.