Omniscia Criptan Audit

WalletFactory Code Style Findings

WalletFactory Code Style Findings

WFY-01C: Inefficient Event Emission

Description:

The linked code reads a value from storage, writes to it and then emits it from a local variable.

Example:

contracts/WalletFactory.sol
54/**
55 * @dev Changes the current master address for `_newMaster`.
56 * This operation can only be performed by the owner.
57 */
58function setMaster(address payable _newMaster) public onlyOwner {
59 require(_newMaster != address(0), "WalletFactory: master address cannot be zero");
60
61 address oldMaster = master;
62 master = _newMaster;
63 emit MasterChanged(oldMaster, _newMaster);

Recommendation:

We advise the value to be emitted directly without a local variable by referencing the master variable directly in the event emission.

Alleviation:

The event emission was optimized to be performed prior to the storage update thereby reducing the gas cost of the function.

WFY-02C: Inefficient Invocation of Master Initialization

Description:

The constructor of the contract invokes the setMaster function which applies the onlyOwner modifier inefficiently.

Example:

contracts/WalletFactory.sol
47constructor(address payable _master, address _template) {
48 require(_template != address(0), "WalletFactory: template address cannot be zero");
49
50 template = _template;
51 setMaster(_master);
52}
53
54/**
55 * @dev Changes the current master address for `_newMaster`.
56 * This operation can only be performed by the owner.
57 */
58function setMaster(address payable _newMaster) public onlyOwner {
59 require(_newMaster != address(0), "WalletFactory: master address cannot be zero");
60
61 address oldMaster = master;
62 master = _newMaster;
63 emit MasterChanged(oldMaster, _newMaster);
64}

Recommendation:

We advise the code within setMaster to be refactored to invoke an internal / private function of the same name prefixed with an underscore (_) and applying the modifier only on the public / external version.

Alleviation:

The setMaster function was refactored to an internal _setMaster instance that is invoked by the constructor and the setMaster public functions thereby alleviating this exhibit.

WFY-03C: Variable Mutability Specifier

Description:

The linked variable is assigned to only once during the contract's constructor.

Example:

contracts/WalletFactory.sol
47constructor(address payable _master, address _template) {
48 require(_template != address(0), "WalletFactory: template address cannot be zero");
49
50 template = _template;
51 setMaster(_master);
52}

Recommendation:

We advise it to be set as immutable greatly optimizing the codebase.

Alleviation:

The variable has been set as immutable greatly optimizing its read-access gas cost.