Omniscia Tangible Audit
RentNotificationDispatcher Code Style Findings
RentNotificationDispatcher Code Style Findings
RND-01C: Multiple Redundant Invocations of Getter Function
Type | Severity | Location |
---|---|---|
Gas Optimization | RentNotificationDispatcher.sol:L63, L64, L67 |
Description:
The NotificationWhitelister::tnft
function is invoked three separate times within the RentNotificationDispatcher::notify
function inefficiently.
Example:
contracts/notifications/RentNotificationDispatcher.sol
54function notify(55 address _tnft,56 uint256 tokenId,57 uint256 unclaimedAmount,58 uint256 newDeposit,59 uint256 startTime,60 uint256 endTime61) external onlyTnftRentManager {62 // if in if to save gas in case nothing registered63 if (_tnft == address(tnft())) {64 address receiver = registeredForNotification(address(tnft()), tokenId);65 if (receiver != address(0)) {66 IRentNotificationReceiver(receiver).notify(67 address(tnft()),68 tokenId,69 unclaimedAmount,70 newDeposit,71 startTime,72 endTime73 );74 emit Notified(receiver, tokenId, unclaimedAmount, newDeposit);75 }76 }77}
Recommendation:
We advise the function to be invoked once and to be cached to a local variable that is consequently utilized in place of the remaining invocations, optimizing the gas cost of the function significantly.
Alleviation (2ad448279d9e8e4b6edd94bcd2eb22129b6f7357):
The tnft
getter function's result is correctly cached to a local localTnft
variable, optimizing the code's gas cost.