<!-- canonical: https://0xsimao.com/findings/codeup-erc20-revert-weth-low -->

# `Codeup::claimCodeupERC20()` may revert whenever the `weth` balance is very low

Medium · Three Sigma · DeFi game · 23rd October, 2024

Finding M-1 of the CODEUP security review.

- Report: /reports/codeup
- Source: https://cdn.sanity.io/files/qoqld077/staging/d9e57830a75b5165fd56e8b88037de7986a165ec.pdf

---

### Description

`Codeup::claimCodeupERC20()` adds liquidity to the `Uniswap` pool whenever the `weth` balance is bigger than `1`. However, an amount bigger than `1` may still lead to reverts if it is low enough. If it is exactly 1, it will shift right to get the amount of `weth` to swap for `CodeupERC20`, trying to swap an amount of `0` and reverting. If it is bigger than 2, but still low, it may swap this for an even smaller amount of `CodeupERC20`, reverting when adding liquidity due to not providing enough liquidity to mint a single share.
A [poc](https://github.com/0x73696d616f/codeup-issues-external/blob/main/test/Codeup.t.sol#L146) is available to confirm the finding.

### Recommendation

Instead of setting `1`, a slightly bigger dust amount could be use to ensure it does not revert.

---

Related findings:

- [An attacker may DoS user Fluid balance increases by frontrunning `FluidLocker::claim()` calls and calling `EP_PROGRAM_MANAGER::batchUpdateUserUnits()` directly](https://0xsimao.com/findings/superfluid-locker-system-increases-frontrunning-program-directly): Superfluid Locker System
