Skip to content
Business logic Audit finding Intermediate

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.

xYrYuYx Follow

Originally disclosed on Code4rena

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 totalGlobalShares becomes 0 and 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 disableValidator the warden was able to lock funds, making them irredemeable

It seems to me that this is caused by the fact that unstake as well as disableValidator will 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 disableValidator would allow them to claim those shares.

The function disableValidator can be called by either the validator or the owner, while onlyOwner can add a new validator

The 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)

The original report as published on Code4rena, by xYrYuYx. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Disable a validator to make totalGlobalShares zero.
  2. Mine blocks to accumulate rewards.
  3. 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.

More by xYrYuYx

View all

3 more disclosed reports, best first.

More from Covalent contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.