<!-- canonical: https://0xsimao.com/findings/codeup-rounding-game-eth-precision -->

# Significant rounding errors due to `gameETH` not having precision

Crit/High · Three Sigma · DeFi game · 23rd October, 2024

Finding H-2 of the CODEUP security review.

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

---

### Description

In `Codeup::addGameETH()` and `Codeup::reinvest()`, `gameETH` is obtained as `gameETH = amount / gameETHPrice`, which means there may be rounding errors. `gameETH` has no decimals as can be confirmed by the return values of `Codeup::_getUpgradePrice()` and `Codeup::_getYield()`, which have no extra precision. 

Thus, as `gameETHPrice` may be a big value - currently `1e12` in the tests, the rounding error may be up to `1e12 - 1`, which is approx `0.0023 USD`. If the price is increased, the rounding error grow to bigger values causing significant loss of funds for users.

### Recommendation

Add some precision to `gameETH` by scaling the values in the functions `Codeup::_getUpgradePrice()` and `Codeup::_getYield()` and decreasing the `gameETHPrice` so `gameETH` inherits the decimals of `ETH`.

---

Related findings:

- [`FluidLocker::_getUnlockingPercentage()` divides before multiplying, suffering a significant precision error](https://0xsimao.com/findings/superfluid-locker-system-unlocking-multiplying-suffering-precision): Superfluid Locker System
- [Significant rounding error in whitelist discount that could be avoided](https://0xsimao.com/findings/1inch-rounding-whitelist-discount-avoided): 1inch Fee Extension
