HardhatDeFi
15,000 USDC
View results
Submission Details
Severity: low
Invalid

Redundant mapping call in `AaveDIVAWrapperCore::_createContingentPool` causing gas inefficiency and reducing code readability

Summary

When create contingent pool in the function AaveDIVAWrapperCore::createContingentPool, the contract retrieves the _wToken twice from _collateralTokenToWToken mapping instead of using the already-declared _wToken variable.

This redundant mapping call increases gas costs and reduces code readability, as the _wToken has already been assigned earlier in the function.

Vulnerability Details

In the function AaveDIVAWrapperCore::_createContingentPool, the _wToken is correctly retrieved and stored at the beginning:

address _wToken = _collateralTokenToWToken[_poolParams.collateralToken];

However, when calling IDIVA.createContingentPool, the function fetches the same mapping again instead of using _wToken:

// Create pool on DIVA Protocol using the wToken as collateral.
bytes32 _poolId = IDIVA(_diva).createContingentPool(
IDIVA.PoolParams({
referenceAsset: _poolParams.referenceAsset,
expiryTime: _poolParams.expiryTime,
floor: _poolParams.floor,
inflection: _poolParams.inflection,
cap: _poolParams.cap,
gradient: _poolParams.gradient,
collateralAmount: _poolParams.collateralAmount,
@> collateralToken: _collateralTokenToWToken[
_poolParams.collateralToken
], // Using the address of the wToken here
dataProvider: _poolParams.dataProvider,
capacity: _poolParams.capacity,
longRecipient: _poolParams.longRecipient,
shortRecipient: _poolParams.shortRecipient,
permissionedERC721Token: _poolParams.permissionedERC721Token
})
);

Instead, it should directly use _wToken, avoiding unnecessary gas consumption and making the code cleaner.

Impact

Reduces code clarity and wastes unnecessary gas.

Tools Used

Manual review.

Recommendations

Consider using _wToken variable instead of calling _collateralTokenToWToken again.

// Create pool on DIVA Protocol using the wToken as collateral.
bytes32 _poolId = IDIVA(_diva).createContingentPool(
IDIVA.PoolParams({
referenceAsset: _poolParams.referenceAsset,
expiryTime: _poolParams.expiryTime,
floor: _poolParams.floor,
inflection: _poolParams.inflection,
cap: _poolParams.cap,
gradient: _poolParams.gradient,
collateralAmount: _poolParams.collateralAmount,
+ collateralToken: _wToken, // Use stored value instead of redundant lookup
- collateralToken: _collateralTokenToWToken[
- _poolParams.collateralToken
- ], // Using the address of the wToken here
dataProvider: _poolParams.dataProvider,
capacity: _poolParams.capacity,
longRecipient: _poolParams.longRecipient,
shortRecipient: _poolParams.shortRecipient,
permissionedERC721Token: _poolParams.permissionedERC721Token
})
);
Updates

Lead Judging Commences

bube Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.