MEDIUM severity: The vulnerability is related to the handling of empty orders in the `market.update` function. When a. The vulnerability is related to the handling of empty orders in the `market.update` function. When an empty order is processed, the oracle version is not requested, and during the settlement process, an invalid oracle version with a price of 0 is used. This can lead to incorrect accounting of fees a...

Vulnerable code:
```\nif (!newOrder.isEmpty()):\n    oracle.request(IMarket(this), account)\n```\n```\nfunction isEmpty(Order memory self) internal pure returns (bool) {\n    return pos(self).isZero() && neg(self).isZero();\n}\n\nfunction pos(Order memory self) internal pure returns (UFixed6) {\n    return \n        self.makerPos.add(self.longPos).add(self.shortPos);\n}\n\nfunction neg(Order memory self) internal pure returns (UFixed6) {\n    return \n        self.makerNeg.add(self.longNeg).add(self.shortNeg);\n}\n```\n```\nfunction _processOrderGlobal(\n    Context memory context,\n    SettlementContext memory settlementContext,\n    uint256 newOrderId,\n    Order memory newOrder\n) private {\n    OracleVersion memory oracleVersion = oracle.at(newOrder.timestamp);\n\n    context.pending.global.sub(newOrder);\n    if (!oracleVersion.valid) {\n        newOrder.invalidate();\n    }\n\n    VersionAccumulationResult memory accumulationResult;\n    (\n        settlementContext.latestVersion,\n        context.global,\n        accumulationResult\n    ) = VersionLib.accumulate(\n        settlementContext.latestVersion,\n        context.global,\n        context.latestPosition.global,\n        newOrder,\n        settlementContext.orderOracleVersion,\n        oracleVersion,\n        context.marketParameter,\n        context.riskParameter\n    );\n```\n```\nfunction _accumulateLinearFee(\n    Version memory next,\n    AccumulationContext memory context,\n    VersionAccumulationResult memory result\n) private pure {\n    (\n        UFixed6 makerLinearFee,\n        UFixed6 makerSubtractiveFee\n    ) = _accumulateSubtractiveFee(\n        context.riskParameter.makerFee.linear(\n            Fixed6Lib.from(context.order.makerTotal()),\n            context.toOracleVersion.price.abs()\n        ),\n        context.order.makerTotal(),\n        context.order.makerReferral,\n        next.makerLinearFee\n    );\n\n    // Compute maker linear fee\n    makerLinearFee = makerLinearFee.add(makerSubtractiveFee);\n\n    // Compute long-short funding rate\n    Fixed6 funding = context.global.pAccumulator.accumulate(\n        context.riskParameter.pController,\n        toSkew.unsafeDiv(Fixed6Lib.from(context.riskParameter.takerFee.scale)).min(Fixed6Lib.ONE).max(Fixed6Lib.NEG_ONE),\n        context.fromOracleVersion.timestamp,\n        context.toOracleVersion.timestamp,\n        context.fromPosition.takerSocialized().mul(context.fromOracleVersion.price.abs())\n    );\n\n    // Compute interest\n    _accumulateInterest(\n        next,\n        context\n    );\n}\n\nfunction _accumulateInterest(\n    Version memory next,\n    AccumulationContext memory context\n) private pure returns (Fixed6 interestMaker, Fixed6 interestLong, Fixed6 interestShort, UFixed6 interestFee) {\n    UFixed6 notional = context.fromPosition.long.add(context.fromPosition.short).min(context.fromPosition.maker).mul(context.fromOracleVersion.price.abs());\n\n    // Compute interest maker\n    Fixed6 interestMaker = notional.mul(context.riskParameter.makerFee.scale);\n\n    // Compute interest long\n    Fixed6 interestLong = notional.mul(context.riskParameter.longFee.scale);\n\n    // Compute interest short\n    Fixed6 interestShort = notional.mul(context.riskParameter.shortFee.scale);\n\n    // Compute interest fee\n    UFixed6 interestFee = notional.mul(context.riskParameter.interestFee.scale);\n}\n```\n```\nfunction _settle(IMarket market, address account) private {\n    market.update(\n        account,\n        UFixed6Lib.MAX,\n        UFixed6Lib.MAX,\n        UFixed6Lib.MAX,\n        Fixed6Lib.ZERO,\n        false\n    );\n}\n```\n```\nit('no fees accumulation due to invalid version with price = 0', async () => {\n\n    function setupOracle(price: string, timestamp: number, nextTimestamp: number) {\n        const oracleVersion = {\n            price: parse6decimal(price),\n            timestamp: timestamp,\n            valid: true,\n        };\n        oracle.at.whenCalledWith(oracleVersion.timestamp).returns(oracleVersion);\n        oracle.status.returns([oracleVersion, nextTimestamp]);\n        oracle.request.returns();\n    }\n\n    function setupOracleAt(price: string, valid: boolean, timestamp: number) {\n        const oracleVersion = {\n            price: parse6decimal(price),\n            timestamp: timestamp,\n            valid: valid,\n        };\n        oracle.at.whenCalledWith(oracleVersion.timestamp).returns(oracleVersion);\n    }\n\n    const riskParameter = await market.riskParameter();\n    const riskParameterMakerFee = {\n        linearFee: parse6decimal('0.005'),\n        proportionalFee: parse6decimal('0.0025'),\n        adiabaticFee: parse6decimal('0.01'),\n    };\n    riskParameter.makerFee = riskParameterMakerFee;\n    const riskParameterTakerFee = {\n        linearFee: parse6decimal('0.005'),\n        proportionalFee: parse6decimal('0.0025'),\n        adiabaticFee: parse6decimal('0.01'),\n    };\n    riskParameter.takerFee = riskParameterTakerFee;\n    await market.connect(owner).updateRiskParameter(riskParameter);\n\n    dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true);\n    dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true);\n\n    setupOracle('100', TIMESTAMP, TIMESTAMP + 100);\n\n    await market\n       .connect(user)\n        ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false);\n    await market\n       .connect(userB)\n        ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION, 0, COLLATERAL, false);\n\n    setupOracle('100', TIMESTAMP + 100, TIMESTAMP + 200);\n    await market\n       .connect(user)\n        ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0,\n```\n```\nversion 200: \n    longValue: -318\n    makerValue: 285\n\nversion 300: \n    longValue: -100000637\n    makerValue: 100500571\n\nversion 400: \n    longValue: -637\n    makerValue: 571\n```