Fluctuating collateral value during redemption proposal dispute period exposes the redeemer or protocol to potential gains or losses depending on the asset price movement
Audit: 2024-03-dittoeth-findings
Severity: HIGH

# Lines of code

https://github.com/code-423n4/2024-03-dittoeth/blob/91faf46078bb6fe8ce9f55bcb717e5d2d302d22e/contracts/facets/RedemptionFacet.sol#L310
https://github.com/code-423n4/2024-03-dittoeth/blob/91faf46078bb6fe8ce9f55bcb717e5d2d302d22e/contracts/facets/RedemptionFacet.sol#L224


# Vulnerability details

## Impact

When the redeemer submits their candidate `shortRecords`, the collateral is calculated based on the `asset price` (`LibOracle::getPrice`) and the redemption amount:

```solidity
File: RedemptionFacet.sol
056:     function proposeRedemption(
057:         address asset,
058:         MTypes.ProposalInput[] calldata proposalInput,
059:         uint88 redemptionAmount,
060:         uint88 maxRedemptionFee
061:     ) external isNotFrozen(asset) nonReentrant {
...
...
075:         p.oraclePrice = LibOracle.getPrice(p.asset);
...
...
115: 
116:             p.colRedeemed = p.oraclePrice.mulU88(p.amountProposed);
117:             if (p.colRedeemed > currentSR.collateral) {
118:                 p.colRedeemed = currentSR.collateral;
119:             }
```

Additionally, the `timeToDispute` is calculated based on the collateral ratio of the proposals added to the `redeemer's slate`, which can extend up to 6 hours. The issue arises during this period when the `asset price` changes, resulting in inconsistencies in the collateral received in `RedemptionFacet::claimRedemption` or `RedemptionFacet::disputeRedemption`. This exposes the redeemer or protocol to potential gains or losses depending on the asset price movement.

## Proof of Concept

Consider the following scenario:

1. The price is `3000 USD` per `1 ETH`.
2. The redeemer submits some short proposals and waits for the `timeToDispute` to elapse. At the current price, the redeemer would receive `2 ETH` collateral for redeeming `6000 USD` (`0.00033 * 6000 USD = 2 ETH`) when the dispute period ends.
3. However, during the dispute period, the price of ETH increases to `3500 USD` per `1 ETH`.
4. When the `timeToDispute` ends, the redeemer calls `RedemptionFacet::claimRedemption`, receiving collateral calculated using the outdated price (`2 ETH`). However, since the ETH price increased, the correct collateral should be less (`0.00028 * 6000 USD = 1.68 ETH`).
5. Consequently, the redeemer withdraws `2 ETH` with only `6000 USD`, which is incorrect because the currentETH price is `3500 USD`.

The provided test demonstrates that the collateral delivered in `RedemptionFacet::claimRedemption` remains unchanged from the initial calculation in `RedemptionFacet::proposeRedemption`, leading to incorrect collateral distribution if the asset price changes during the dispute period.

```solidity
    // File: test/Redemption.t.sol
    function test_proposeRedemptionCollateralIsNotRecalculated() public {
        //
        address redeemer = address(1212);
        depositUsd(redeemer, DEF_REDEMPTION_AMOUNT);
        depositEth(redeemer, DEFAULT_AMOUNT);
        //
        // 1. Match orders
        fundLimi