Omniscia vfat Audit

PositionSettingsRegistry Code Style Findings

PositionSettingsRegistry Code Style Findings

PSR-01C: Significantly Inefficient Multi-Position Adjustment

Description:

The PositionSettingsRegistry::setMultiplePositionSettings function will repetitively load the PositionSettings into memory before re-writing them to storage even though a portion of the settings are adjusted for each settings entry.

Example:

contracts/PositionSettingsRegistry.sol
109function setMultiplePositionSettings(
110 Farm[] calldata farms,
111 RewardConfig calldata rewardConfig
112) public checkRewardConfig(rewardConfig) {
113 Sickle sickle = _get_sickle_by_owner(msg.sender);
114 PositionSettings memory settings;
115 PositionKey memory key;
116 for (uint256 i; i < farms.length; i++) {
117 key = PositionKey({
118 sickle: sickle,
119 stakingContract: farms[i].stakingContract,
120 poolIndex: farms[i].poolIndex
121 });
122 bytes32 keyHash = keccak256(abi.encode(key));
123 settings = positionSettingsMap[keyHash];
124 settings.automateRewards = true;
125 settings.rewardConfig = rewardConfig;
126 positionSettingsMap[keyHash] = settings;
127 emit PositionSettingsSet(key, settings);
128 }
129}

Recommendation:

We advise the PositionKey memory key pointer to be set as a storage one and the positionSettingsMap[keyHash] assignment to be removed, greatly reducing the gas cost incurred when invoking the PositionSettingsRegistry::setMultiplePositionSettings function.

Alleviation (6ab7af3bb495b817ffec469255ea679b1813eecb):

The code was updated to solely assign to the variables necessary for each positionSettingsMap[keyHash] entry, significantly reducing the function’s gas cost.