Submitted by rbserver, also found by volodya.
Calling the following Position._marketSell function calls rubiconMarket.sellAllAmount(ERC20(_asset), _payAmount, ERC20(_quote), _minFill), where _minFill does not include _fee.
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/poolsUtility/Position.sol#L475-L511
Calling the following RubiconMarket.sellAllAmount function then executes require(fill_amt >= min_fill_amount, "min_fill_amount isn't filled"). In contrast to min_fill_amount, which is the Position._marketSell functions _minFill that does not include _fee, fill_amt used in this require statement includes the fee. This means that fill_amt is very likely to be bigger than min_fill_amount, which makes this require statement and the corresponding slippage control not effective. In fact, as shown by the POC below, the fill_amt with the fee deducted that is set by calling calcAmountAfterFee(fill_amt) can equal min_fill_amount, which also proves that the fill_amt, which includes the fee, would be larger than min_fill_amount that does not include fee, and improperly comparing these two in the require statement would only result in an ineffective slippage control.
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/RubiconMarket.sol#L1028-L1067
First, please update the Position._marketSell function as follows to divide by 100_000 for the POC purpose. This is for fixing the bug mentioned in the report titled Calling Position._marketBuy and Position._marketSell functions that calculate _fee by dividing by 10000 can cause incorrect calculations.
Second, please update the RubiconMarket.sellAllAmount function as follows to log min_fill_amount, the fill_amt that includes fee, and the fill_amt with the fee deducted for the POC purpose.
Third, please add the following Calling Position._marketSell function compares fill_amt that includes fee to min_fill_amount that does not include fee test in the Long positions describe block in test\hardhat-tests\leverage-wrapper.ts. This test will pass to print the logs below for demonstrating the described scenario:
VSCode
The Position._marketSell function can be updated to call rubiconMarket.sellAllAmount(ERC20(_asset), _payAmount, ERC20(_quote), _minFill.add(_fee)) instead of rubiconMarket.sellAllAmount(ERC20(_asset), _payAmount, ERC20(_quote), _minFill).
HickupHH3 (judge) commented:
