Omniscia rain protocol Audit

ReadWriteTier Static Analysis Findings

ReadWriteTier Static Analysis Findings

RWT-01S: Data Location Optimization

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 SHOULD
45/// override to enforce status requirements.
46/// Emits `TierChange` event.
47/// @inheritdoc ITier
48function 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 never
55 // 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.number
63 );
64
65 reports[account_] = TierReport.updateReportWithTierAtBlock(
66 report_,
67 startTier_,
68 endTier_,
69 block.number
70 );
71
72 // Emit this event for ITier.
73 emit TierChange(msg.sender, account_, startTier_, endTier_);
74
75 // Call the `_afterSetTier` hook to allow inheriting contracts
76 // to enforce requirements.
77 // The inheriting contract MUST `require` or otherwise
78 // 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 at
85/// 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.