Root + Impact
Description
In the amendSellOrder
function, there is no time interval limit for modifying the SellOrder! If there are no buyers, the seller can repeatedly amend the newDeadlineDuration
, causing the sell order’s validity to be extended indefinitely (3 days + 3 days + 3 days + ...
). This bypasses the MAX_DEADLINE_DURATION
limit on the SellOrder and breaks the intended functionality of the protocol!
@> uint256 public constant MAX_DEADLINE_DURATION = 3 days;
function amendSellOrder(
uint256 _orderId,
uint256 _newAmountToSell,
uint256 _newPriceInUSDC,
@> uint256 _newDeadlineDuration
) public {
...
...
@> if (_newDeadlineDuration == 0 || _newDeadlineDuration > MAX_DEADLINE_DURATION) revert InvalidDeadline();
...
...
@> order.deadlineTimestamp = newDeadlineTimestamp;
emit OrderAmended(_orderId, _newAmountToSell, _newPriceInUSDC, newDeadlineTimestamp);
}
Risk
Likelihood:
Impact:
Proof of Concept
function test_newDeadlineDuration() public {
vm.startPrank(alice);
wbtc.approve(address(book), 2e8);
uint256 aliceId = book.createSellOrder(address(wbtc), 2e8, 180_000e6, 3 days);
string memory aliceOrderDetails_1 = book.getOrderDetailsString(aliceId);
console2.log(aliceOrderDetails_1);
vm.stopPrank();
vm.warp(block.timestamp + 3 days - 1);
vm.prank(alice);
book.amendSellOrder(aliceId, 1.75e8, 175_000e6, 3 days);
string memory aliceOrderDetails_2 = book.getOrderDetailsString(aliceId);
console2.log(aliceOrderDetails_2);
vm.warp(block.timestamp + 3 days - 1);
vm.prank(alice);
book.amendSellOrder(aliceId, 1.75e8, 175_000e6, 3 days);
string memory aliceOrderDetails_3 = book.getOrderDetailsString(aliceId);
console2.log(aliceOrderDetails_3);
}
Output:
[PASS] test_newDeadlineDuration() (gas: 329879)
Logs:
Order ID: 1
Seller: 0xaf6db259343d020e372f4ab69cad536aaf79d0ac
Selling: 200000000 wBTC
Asking Price: 180000000000 USDC
@> Deadline Timestamp: 259201
Status: Active
Order ID: 1
Seller: 0xaf6db259343d020e372f4ab69cad536aaf79d0ac
Selling: 175000000 wBTC
Asking Price: 175000000000 USDC
@> Deadline Timestamp: 518400
Status: Active
Order ID: 1
Seller: 0xaf6db259343d020e372f4ab69cad536aaf79d0ac
Selling: 175000000 wBTC
Asking Price: 175000000000 USDC
@> Deadline Timestamp: 777599
Status: Active
Recommended Mitigation
Set a total validity period to prevent the SellOrder from remaining valid indefinitely.
Add a time interval for the amendSellOrder
function to prevent continuous modifications in a short period.