Unbounded number of bonusTokens #114
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
This issue or pull request already exists
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/rubiconPools/BathToken.sol#L629
https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/rubiconPools/BathToken.sol#L270
Vulnerability details
Impact
Each additional bonus token added to the
BathToken.bonusTokens[]
array will cause the gas fee ofBathToken.withdraw()
calls to be more expensive.The
BathToken
does not impose any upper limit on theBathToken.bonusTokens[]
array. It also does not implement any function to reduce the size of theBathToken.bonusTokens[]
array.As such, it is possible to append new bonus token to the
BathToken.bonusTokens[]
array until a point where an "Out of Gas" error or a "Block Gas Limit" error happens whenBathToken.withdraw()
is called. At this point, none of the BathToken LPs will be able to withdraw their funds from the affected BathToken pools.Proof-of-Concept
The following shows that the
distributeBonusTokenRewards
function, which is called bywithdraw
function, looping through theBathToken.bonusTokens[]
array and execute the code for the rewards/bonus distribution in each iteration.https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/rubiconPools/BathToken.sol#L629
The following shows the new bonus token address appends to the
BathToken.bonusTokens[]
array without checking for the upper limit.https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/rubiconPools/BathToken.sol#L270
Recommended Mitigation Steps
Define a max number of bonus tokens in a pool, and have the array's length checked. Additionally, implement function to reduce the array size so that it is possible to remove some of the bonus token from the array if needed.
The text was updated successfully, but these errors were encountered: