Olympus DAO contest - cRat1st0s'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: 73/147

Findings: 2

Award: $87.03

🌟 Selected for report: 0

🚀 Solo Findings: 0

2022-08-olympus-code4rena QA Report

Files Description Table

File NameSHA-1 Hash
2022-08-olympus/src/modules/PRICE.soleb3c920eaaf30e31cffbef13d8510dc18341d5ab

QA Report

Issues found

[N-01]: Typos

Impact

None.

Code Affected and Mitigation
diff --git a/src/modules/PRICE.sol b/src/modules/PRICE.sol
index 55d85d3..c3867d1 100644
--- a/src/modules/PRICE.sol
+++ b/src/modules/PRICE.sol
@@ -123,7 +123,7 @@ contract OlympusPrice is Module {
         // Revert if not initialized
         if (!initialized) revert Price_NotInitialized();
 
-        // Cache numbe of observations to save gas.
+        // Cache number of observations to save gas.
         uint32 numObs = numObservations;
 
         // Get earliest observation in window
Tools used

VS Code

2022-08-olympus-code4rena QA Report

Files Description Table

File NameSHA-1 Hash
2022-08-olympus/src/modules/PRICE.soleb3c920eaaf30e31cffbef13d8510dc18341d5ab
2022-08-olympus/src/Kernel.sol702fd864c142f5c93781482371d168379d6b10df
2022-08-olympus/src/utils/KernelUtils.solb103389226af6aa16880e2568c5de4de143d7950
2022-08-olympus/src/modules/INSTR.solb2c9521b73b50db74fa17b59b12e9b25269a83cc
2022-08-olympus/src/modules/RANGE.sol3b34f485fcb242d7a254307b239f055524ed2e6b
2022-08-olympus/src/modules/TRSRY.sol7626a2b1c998b640c51d08c8e665498ba73efca0
2022-08-olympus/src/modules/VOTES.sol5e22b6aff627c48b8cedabbede375c1f5a468985
2022-08-olympus/src/modules/MINTR.sole3ba147c72850c7463b5a3da587a77550ad6da1e
2022-08-olympus/src/modules/PRICE.soleb3c920eaaf30e31cffbef13d8510dc18341d5ab
2022-08-olympus/src/policies/PriceConfig.sol988825fff850ed5efb9713ac352628ca77f78cbc
2022-08-olympus/src/policies/BondCallback.sol6be071dd7f9ccc578d929670bff27ed8f72a9f62
2022-08-olympus/src/policies/TreasuryCustodian.sol752907434e36330542e6f3f18ae2e3a89e746c52
2022-08-olympus/src/policies/Governance.sol88ae920ee84d217efdd686cb29939d820cbbd632
2022-08-olympus/src/policies/Operator.solf185cfaa901424dd55c533b88a7b801f08b35367
2022-08-olympus/src/policies/VoterRegistration.sol74328138074d3796580439636955db37e4ffa9b2
2022-08-olympus/src/policies/Heart.solf1a6dcb7778663cba55f2278e6e2d9044b7ec69c

Gas Optimizations

[G-01]: For-Loops: No need to explicitly initialize variables with default values

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). If you explicitly initialize it with its default value, you are just wasting gas.

Code Affected

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/Kernel.sol#L397

for (uint256 i = 0; i < reqLength; ) {

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/utils/KernelUtils.sol#L43

for (uint256 i = 0; i < 5; ) {

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/utils/KernelUtils.sol#L58

for (uint256 i = 0; i < 32; ) {
Mitigation

Do not initialize variables with default values.

Tools used

VS Code

[G-02]: >= is cheaper than >

Impact

Non-strict inequalities (>=) are cheaper than strict ones (>). This is due to some supplementary checks (ISZERO, 3 gas).

Code Affected

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/PRICE.sol#L90

if (exponent > 38) revert Price_InvalidParams();

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/RANGE.sol#L244-L249

if (
    wallSpread_ > 10000 ||
    wallSpread_ < 100 ||
    cushionSpread_ > 10000 ||
    cushionSpread_ < 100 ||
    cushionSpread_ > wallSpread_

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/PRICE.sol#L215

if (startObservations_.length != numObs || lastObservationTime_ > uint48(block.timestamp))

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/RANGE.sol#L264

if (thresholdFactor_ > 10000 || thresholdFactor_ < 100) revert RANGE_InvalidParams();

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Governance.sol#L212

if (block.timestamp > proposal.submissionTimestamp + ACTIVATION_DEADLINE) {

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L103

if (configParams[1] > uint256(7 days) || configParams[1] < uint256(1 days))

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L108

if (configParams[3] < uint32(1 hours) || configParams[3] > configParams[1])

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L111

if (configParams[4] > 10000 || configParams[4] < 100) revert Operator_InvalidParams();

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L113-L115

        if (
            configParams[5] < 1 hours ||
            configParams[6] > configParams[7] ||

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L237

if (currentPrice > range.cushion.low.price || currentPrice < range.wall.low.price) {

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L243

if (currentPrice < range.cushion.low.price && currentPrice > range.wall.low.price) {

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L254

currentPrice < range.cushion.high.price || currentPrice > range.wall.high.price

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L262

currentPrice > range.cushion.high.price && currentPrice < range.wall.high.price

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L518

if (cushionFactor_ > 10000 || cushionFactor_ < 100) revert Operator_InvalidParams();

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L533

if (duration_ > uint256(7 days) || duration_ < uint256(1 days))

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L536

if (depositInterval_ < uint32(1 hours) || depositInterval_ > duration_)

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L550

if (reserveFactor_ > 10000 || reserveFactor_ < 100) revert Operator_InvalidParams();

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L565

if (wait_ < 1 hours || threshold_ > observe_ || observe_ == 0)

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L758

if (amountOut > RANGE.capacity(false)) revert Operator_InsufficientCapacity();

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L769

if (amountOut > RANGE.capacity(true)) revert Operator_InsufficientCapacity();

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/utils/KernelUtils.sol#L46

if (char < 0x41 || char > 0x5A) revert InvalidKeycode(keycode_); // A-Z only

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/utils/KernelUtils.sol#L60

if ((char < 0x61 || char > 0x7A) && char != 0x5f && char != 0x00) {

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/PRICE.sol#L165

if (updatedAt < block.timestamp - 3 * uint256(observationFrequency))

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/PRICE.sol#L171

if (updatedAt < block.timestamp - uint256(observationFrequency))

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/RANGE.sol#L133

if (capacity_ < _range.high.threshold && _range.high.active) {

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/RANGE.sol#L145

if (capacity_ < _range.low.threshold && _range.low.active) {

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/TRSRY.sol#L131

if (oldDebt < amount_) totalDebt[token_] += amount_ - oldDebt;

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/TRSRY.sol#L144

if (approval < amount_) revert TRSRY_NotApproved();

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/BondCallback.sol#L114

if (quoteToken.balanceOf(address(this)) < priorBalances[quoteToken] + inputAmount_)

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Governance.sol#L164

if (VOTES.balanceOf(msg.sender) * 10000 < VOTES.totalSupply() * SUBMISSION_REQUIREMENT)

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Governance.sol#L227

if (block.timestamp < activeProposal.activationTimestamp + GRACE_PERIOD) {

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Governance.sol#L268

if (netVotes * 100 < VOTES.totalSupply() * EXECUTION_THRESHOLD) {

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Governance.sol#L272

if (block.timestamp < activeProposal.activationTimestamp + EXECUTION_TIMELOCK) {

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Heart.sol#L94

if (block.timestamp < lastBeat + frequency()) revert Heart_OutOfCycle();

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L106

if (configParams[2] < uint32(10_000)) revert Operator_InvalidParams();

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L289

if (amountOut < minAmountOut_)

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L320

if (amountOut < minAmountOut_)

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L535

if (debtBuffer_ < uint32(10_000)) revert Operator_InvalidParams();

https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/policies/Operator.sol#L741

RANGE.capacity(high_) < auctioneer.currentCapacity(market))
Mitigation

Replace > / < with >= / <= without breaking the logic of the code.

Example

Change

if (exponent > 38) revert Price_InvalidParams();

to

if (exponent >= 39) revert Price_InvalidParams();
Tools used

VS Code

#0 - IllIllI000

2022-09-22T11:41:25Z

@0xean G-01 is invalid since they're all local variables, and G-02 changes the behavior of the code. Can you elaborate on why this was ranked highly?

#1 - 0xean

2022-09-22T12:42:08Z

"highly"? It's in the bottom 1/3rd of all gas reports submitted. Happy to downgrade further.

#2 - IllIllI000

2022-09-22T12:50:57Z

"highly"? It's in the bottom 1/3rd of all gas reports submitted. Happy to downgrade further.

According to the spreadsheet it's in the top third with a score of 79. Mine https://github.com/code-423n4/2022-08-olympus-findings/issues/269 has a score of 77

#3 - 0xean

2022-09-22T12:54:03Z

Okay, will re-check and revise.

You are incorrect about these savings being invalid, but happy to take another look at where it stands.

#4 - IllIllI000

2022-09-22T13:02:23Z

You are incorrect about these savings being invalid, but happy to take another look at where it stands.

It's invalid for stack variables, which the finding flags. See https://gist.github.com/IllIllI000/4c0a09e9492ec519339be3cde7431d8c

#5 - 0xean

2022-09-22T14:12:36Z

With the optimizer enabled you are correct, there is no gas savings for G-01. I had tested without the optimizer.

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