The _getRequiredCollateralSingleLegPartner function in the CollateralTracker contract has a logic path where the required variable may remain unassigned. Specifically, if isLong != tokenId.isLong(partnerIndex) is true and isLong == 0, the function does not assign a value to required. This can lead to uninitialized variables being used, causing unexpected behavior or vulnerabilities in the contract. Uninitialized variables can result in incorrect collateral calculations, potentially affecting the security and stability of the entire collateral management system.
Lines of code
https://github.com/code-423n4/2024-06-panoptic/blob/main/contracts/CollateralTracker.sol#L1445
Vulnerability details
Impact
The
_getRequiredCollateralSingleLegPartner
function in theCollateralTracker
contract has a logic path where therequired
variable may remain unassigned. Specifically, ifisLong != tokenId.isLong(partnerIndex)
is true andisLong == 0
, the function does not assign a value torequired
. This can lead to uninitialized variables being used, causing unexpected behavior or vulnerabilities in the contract. Uninitialized variables can result in incorrect collateral calculations, potentially affecting the security and stability of the entire collateral management system.Proof of Concept
Line of Code:
Proof:
Here's a scenario illustrating the issue:
isLong
is0
.tokenId.isLong(partnerIndex)
is1
.if (isLong != tokenId.isLong(partnerIndex))
is true.isLong == 0
, the innerif (isLong == 1)
is false, leading to no assignment forrequired
.This results in
required
being uninitialized, which can cause erroneous behavior when this variable is later used.Tools Used
Manual
Recommended Mitigation Steps
Ensure that all code paths in
_getRequiredCollateralSingleLegPartner
assign a value to therequired
variable.This ensures that the
required
variable is always assigned a value, preventing uninitialized variables from causing issues in the contract.Assessed type
Context