Omniscia Nuklai Protocol Audit
NuklaiToken Code Style Findings
NuklaiToken Code Style Findings
NTN-01C: Potential Optimization of Variable Mutability
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | NuklaiToken.sol:L12 |
Description:
The _cap
variable is written to only once during the contract's initialization via the NuklaiToken::init
function.
Example:
11// The cap or max total supply of the token.12uint256 private _cap;13
14event BatchMint(address indexed sender, uint256 recipientsLength, uint256 totalValue);15
16constructor() initializer {}17
18function init(string memory name, string memory symbol, address admin, uint256 cap_) public initializer {19 __ERC20_init_unchained(name, symbol);20 __ERC20Snapshot_init_unchained();21 __ERC20Permit_init(name);22 __Pausable_init_unchained();23 __NuklaiToken_init_unchained(cap_);24 // We don't use __ERC20PresetMinterPauser_init_unchained to avoid giving permisions to _msgSender25 require(admin != address(0), "NAI: Admin can't be zero address");26 _setupRole(DEFAULT_ADMIN_ROLE, admin);27 _setupRole(MINTER_ROLE, admin);28 _setupRole(PAUSER_ROLE, admin);29}30
31function __NuklaiToken_init_unchained(uint256 cap_) internal onlyInitializing {32 require(cap_ > 0, "NAI: cap is 0");33 _cap = cap_;34}
Recommendation:
We advise the variable to be set as immutable
and assigned to during the contract's NuklaiToken::constructor
, optimizing its read-access gas cost significantly.
To note, immutable
variables are fully compatible with upgradeable contracts as they are stored directly in the bytecode of the contract. Such a change would also reduce the deployment gas cost and overall bytecode of the contract as the NuklaiToken::__NuklaiToken_init_unchained
function would no longer be necessary.
Alleviation:
The Nuklai team evaluated this exhibit but opted not to apply a remediation for it as the Nuklai token is already deployed. Given that the exhibit is of informational nature, we consider it safely acknowledged.