Omniscia Stakewise Audit
StakedEthToken Code Style Findings
StakedEthToken Code Style Findings
SET-01C: Incorrect Gas Optimization
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | Informational | StakedEthToken.sol:L78-L84 |
Description:
The way the code is structured actually incurs more gas than simply performing a direct assignment to the storage slot as it performs redundant in-memory operations.
Example:
78uint256 _distributorPrincipal = distributorPrincipal; // gas savings79if (senderRewardsDisabled) {80 _distributorPrincipal = _distributorPrincipal.sub(amount);81} else {82 _distributorPrincipal = _distributorPrincipal.add(amount);83}84distributorPrincipal = _distributorPrincipal;Recommendation:
We advise the code block to be reverted to the canonical implementation similarly to toggleRewards to reduce the gas cost of the function. In general, such optimizations are only valuable when the value that is cached in memory would have been read twice which is not the case here.
Alleviation:
The Stakewise team confirmed this exhibit, however, they will update the live implementation of the contract only when a logic update is also performed to avoid contract upgrades solely for optimizations.
SET-02C: Potential XOR Optimization
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | Informational | StakedEthToken.sol:L76 |
Description:
The if statement performs a XOR operation between the values of senderRewardsDisabled and recipientRewardsDisabled. This operation can be optimized in all cases by adjusting the statements from (a || b) && !(a && b) to a ? !b : b.
Example:
76if ((senderRewardsDisabled || recipientRewardsDisabled) && !(senderRewardsDisabled && recipientRewardsDisabled)) {Recommendation:
Although the gas optimization is minimal, we advise it to be applied as such optimizations can compound to a significant reduction in gas.
Alleviation:
The Stakewise team considered this exhibit but opted to retain the current implementation in place.