Incorrect updateGlobalExchangeRate implementation
The updateGlobalExchangeRate function mishandles the case when totalGlobalShares is zero, causing reward tokens to become permanently locked in the contract. An attacker could trigger this by disabling a validator or through unstaking, leading to locked funds.
Submitted by xYrYuYx
Impact
UpdateGlobalExchangeRate has incorrect implementation when totalGlobalShares is zero.
If any user didn’t start stake, totalGlobalShares is 0, and every stake it will increase. but there is possibility that totalGlobalShares can be 0 amount later by unstake or disable validator.
Proof of Concept
This is my test case to proof this issue: C4_issues.js L76
In my test case, I disabled validator to make totalGlobalShares to zero. And in this case, some reward amount will be forever locked in the contract. After disable validator, I mined 10 blocks, and 4 more blocks mined due to other function calls, So total 14 CQT is forever locked in the contract.
Tools Used
Hardhat test
Recommended Mitigation Steps
Please think again when totalGlobalShares is zero.
kitti-katy (Covalent) acknowledged:
That is right, and I think the best solution would be to add a validator instance who is the owner and stake some low amount of tokens in it. This way we can make sure there is no such situation when
totalGlobalSharesbecomes0and if everyone unstaked, the owner could take out reward tokens and then unstake / redeem rewards.Not sure. That could even be marked as “high risk”. if the situation happens and not handled right away (taking out reward tokens), then there could be more significant financial loss.
kitti-katy (Covalent) commented:
marked resolved as it will be manually handled
GalloDaSballo (judge) commented:
The issue found by the warden is straightforward: Through mix of unstaking and the use of
disableValidatorthe warden was able to lock funds, making them irredemeableIt seems to me that this is caused by the fact that
unstakeas well asdisableValidatorwill reduce the shares: https://github.com/code-423n4/2021-10-covalent/blob/a8368e7982d336a4b464a53cfe221b2395da801f/contracts/DelegatedStaking.sol#L348`I would recommend separating the shares accounting from the activation of validator, simply removing the subtraction of global shares in
disableValidatorwould allow them to claim those shares.The function
disableValidatorcan be called by either the validator or the owner, while onlyOwner can add a new validatorThe owner has the ability to perform this type of griefing, as well as a group of validators if they so chose
Due to the specifics of the grief I will rate it of Medium Severity, as per the docs:
2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.In this case we have a way to leak value (lock funds) with specific condition (malicious owner or multiple griefing validators)
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the updateGlobalExchangeRate function does not correctly handle the case when totalGlobalShares is zero, leading to locked rewards.
Impact
Reward tokens could become permanently locked in the contract, resulting in financial loss.
What the attacker needed
Ability to disable a validator or unstake all shares
The fix
The issue was manually handled according to the project team, but a proper fix would be to ensure totalGlobalShares never becomes zero or to handle the zero case correctly.
How it was found
- Disable a validator to make totalGlobalShares zero.
- Mine blocks to accumulate rewards.
- Observe that reward tokens become locked in the contract.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a smart contract bug where a function that updates exchange rates fails when a key number (total shares) is zero. Because of that, some reward tokens get stuck in the contract and no one can retrieve them. An attacker could cause this by making the total shares zero, for example by disabling a validator.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.