Omniscia rain protocol Audit
Phased Code Style Findings
Phased Code Style Findings
PHA-01C: Phase Consistency
Type | Severity | Location |
---|---|---|
Code Style | Phased.sol:L47, L57, L67, L96, L114 |
Description:
The constant MAX_PHASE
exists in the contract to indicate the maximum number of phases supported by it, however, the literal 8
is used multiple times across its code.
Example:
contracts/phased/Phased.sol
47uint256 private constant MAX_PHASE = 8;48
49/// `PhaseScheduled` is emitted when the next phase is scheduled.50event PhaseScheduled(51 address sender,52 uint256 newPhase,53 uint256 scheduledBlock54);55
56/// 8 phases each as 32 bits to fit a single 32 byte word.57uint32[8] public phaseBlocks;
Recommendation:
We advise all linked numeric literals to be replaced by the constant expression MAX_PHASE
to ensure consistency in the codebase and ease of maintainability.
Alleviation:
The MAX_PHASE
constant is now utilized in place of the literal 8
in all instances.
PHA-02C: Type Casting Optimization
Type | Severity | Location |
---|---|---|
Gas Optimization | Phased.sol:L170 |
Description:
The linked downcasting operation is guaranteed to be performed safely by the require
check of block_
that precedes it.
Example:
contracts/phased/Phased.sol
154function schedulePhase(uint256 phase_, uint256 block_) internal {155 require(block.number <= block_, "NEXT_BLOCK_PAST");156 require(block_ < UNINITIALIZED, "NEXT_BLOCK_UNINITIALIZED");157 // Don't need to check for underflow as the index will be used as a158 // fixed array index below. Implies that scheduling phase `0` is NOT159 // supported.160 uint256 index_;161 unchecked {162 index_ = phase_ - 1;163 }164 // Bit of a hack to check the current phase against the index to165 // save calculating the subtraction twice.166 require(currentPhase() == index_, "NEXT_PHASE");167
168 require(UNINITIALIZED == phaseBlocks[index_], "NEXT_BLOCK_SET");169
170 phaseBlocks[index_] = uint32(block_);171
172 emit PhaseScheduled(msg.sender, phase_, block_);173}
Recommendation:
We advise it to be wrapped to an unchecked
code block to optimize the gas cost of the function.
Alleviation:
The casting operation is now optimally wrapped in an unchecked
code block.