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.
VRF-01C: Potential Optimization of Variable Mutability
Description:
The
vrfCoordinator
variable is assigned to only once during the contract's initialization flow viaVRFConsumerBaseV2Upgradeable::__VRFConsumerBase_init
.Example:
Recommendation:
We advise the original
VRFConsumerBaseV2
implementation of Chainlink to be utilized instead, as it is compatible with upgradeable contracts and makes use of animmutable
variable that greatly optimizes read-access gas costs of the coordinator.Alternatively, we advise the
vrfCoordinator
variable to be set asimmutable
and aVRFConsumerBaseV2Upgradeable::constructor
to be introduced replacing theVRFConsumerBaseV2Upgradeable::__VRFConsumerBase_init
function and thus mimicking the Chainlink implementation.