CORIONplatform / solidity

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

instantTrade in the exchange contract should be multiple functions, and while loop is unnecessary #78

Closed pyskell closed 7 years ago

pyskell commented 7 years ago

It's very difficult to determine the execution path of the instantTrade function in the exchange contract, it seems to be responsible for the following functionality:

while( left > 0 ) in this function seems to be unnecessary, none of the trading code should require a while loop. Even in the case of instantly trading against the order book (ie. a "market order") the instantTradeScanOrders should be able to provide an array of orders that can be used to fill the order.

Another potential risk with while(left >0) is that the contract can enter an infinite loop and run out of gas if trying to instantly trade an order that does not have a large enough order/trade book to fill it.

Lastly the complexity of this statement is very high and it's very difficult to determine what it will do (break or not) in any given case if ( stop || ( jumpTo == 0 || ( _rateLimit > 0 && ( ( _sell && jumpTo > _rateLimit) || ( ! _sell && jumpTo < _rateLimit) ) ) ) ) { break; }

iFA88 commented 7 years ago

We need a complex function for everything, because we dont have so much "space" while deploy. Exchange is under development, but thank you for reporting!