TangibleTNFT / baskets-foundry

baskets-foundry
2 stars 0 forks source link

[VRF-01C] Potential Optimization of Variable Mutability #59

Closed chasebrownn closed 9 months ago

chasebrownn commented 9 months ago

VRF-01C: Potential Optimization of Variable Mutability

Type Severity Location
Gas Optimization VRFConsumerBaseV2Upgradeable.sol:L101, L106-L108

Description:

The vrfCoordinator variable is assigned to only once during the contract's initialization flow via VRFConsumerBaseV2Upgradeable::__VRFConsumerBase_init.

Example:

address public vrfCoordinator;

/**
 * @param _vrfCoordinator address of VRFCoordinator contract
 */
function __VRFConsumerBase_init(address _vrfCoordinator) internal onlyInitializing {
  vrfCoordinator = _vrfCoordinator;
}

Recommendation:

We advise the original VRFConsumerBaseV2 implementation of Chainlink to be utilized instead, as it is compatible with upgradeable contracts and makes use of an immutable variable that greatly optimizes read-access gas costs of the coordinator.

Alternatively, we advise the vrfCoordinator variable to be set as immutable and a VRFConsumerBaseV2Upgradeable::constructor to be introduced replacing the VRFConsumerBaseV2Upgradeable::__VRFConsumerBase_init function and thus mimicking the Chainlink implementation.

chasebrownn commented 9 months ago

Acknowledged