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:
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
],
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
})
);