Skip to content

setEpochDuration() breaks the user's expected exchangeRate #83

Description

@code423n4

Lines of code

https://github.com/code-423n4/2023-01-ondo/blob/f3426e5b6b4561e09460b2e6471eb694efdd6c70/contracts/cash/CashManager.sol#L546-L552

Vulnerability details

Impact

Extended epoch time, resulting in exchangeRate changes that affect user revenue

Proof of Concept

MANAGER_ADMIN can modify epochDuration with setEpochDuration()
epochDuration is an important factor in the calculation of whether to enter a new epoch

However, setEpochDuration() does not first perform an updateEpoch (if it needs to be currently satisfied to enter a new epoch, it enters a new epoch)
As a result, it may not be possible to switch to the new epoch because the epochDuration has grown, and the old epoch is still used.

As each epoch will have its own exchangeRate, the user has already estimated the exchangeRate before the end of the epoch, so the requestMint() is performed.
Since setEpochDuration changed the epochDuration, the exchangeRate changed. when exchangeRate changes ,maybe affect user revenue

So it is recommended to calculate the old epochDuration for the elapsed time to get the correct exchangeRate

Tools Used

Recommended Mitigation Steps

add updateEpoch

  function setEpochDuration(
    uint256 _epochDuration
- ) external onlyRole(MANAGER_ADMIN) {
+ ) external updateEpoch onlyRole(MANAGER_ADMIN) {
    uint256 oldEpochDuration = epochDuration;
    epochDuration = _epochDuration;
    emit EpochDurationSet(oldEpochDuration, _epochDuration);
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    2 (Med Risk)Assets not at direct risk, but function/availability of the protocol could be impacted or leak valuebugSomething isn't workingduplicate-205satisfactorysatisfies C4 submission criteria; eligible for awardssponsor confirmedSponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions