Omniscia rain protocol Audit
ReadWriteTier Static Analysis Findings
ReadWriteTier Static Analysis Findings
RWT-01S: Data Location Optimization
Type | Severity | Location |
---|---|---|
Gas Optimization | ReadWriteTier.sol:L51, L96 |
Description:
The linked function arguments are set as memory
in external
functions and function chains.
Example:
contracts/tier/ReadWriteTier.sol
42/// Errors if the user attempts to return to the ZERO tier.43/// Updates the report from `report` using default `TierReport` logic.44/// Calls `_afterSetTier` that inheriting contracts SHOULD45/// override to enforce status requirements.46/// Emits `TierChange` event.47/// @inheritdoc ITier48function setTier(49 address account_,50 uint256 endTier_,51 bytes memory data_52) external virtual override {53 // The user must move to at least tier 1.54 // The tier 0 status is reserved for users that have never55 // interacted with the contract.56 require(endTier_ > 0, "SET_ZERO_TIER");57
58 uint256 report_ = report(account_);59
60 uint256 startTier_ = TierReport.tierAtBlockFromReport(61 report_,62 block.number63 );64
65 reports[account_] = TierReport.updateReportWithTierAtBlock(66 report_,67 startTier_,68 endTier_,69 block.number70 );71
72 // Emit this event for ITier.73 emit TierChange(msg.sender, account_, startTier_, endTier_);74
75 // Call the `_afterSetTier` hook to allow inheriting contracts76 // to enforce requirements.77 // The inheriting contract MUST `require` or otherwise78 // enforce its needs to rollback a bad status change.79 _afterSetTier(account_, startTier_, endTier_, data_);80}81
82/// Inheriting contracts SHOULD override this to enforce requirements.83///84/// All the internal accounting and state changes are complete at85/// this point.86/// Use `require` to enforce additional requirements for tier changes.87///88/// @param account_ The account with the new tier.89/// @param startTier_ The tier the account had before this update.90/// @param endTier_ The tier the account will have after this update.91/// @param data_ Additional arbitrary data to inform update requirements.92function _afterSetTier(93 address account_,94 uint256 startTier_,95 uint256 endTier_,96 bytes memory data_97) internal virtual {} // solhint-disable-line no-empty-blocks
Recommendation:
We advise them to be set as calldata
optimizing their gas cost and enforcing immutability on the input arguments.
Alleviation:
The data location was properly set as calldata
optimizing the codebase.