CORIONplatform / solidity

GNU General Public License v3.0
12 stars 9 forks source link

Possible Denial of Service in exchange.sol instantTradeScanOrders #80

Closed pyskell closed 7 years ago

pyskell commented 7 years ago

The code for finding matching trade orders relies on the following loop:

for ( uint256 a=0 ; a<pos[currentRate].orders.length ; a++ ){
// Lots of logic
}

This can theoretically be DoS'd via placing lots of sell orders for very small amounts of COR at very high rates. After enough of these sell orders are placed the contents of pos[] would become too large to iterate over. Additionally since it always starts at position 0 then this is particularly vulnerable to a DoS from the first person to start selling in the contract.

Example DoS code:

for ( uint256 i=1; i<2**256 ; a++ ){
contract.sell(false, i/2**18, false, 2**18);

// Could use even smaller amounts of i/2**24 I think as COR is denominated in a very small amount.
}

Some possibilities to consider:

Dexaran commented 7 years ago

It is also possible to avoid automated order trading.

In this case user can place an order and order placement will trigger a specified event. User should manually choose an order that he wants to fill when he is going to make a trade. Also it should be done by the UI. UI can filter a list of current orders and select more relevant orders when the user wants to make a trade.