sherlock-audit / 2024-05-kwenta-x-perennial-integration-update-judging

5 stars 3 forks source link

Informational 07 currentPosition Check #44

Closed sherlock-admin2 closed 5 months ago

sherlock-admin2 commented 5 months ago

Informational 07 currentPosition Check

Low/Info issue submitted by 1337web3

Summary

The collateral calculation in the given code snippet appears to be inconsistent. The order.execute() function returns a value different than 0 only if the parameter passed to it is equal to 3. Calling the function without a check whether the parameter is equal to 3 leads to bigger gas costs without any added value.

Vulnerability Detail

The collateral value is consistently 0 unless the side is 3.

https://github.com/sherlock-audit/2024-05-kwenta-x-perennial-integration-update/blob/main/perennial-v2/packages/perennial-extensions/contracts/MultiInvoker.sol#L392

Impact

The collateral calculation logic may lead to bigger gas costs without any added value.

Code Snippet

Fixed6 collateral = order.execute(currentPosition);

Tool used

Manual Review

Recommendation

Review and clarify the logic for collateral calculation to ensure consistency and accuracy. Consider revising the code to explicitly handle cases where currentPosition is not 3 to avoid confusion and potential errors. A check whether currentPosition is equal to 3 may be added:

Fixed6 collateral = currentPosition == 3 ? order.execute(currentPosition) ? Fixed6Lib.ZERO;