Bid submission vulnerable to market parameters changes
The details for the audit state:\\nMarket owners should NOT be able to race-condition attack borrowers or lenders by changing market settings while bids are being submitted or accepted (while tx are in mempool). Care has been taken to ensure that this is not possible (similar in theory to sandwich attacking but worse as if possible it could cause unexpected and non-consentual interest rate on a loan) and further-auditing of this is welcome.\\nHowever, there is little protection in place to protect the submitter of a bid from changes in market parameters.\\nIn _submitBid(), certain bid parameters are taken from the marketRegistry:\\n```\\n    function _submitBid(// rest of code)\\n        // rest of code\\n        (bid.terms.paymentCycle, bidPaymentCycleType[bidId]) = marketRegistry\\n            .getPaymentCycle(_marketplaceId);\\n\\n        bid.terms.APR = _APR;\\n\\n        bidDefaultDuration[bidId] = marketRegistry.getPaymentDefaultDuration(\\n            _marketplaceId\\n        );\\n\\n        bidExpirationTime[bidId] = marketRegistry.getBidExpirationTime(\\n            _marketplaceId\\n        );\\n\\n        bid.paymentType = marketRegistry.getPaymentType(_marketplaceId);\\n        \\n        bid.terms.paymentCycleAmount = V2Calculations\\n            .calculatePaymentCycleAmount(\\n                bid.paymentType,\\n                bidPaymentCycleType[bidId],\\n                _principal,\\n                _duration,\\n                bid.terms.paymentCycle,\\n                _APR\\n            );\\n        // rest of code\\n```\\n
Take every single parameters as input of `_submitBid()` (including fee percents) and compare them to the values in `marketRegistry` to make sure borrower agrees with them, revert if they differ.
If market parameters are changed in between the borrower submitting a bid transaction and the transaction being applied, borrower may be subject to changes in `bidDefaultDuration`, `bidExpirationTime`, `paymentType`, `paymentCycle`, `bidPaymentCycleType` and `paymentCycleAmount`.\\nThat is, the user may be committed to the bid for longer / shorter than expected. They may have a longer / shorter default duration (time for the loan being considered defaulted / eligible for liquidation). They have un-provisioned for payment type and cycle parameters.\\nI believe most of this will have a medium impact on borrower (mild inconveniences / resolvable by directly repaying the loan) if the market owner is not evil and adapting the parameters reasonably.\\nAn evil market owner can set the value of `bidDefaultDuration` and `paymentCycle` very low (0) so that the loan will default immediately. It can then accept the bid, make user default immediately, and liquidate the loan to steal the user's collateral. This results in a loss of collateral for the borrower.
```\\n    function _submitBid(// rest of code)\\n        // rest of code\\n        (bid.terms.paymentCycle, bidPaymentCycleType[bidId]) = marketRegistry\\n            .getPaymentCycle(_marketplaceId);\\n\\n        bid.terms.APR = _APR;\\n\\n        bidDefaultDuration[bidId] = marketRegistry.getPaymentDefaultDuration(\\n            _marketplaceId\\n        );\\n\\n        bidExpirationTime[bidId] = marketRegistry.getBidExpirationTime(\\n            _marketplaceId\\n        );\\n\\n        bid.paymentType = marketRegistry.getPaymentType(_marketplaceId);\\n        \\n        bid.terms.paymentCycleAmount = V2Calculations\\n            .calculatePaymentCycleAmount(\\n                bid.paymentType,\\n                bidPaymentCycleType[bidId],\\n                _principal,\\n                _duration,\\n                bid.terms.paymentCycle,\\n                _APR\\n            );\\n        // rest of code\\n```\\n