Inaccurate settlement reserve accounting
The off-chain accounting of fCash debt or prime cash in the settlement reserve will be inaccurate due to an error when handling the conversion between signed and unsigned integers.\\nEvents will be emitted to reconcile off-chain accounting for the edge condition when leveraged vaults lend at zero interest. This event will be emitted if there is fCash debt or prime cash in the settlement reserve.\\nIn an event where `s.fCashDebtHeldInSettlementReserve > 0` and `s.primeCashHeldInSettlementReserve <= 0`, no event will be emitted. As a result, the off-chain accounting of fCash debt or prime cash in the settlement reserve will be off.\\nThe reason is that since `fCashDebtInReserve` is the negation of `s.fCashDebtHeldInSettlementReserve`, which is an unsigned integer, `fCashDebtInReserve` will always be less than or equal to 0. Therefore, `fCashDebtInReserve` > 0 will always be false and is an unsatisfiable condition.\\n```\\nFile: PrimeRateLib.sol\\n        // This is purely done to fully reconcile off chain accounting with the edge condition where\\n        // leveraged vaults lend at zero interest.\\n        int256 fCashDebtInReserve = -int256(s.fCashDebtHeldInSettlementReserve);\\n        int256 primeCashInReserve = int256(s.primeCashHeldInSettlementReserve);\\n        if (fCashDebtInReserve > 0 || primeCashInReserve > 0) {\\n            int256 settledPrimeCash = convertFromUnderlying(settlementRate, fCashDebtInReserve);\\n            int256 excessCash;\\n            if (primeCashInReserve > settledPrimeCash) {\\n                excessCash = primeCashInReserve - settledPrimeCash;\\n                BalanceHandler.incrementFeeToReserve(currencyId, excessCash);\\n            } \\n\\n            Emitter.emitSettlefCashDebtInReserve(\\n                currencyId, maturity, fCashDebtInReserve, settledPrimeCash, excessCash\\n            );\\n        }\\n```\\n
It is recommended to implement the following fix:\\n```\\n// Remove the line below\\n int256 fCashDebtInReserve = // Remove the line below\\nint256(s.fCashDebtHeldInSettlementReserve);\\n// Add the line below\\n int256 fCashDebtInReserve = int256(s.fCashDebtHeldInSettlementReserve);\\n```\\n
The off-chain accounting of fCash debt or prime cash in the settlement reserve will be inaccurate. Users who rely on inaccurate accounting information to conduct any form of financial transaction will expose themselves to unintended financial risks and make ill-informed decisions.
```\\nFile: PrimeRateLib.sol\\n        // This is purely done to fully reconcile off chain accounting with the edge condition where\\n        // leveraged vaults lend at zero interest.\\n        int256 fCashDebtInReserve = -int256(s.fCashDebtHeldInSettlementReserve);\\n        int256 primeCashInReserve = int256(s.primeCashHeldInSettlementReserve);\\n        if (fCashDebtInReserve > 0 || primeCashInReserve > 0) {\\n            int256 settledPrimeCash = convertFromUnderlying(settlementRate, fCashDebtInReserve);\\n            int256 excessCash;\\n            if (primeCashInReserve > settledPrimeCash) {\\n                excessCash = primeCashInReserve - settledPrimeCash;\\n                BalanceHandler.incrementFeeToReserve(currencyId, excessCash);\\n            } \\n\\n            Emitter.emitSettlefCashDebtInReserve(\\n                currencyId, maturity, fCashDebtInReserve, settledPrimeCash, excessCash\\n            );\\n        }\\n```\\n