Some state variables or custom error never been used inside BriVault , it will increase gas cost at deployment time
Description
-
stakedAmount, totalAssetsShares, and error notRegistered() are unused state variables and custom error it doesn't severely disrupt the protocol logic or functionality
-
Howeverunused state variables or custom error leads to increasing gas amount during deployment time
uint256 public participationFeeBsp;
uint256 constant BASE = 10000;
uint256 constant PARTICIPATIONFEEBSPMAX = 300;
@dev participationFee address
*/
address private participationFeeAddress;
uint256 public eventStartDate;
uint256 public eventEndDate;
@> uint256 public stakedAmount;
@> uint256 public totalAssetsShares;
string public winner;
uint256 public finalizedVaultAsset;
uint256 public totalWinnerShares;
uint256 public totalParticipantShares;
bool public _setWinner;
uint256 public winnerCountryId;
error eventStarted();
error lowFeeAndAmount();
error invalidCountry();
error eventNotEnded();
error didNotWin();
@> error notRegistered();
error winnerNotSet();
error noDeposit();
error eventNotStarted();
error WinnerAlreadySet();
error limiteExceede();
Risk
Likelihood:
Impact:
Proof of Concept
function test_deployBefore() public{
vm.startPrank(owner);
briVault = new BriVault(
IERC20(address(mockToken)),
participationFeeBsp,
eventStartDate,
participationFeeAddress,
minimumAmount,
eventEndDate
);
vm.stopPrank();
}
[PASS] test_deployBefore() (gas: 3533536)
function test_deployAfter() public{
vm.startPrank(owner);
briVault = new BriVault(
IERC20(address(mockToken)),
participationFeeBsp,
eventStartDate,
participationFeeAddress,
minimumAmount,
eventEndDate
);
vm.stopPrank();
}
[PASS] test_deployAfter() (gas: 3508205)
3533536 > 3508205
Recommended Mitigation
If these variables are not used in the future or to support another protocol, it is recommended to remove it
//variables
uint256 public participationFeeBsp;
uint256 constant BASE = 10000;
uint256 constant PARTICIPATIONFEEBSPMAX = 300;
/**
@dev participationFee address
*/
address private participationFeeAddress;
uint256 public eventStartDate;
uint256 public eventEndDate;
- uint256 public stakedAmount;
- uint256 public totalAssetsShares;
string public winner;
uint256 public finalizedVaultAsset;
uint256 public totalWinnerShares;
uint256 public totalParticipantShares;
bool public _setWinner;
uint256 public winnerCountryId;
// Error Logs
error eventStarted();
error lowFeeAndAmount();
error invalidCountry();
error eventNotEnded();
error didNotWin();
- error notRegistered();
error winnerNotSet();
error noDeposit();
error eventNotStarted();
error WinnerAlreadySet();
error limiteExceede();