Vulnerability: Combining shorts can incorrectly reset the shorts flag
Severity: medium

Description:
The protocol allows users to combine multiple short positions into one as long as the combined short stays above the primary collateral ratio. The function is also able to reset an active flag from any of the combined shorts if the final ratio is above the primaryLiquidationCR.\\nThe issue is that the combineShorts function does not call updateErcDebt, which is called in every other function that is able to reset a shorts flag. This means that if the debt is outdated the final combined short could incorrectly reset the flag putting the position on a healthy ratio when it really isn't. This would also mean that it will have to be reflagged and go through the timer again before it can be liquidated.\\nThe combine shorts function merges all short records into the short at position id[0]. Focusing on the debt aspect it adds up the total debt and calculates the ercDebtSocialized of all positions except for the first.\\n```\\n      {\\n      uint88 currentShortCollateral = currentShort.collateral;\\n      uint88 currentShortErcDebt = currentShort.ercDebt;\\n      collateral += currentShortCollateral;\\n      ercDebt += currentShortErcDebt;\\n      yield += currentShortCollateral.mul(currentShort.zethYieldRate);\\n      ercDebtSocialized += currentShortErcDebt.mul(currentShort.ercDebtRate);\\n      }\\n```\\n\\nIt then merges this total to the first position using the merge function and this will give us the combined short.\\n```\\n// Merge all short records into the short at position id[0]\\n        firstShort.merge(ercDebt, ercDebtSocialized, collateral, yield, c.shortUpdatedAt);\\n```\\n\\nFinally we check if the position had an active flag and if it did, we check if the new combined short is in a healthy enough state to reset the flag, if not the whole function reverts.\\n```\\n        // If at least one short was flagged, ensure resulting c-ratio > primaryLiquidationCR\\n        if (c.shortFlagExists) {\\n            if (\\n                firstShort.getCollateralRatioSpotPrice(\\n                    LibOracle.getSavedOrSpotOraclePrice(_asset)\\n                ) < LibAsset.primaryLiquidationCR(_asset)\\n            ) revert Errors.InsufficientCollateral();\\n            // Resulting combined short has sufficient c-ratio to remove flag\\n            firstShort.resetFlag();\\n        }\\n```\\n\\nAs you can see the updateErcDebt function is not called anywhere in the function meaning the flag could be reset with outdated values.

Impact:
A short could have its flag incorrectly reset and reset the timer. This is not good for the protocol as it will have a unhealthy short for a longer time.

Recommended mitigation:
Call updateErcDebt on the short once it is combined in the combineShorts function to ensure the collateral ratio is calculated with the most up to date values.\\n```\\n    function combineShorts(address asset, uint8[] memory ids)\\n        external\\n        isNotFrozen(asset)\\n        nonReentrant\\n        onlyValidShortRecord(asset, msg.sender, ids[0])\\n    {\\n        // Initial code\\n\\n        // Merge all short records into the short at position id[0]\\n        firstShort.merge(ercDebt, ercDebtSocialized, collateral, yield, c.shortUpdatedAt);\\n\\n        firstShort.updateErcDebt(asset); // update debt here before checking flag\\n\\n        // If at least one short was flagged, ensure resulting c-ratio > primaryLiquidationCR\\n        if (c.shortFlagExists) {\\n            if (\\n                firstShort.getCollateralRatioSpotPrice(\\n                    LibOracle.getSavedOrSpotOraclePrice(_asset)\\n                ) < LibAsset.primaryLiquidationCR(_asset)\\n            ) revert Errors.InsufficientCollateral();\\n            // Resulting combined short has sufficient c-ratio to remove flag\\n            firstShort.resetFlag();\\n        }\\n        emit Events.CombineShorts(asset, msg.sender, ids);\\n    }\\n```\\n