Closed code423n4 closed 2 years ago
The code is written in solidity 0.8.12 a division by zero will cause a revert.
For that reason I must disagree with the finding, I would like to see a code POC but I believe the POC would just revert per the reason above
I think this issue can be considered as a dup of #74
Lines of code
https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L293 https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L890 https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L881 https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L764
Vulnerability details
Impact
In
StakedCitadel.sol/_mintSharesFor()
, it doesn’t check whether thepool
is equal to zero. Ifpool == 0
andtotalSupply() != 0
,_mintSharesFor()
will revert. And In_depositFor()
, it usesbalance()
aspool
. In consequence, when the CTDL balance ofStakedCitadel
is zero and the total supply of xCTDL is not zero,_depositFor()
always reverts. No one can ever deposit any CTDL.Proof of Concept
earn()
, and it transfer 95% of CTDL balance of StakedCitadel to strategyhttps://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L717
withdrawAll()
, It should take 10 CTDLs in this case. The CTDL balance of StakedCitadel is not enough afterearn()
, So it will transfer CTDLs from strategy to ensurer == token.balanceOf(address(this))
. Since withdrawalFee is never higher than 2%, there is no fee in this transaction. In the end, the CTDL balance of StakedCitadel becomes zero.balance()
in_depositFor()
returns zero, AndtotalSupply()
in_mintSharesFor()
returns non-zero, since Alice still has xCTDL. In consequence,_mintSharesFor()
always reverts atshares = (_amount * totalSupply()) / _pool;
, no one can deposit any CTDL intohttps://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L764
https://github.com/code-423n4/2022-04-badger-citadel/blob/main/src/StakedCitadel.sol#L881
Tools Used
vim
Recommended Mitigation Steps
Add a check for
pool
in_mintSharesFor()