Olympus DAO contest - Chandr's results

Version 3 of Olympus protocol, a decentralized floating currency.

General Information

Platform: Code4rena

Start Date: 25/08/2022

Pot Size: $75,000 USDC

Total HM: 35

Participants: 147

Period: 7 days

Judge: 0xean

Total Solo HM: 15

Id: 156

League: ETH

Olympus DAO

Findings Distribution

Researcher Performance

Rank: 88/147

Findings: 2

Award: $86.89

🌟 Selected for report: 0

🚀 Solo Findings: 0

Shadowed variables

IMPACT: Shadowing local variables is naming conventions found in two or more variables that are similar. Although they do not pose any immediate risk to the contract, incorrect usage of the variables is possible and can cause serious issues if the developer does not pay close attention. [Reference|https://github.com/crytic/slither/wiki/Detector-Documentation#local-variable-shadowing]

ERC20Permit.constructor(string).name (OlympusERC20.sol#844) shadows: ERC20.name() (OlympusERC20.sol#689-691) (function)

Mitigation: rename name to _name

Requirement violation.

(Https://github.com/code-423n4/2022-08-olympus/tree/main/src/Kernel.sol#L300)

A requirement was violated in a nested call and the call was reverted as a result. Make sure valid inputs are provided to the nested call (for instance, via passed arguments). Reference: https://swcregistry.io/docs/SWC-123

public functions not called by the contract should be declared external instead

Impact: Contracts are allowed to override their parents' functions and change the visibility from external to public. Kernel.grantRole(Role,address) (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/Kernel.sol#L443-L452) Kernel.revokeRole(Role,address) (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/Kernel.sol#L455-L462) OlympusMinter.mintOhm(address,uint256) (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/MINTR.sol#L33-L35) OlympusMinter.burnOhm(address,uint256) (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/MINTR.sol#L37-L39) OlympusVotes.transfer(address,uint256) (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/VOTES.sol#L45-48) OlympusVotes.transferFrom(address,address,uint256) (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/VOTES.sol#L51-63) OlympusInstructions.getInstructions(uint256) (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/INSTR.sol#L37-39)

MixedCase:

Functions should be written in mixedCase, see Solidity naming conventions. Functions breaking this convention:

Reference: https://github.com/code-423n4/2021-11-bootfinance-findings/issues/163

Function OlympusRange.KEYCODE() - (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/RANGE.sol#L110-L112) Function OlympusRange.VERSION() (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/RANGE.sol#L115-L117) Function OlympusVotes.KEYCODE() (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/VOTES.sol#L22-24) Function OlympusVotes.VERSION() (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/VOTES.sol#L27-29) Function OlympusInstructions.KEYCODE() (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/INSTR.sol#L23-25) Function OlympusInstructions.VERSION() (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/INSTR.sol#L28-30) Variable TreasuryCustodian.TRSRY (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/TreasuryCustodian.sol#L20) Variable Operator._status (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L59) Variable Operator._config (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L60) Variable Operator.PRICE (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L69) Variable Operator.RANGE (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L70) Variable Operator.TRSRY (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L71) Variable Operator.MINTR (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L72) Variable OlympusGovernance.INSTR (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Governance.sol#L56) Variable OlympusGovernance.VOTES (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Governance.sol#L57) Variable VoterRegistration.VOTES (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/VoterRegistration.sol#L10) Variable BondCallback.TRSRY (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/BondCallback.sol#L29) Variable BondCallback.MINTR (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/BondCallback.sol#L30) Variable OlympusPriceConfig.PRICE (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/PriceConfig.sol#L11) Variable OlympusHeart.PRICE (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Heart.sol#L45) Variable OlympusHeart._operator (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Heart.sol#L48) Function Module.KEYCODE() (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/Kernel.sol#L99) Function Module.VERSION() (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/Kernel.sol#L104) Function Module.INIT() (Https://github.com/code-423n4/2022-08-olympus/tree/main/src/Kernel.sol#L109) Function OlympusPrice.KEYCODE() (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L108-110) Function OlympusPrice.VERSION() (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L113-115) Variable OlympusPrice._ohmEthPriceFeed (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L32) Variable OlympusPrice._reserveEthPriceFeed (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L33) Variable OlympusPrice._movingAverage (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L36) Variable OlympusPrice._scaleFactor (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L65) Function OlympusTreasury.KEYCODE() (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/TRSRY.sol#L47-L49) Function OlympusTreasury.VERSION() (Https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/TRSRY.sol#L51-L53)

PREFIX INCREMENTS

IMPACT Prefix increments are cheaper than postfix increments.

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/utils/KernelUtils.sol#L49 i++;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/utils/KernelUtils.sol#L64 i++;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L488 decimals++;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L670 _status.low.count++;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L686 _status.high.count++;

Mitigation: replace foo++ to ++foo

DEFAULT VALUE INITIALIZATION

IMPACT If a variable is not set/initialized, it is assumed to have the default value (0, false, 0x0 etc depending on the data type). Explicitly initializing it with its default value is an anti-pattern and wastes gas.

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/Kernel.sol#L397 for (uint256 i = 0; i < reqLength; ) {

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/utils/KernelUtils.sol#L43 for (uint256 i = 0; i < 5; ) {

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/utils/KernelUtils.sol#L58 for (uint256 i = 0; i < 32; ) {

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L574 _status.high.count = 0;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L575 _status.high.nextObservation = 0;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L578 _status.low.count = 0;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L579 _status.low.nextObservation = 0;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/PRICE.sol#L254 _movingAverage = 0;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/PRICE.sol#L286 _movingAverage = 0;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/RANGE.sol#L135 _range.high.active = false;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/RANGE.sol#L147 _range.low.active = false;

Mitigation: Remove explicit value initialization.

COMPARISON OPERATORS

IMPACT In the EVM, there is no opcode for >= or <=. When using greater than or equal, two operations are performed: > and =. Using strict comparison operators hence saves gas.

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L210 uint48(block.timestamp) >= RANGE.lastActive(true) + uint48(config_.regenWait) &&

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L211 status.high.count >= config.regenThreshold

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L216 uint48(block.timestamp) >= RANGE.lastActive(false) + uint48(config_.regenWait) &&

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L217 status.low.count >= config.regenThreshold

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L486 while (price_ >= 10) {

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L667 if (currentPrice >= movingAverage) {

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Operator.sol#L683 if (currentPrice <= movingAverage) {

Mitigation: Replace <= with <, and >= with >. Do not forget to increment/decrement the compared variable

COMPARISON WITH ZERO

IMPACT

0 is less gas efficient than !0 if you enable the optimizer at 10k AND you’re in a require statement. Detailed explanation with the opcodes here

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Governance.sol#L247 if (userVotesForProposal[activeProposal.proposalId][msg.sender] > 0) {

Mitigation: Replace >0 with !0

Increment/decrement operations

IMPACT X = X + Y IS CHEAPER THAN X += Y X = X- Y IS CHEAPER THAN X -= Y

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Governance.sol#L194 totalEndorsementsForProposal[proposalId_] -= previousEndorsement;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Governance.sol#L198 totalEndorsementsForProposal[proposalId_] += userVotes;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Governance.sol#L252 yesVotesForProposal[activeProposal.proposalId] += userVotes;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Governance.sol#L254 noVotesForProposal[activeProposal.proposalId] += userVotes;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/Heart.sol#L103 lastBeat += frequency();

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/BondCallback.sol#L143 amountsPerMarket[id][0] += inputAmount_;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/policies/BondCallback.sol#L144 amountsPerMarket[id][1] += outputAmount_;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/TRSRY.sol#L96 reserveDebt[token_][msg.sender] += amount_;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/TRSRY.sol#L97 totalDebt[token_] += amount_;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/TRSRY.sol#L115 reserveDebt[token_][msg.sender] -= received;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/TRSRY.sol#L116 totalDebt[token_] -= received;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/TRSRY.sol#L131 if (oldDebt < amount_) totalDebt[token_] += amount_ - oldDebt;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/TRSRY.sol#L132 else totalDebt[token_] -= oldDebt - amount_;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/VOTES.sol#L56 balanceOf[from_] -= amount_;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/VOTES.sol#L58 balanceOf[to_] += amount_;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/PRICE.sol#L136 _movingAverage += (currentPrice - earliestPrice) / numObs;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/PRICE.sol#L138 _movingAverage -= (earliestPrice - currentPrice) / numObs;

Instance: https://github.com/code-423n4/2022-08-olympus/tree/main/src/modules/PRICE.sol#L222 total += startObservations_[i];

Mitigation: X += Y replace with X = X + Y X -= Y replace with X = X - Y

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax Š 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter