code-423n4 / 2022-06-infinity-findings

4 stars 0 forks source link

getCurrentPrice will be return a higher value than expected due to insufficient check in isTimeValid #316

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Lines of code

https://github.com/code-423n4/2022-06-infinity/blob/main/contracts/core/InfinityOrderBookComplication.sol#L175-L178

Vulnerability details

https://github.com/code-423n4/2022-06-infinity/blob/main/contracts/core/InfinityOrderBookComplication.sol#L175-L178

The Boolean value will always return true if start price is zero. The condition will be sufficiently fulfilled since a time will be set in the future but no time is set in the past or at current time:

https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityOrderBookComplication.sol#L38

_sumCurrentPrices() uses the returned value of getCurrentPrice() which contains the calculation logic. The price diff will always be higher when elapsed startPrice.

https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityOrderBookComplication.sol#L340

Therefore, if all the orders are endPrices or a mixture of endPrices that is greater than the startPrice then:

https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityOrderBookComplication.sol#L321

will be higher.

Similar function :

https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L1164

Will also affect :

https://github.com/code-423n4/2022-06-infinity/blob/main/contracts/core/InfinityExchange.sol#L352-L354

therefore, execution price passed to takeOrders() will be higher.

https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L628

https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L656

Check that constraints[3] is != 0.

nneverlander commented 2 years ago

Minor

HardlyDifficult commented 2 years ago

The impact from this report is not explained well enough to judge the severity. Closing as invalid.