Open hats-bug-reporter[bot] opened 2 months ago
That code snippet makes it look like it doesn't approve an unlimited amount.
Yeah, the report and code snippet are contradicting themselves. It only approve the amount of tokens which will be transferred in splitPosition
.
Github username: -- Twitter username: -- Submission hash (on-chain): 0xac22b432f475565c9ca28e80fa970c0b30d912cf334aec73ee9b521fe07c2129 Severity: medium
Description:
Details
The Router contract contains a potential vulnerability related to unlimited token approvals in its
_splitPosition
function. This issue could expose users to unnecessary risk if the contract is compromised or contains bugs.In the
_splitPosition
function, the contract approves an unlimited amount of collateral tokens to be spent by the ConditionalTokens contract. This approval is not revoked after the operation, leaving it open for potential misuse.Code Snippet
Impact
If the ConditionalTokens contract is compromised or contains bugs, it could potentially spend more of the user's collateral tokens than intended. This could lead to:
The severity of this vulnerability is high, as it doesn't immediately lead to fund loss but creates a significant risk if other parts of the system are compromised.
Steps to Reproduce
splitPosition
with a certain amount of collateral tokens.splitPosition
will not change this unlimited approval.Fix
Implement a pattern of approving only the necessary amount and then resetting the approval to zero after the operation. This can be achieved by:
SafeERC20
library, which providessafeApprove
andsafeIncreaseAllowance
functions to handle approvals more safely.Proof of Concept
Here's what the test is doing:
createMarketAndSplitPosition
helper function.