Inconsistant parameter requirements between constructor() and Set() functions in RANGE.sol and Operator.sol .
The constructor functions in RANGE.sol and Operator.sol do not validate parameters that the corresponding setter functions do validate. If the contracts are deployed with improper parameters, they may behave unexpectedly.
Originally disclosed on Code4rena
Submitted by hansfriese, also found by datapunk and itsmeSTYJ
Inconsistant parameter requirements between constructor and Set() functions in RANGE.sol and Operator.sol.
The contracts might work unexpectedly when the params are set improperly using constructor().
Proof of Concept
- In
RANGE.sol, setSpreads() and setThresholdFactor() has some requirements but constructor() doesn’t check at all.
File: 2022-08-olympus\src\modules\RANGE.sol
242: function setSpreads(uint256 cushionSpread_, uint256 wallSpread_) external permissioned {
243: // Confirm spreads are within allowed values
244: if (
245: wallSpread_ > 10000 ||
246: wallSpread_ < 100 ||
247: cushionSpread_ > 10000 ||
248: cushionSpread_ < 100 ||
249: cushionSpread_ > wallSpread_
250: ) revert RANGE_InvalidParams();
251:
252: // Set spreads
253: _range.wall.spread = wallSpread_;
254: _range.cushion.spread = cushionSpread_;
255:
256: emit SpreadsChanged(wallSpread_, cushionSpread_);
257: }
File: 2022-08-olympus\src\modules\RANGE.sol
263: function setThresholdFactor(uint256 thresholdFactor_) external permissioned {
264: if (thresholdFactor_ > 10000 || thresholdFactor_ < 100) revert RANGE_InvalidParams();
265: thresholdFactor = thresholdFactor_;
266:
267: emit ThresholdFactorChanged(thresholdFactor_);
268: }
269:
- In
Operator.sol, setCushionFactor() checks the requirement but constructor() doesn’t check it.
File: 2022-08-olympus\src\policies\Operator.sol
516: function setCushionFactor(uint32 cushionFactor_) external onlyRole("operator_policy") {
517: /// Confirm factor is within allowed values
518: if (cushionFactor_ > 10000 || cushionFactor_ < 100) revert Operator_InvalidParams();
519:
520: /// Set factor
521: _config.cushionFactor = cushionFactor_;
522:
523: emit CushionFactorChanged(cushionFactor_);
524: }
525:
Tools Used
Solidity Visual Developer of VSCode
Recommended Mitigation Steps
Recommend adding same validation for the parameters between constructor() and Set() functions.
Oighty (Olympus) disagreed with severity and commented:
Agree that the constructor should validate these parameters, but it is only an issue if configured improperly.
While I am typically weary of marking input validations as medium severity, I do think in this case it’s warranted as it directly leads to malfunctions at the protocol level and it seems that the sponsors thought it important enough to add the checks elsewhere. Hard call, but will award it at medium severity.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the constructor functions lack the same input validation checks that are present in the setter functions.
Impact
If the contracts are deployed with improper parameters, they could malfunction at the protocol level.
What the attacker needed
Contract deployed with improper parameters
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Smart contracts often have settings that can be changed later by an admin. The code that changes a setting checks that the new value is within a safe range, but the code that sets the initial value when the contract is first deployed does not. If the deployer makes a mistake, the contract could start with bad settings and not work as intended.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.