Set tokens will be updated incorrectly #214
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
Index
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Lines of code
https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L664
https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L670
Vulnerability details
Medium
Set tokens will be updated incorrectly
Although the functions doesn't utilise the other returned arguments, it will still impact values used elsewhere.
https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L664
https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/index-coop-notional-trade-module/contracts/protocol/modules/v1/NotionalTradeModule.sol#L670
For the above mentioned functions, their calculations is as a result of an erroneous calculation of the pre and post notional values,
The comment below stipulates:
https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/index-coop-notional-trade-module/contracts/protocol/lib/Position.sol#L255
but it uses the prePosition unit :
https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/index-coop-notional-trade-module/contracts/protocol/lib/Position.sol#L216
instead of the _postTotalNotional.
Also, the returned value of position unit can be zero if it's the first time the component is being added, this is so because the default position is the last thing that gets edited in calculateAndEditDefaultPosition() but the value is used prior to its modification :
https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/index-coop-notional-trade-module/contracts/protocol/lib/Position.sol#L109
Recommendation
As per the comment on line 255 of calculateDefaultEditPositionUnit(), use the postTotalNotional as the subtrahend.
The text was updated successfully, but these errors were encountered: