Summary
The code comments in interface definition of IPremarket.sol#CreateOfferParams state that CollateralRate
MUST BE GREATER THAN 10_000 , however , the code only ensures if it is not less than 10_000, leaving room for erroneous offers creation at the exact rate of 10_000 or 100% that will affect future integrations and development due developer's assumptions being wrong.
Vulnerability Details
Here are the code blocks that might be helpful to visualize and understand the issue
`IPreMarket.sol`
* @title
* @notice
* @param
* @param
* @param
* @param collateralRate the collateral rate of offer. must be greater than 100%. decimal is 10000.
* @param
* @param
* @param
*/
struct CreateOfferParams {
address marketPlace;
address tokenAddress;
uint256 points;
uint256 amount;
uint256 collateralRate;
uint256 eachTradeTax;
OfferType offerType;
OfferSettleType offerSettleType;
}
`PreMarket.sol`
function createOffer(CreateOfferParams calldata params) external payable {
if (params.collateralRate < Constants.COLLATERAL_RATE_DECIMAL_SCALER) {
revert InvalidCollateralRate();
}
Proof of Concept
function test_create_offer_for_100_percent_collateralRate() public {
vm.startPrank(user);
preMarktes.createOffer(
CreateOfferParams(
marketPlace,
address(mockUSDCToken),
1000,
0.01 * 1e18,
10_000,
300,
OfferType.Ask,
OfferSettleType.Turbo
)
);
}
PoC Output
Ran 1 test for test/PreMarkets.t.sol:PreMarketsTest
[PASS] test_create_offer_for_100_percent_collateralRate() (gas: 540691)
Traces:
[540691] PreMarketsTest::test_create_offer_for_100_percent_collateralRate()
├─ [0] VM::startPrank(0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf)
│ └─ ← [Return]
├─ [525720] UpgradeableProxy::createOffer(CreateOfferParams({ marketPlace: 0xE6b1c25C9BAC2B628d6E2d231F9B53b92172fC2D, tokenAddress: 0xF62849F9A0B5Bf2913b396098F7c7019b51A820a, points: 1000, amount: 10000000000000000 [1e16], collateralRate: 10000 [1e4], eachTradeTax: 300, offerType: 0, offerSettleType: 1 }))
│ ├─ [520669] PreMarktes::createOffer(CreateOfferParams({ marketPlace: 0xE6b1c25C9BAC2B628d6E2d231F9B53b92172fC2D, tokenAddress: 0xF62849F9A0B5Bf2913b396098F7c7019b51A820a, points: 1000, amount: 10000000000000000 [1e16], collateralRate: 10000 [1e4], eachTradeTax: 300, offerType: 0, offerSettleType: 1 })) [delegatecall]
Impact
Offers with wrong collateral rate will be created , jeopardising Current and Future developments + Integrations with the protocol
Tools Used
Manual Review , Foundry
Recommendations
Ensure that in CreateOffer inside PreMarket , the collateralRate needs to be more than 10_000
function createOffer(CreateOfferParams calldata params) external payable {\
if (params.collateralRate <== Constants.COLLATERAL_RATE_DECIMAL_SCALER) {
revert InvalidCollateralRate();
}