Canto Dex Oracle contest - lukris02's results

Execution layer for original work.

General Information

Platform: Code4rena

Start Date: 07/09/2022

Pot Size: $20,000 CANTO

Total HM: 7

Participants: 65

Period: 1 day

Judge: 0xean

Total Solo HM: 3

Id: 159

League: ETH

Canto

Findings Distribution

Researcher Performance

Rank: 55/65

Findings: 1

Award: $39.22

🌟 Selected for report: 1

🚀 Solo Findings: 0

QA Report for Canto Dex Oracle contest

Overview

During the audit, 5 low and 7 non-critical issues were found.

Low Risk Findings (5)

L-1. Check zero denominator

Description

If the input parameter is equal to zero, this will cause the function call failure on division.

Instances
Recommendation

Add the check to prevent function call failure.

L-2. Missing check for input variables

Description

If input variable points== 0, function will return empty array.
More critical, if input variable window== 0, function will return array with default values, which may lead to further incorrect calculations.

Instances
Recommendation

Add require statement or custom error - points!= 0 && window!= 0.

L-3. Large number of observations may cause out-of-gas error

Description

Loops that do not have a fixed number of iterations, for example, loops that depend on storage values, have to be used carefully: Due to the block gas limit, transactions can only consume a certain amount of gas. Either explicitly or just due to normal operation, the number of iterations in a loop can grow beyond the block gas limit, which can cause the complete contract to be stalled at a certain point.

Instances
Recommendation

Restrict the maximum number of sample observations (points).

L-4. Incorrect comment

Instances

// note in terms of note will always be 1

Recommendation

Probably the comment should be like this "price in terms of note will always be 1 ".

L-5. Misleading comment

Description

The comment is misleading, and there is an extra comma and an empty comment line.

Instances

Link:

for (uint i = 0; i < _reserves0.length; ++i) { reserveAverageCumulative0 += _reserves0[i]; //normalize the reserves for TWAP LP Oracle pricing, reserveAverageCumulative1 += _reserves1[i]; // }
Recommendation

Change or delete comment.

Non-Critical Risk Findings (7)

NC-1. Order of Functions

Description

Some internal functions are between public, some external functions are between public, and some public functions are between external.

Instances
Recommendation

According to Style Guide, ordering helps readers identify which functions they can call and to find the constructor and fallback definitions easier.
Functions should be grouped according to their visibility and ordered:

  • constructor
  • receive function (if exists)
  • fallback function (if exists)
  • external
  • public
  • internal
  • private

NC-2. Maximum line length exceeded

Description

Some lines of code are too long.

Instances
Recommendation

According to Style Guide, maximum suggested line length is 120 characters.
Make the lines shorter.

NC-3. Constants may be used

Description

Constants may be used instead of literal values.

Instances
Recommendation

Define constant variables for repeated values (8 and 1e18).

NC-4. Inconsistent comment spacing and location

Description

Some comments are above the line of code and some next to it. Some comments are indented between // and the comment text, some are not.

Instances
{ //manual scope to pop symbol off of stack string memory symbol = ctoken.symbol();
//set price statically to 1 when the Comptroller is retrieving Price if (compareStrings(symbol, "cNOTE")) { // note in terms of note will always be 1 return 1e18; // Stable coins supported by the lending market are instantiated by governance and their price will always be 1 note
Recommendation

Use consistent comment spacing and location.

NC-5. Loop parameter may be changed for clarity

Description

In loop are used _reserves0.length. It is equal to input variable granularity. It can be clearer and more consistent if you use an input variable in the loop.

Instances
  1. Link:
function reserves(uint granularity) external view returns(uint, uint) { (uint[] memory _reserves0, uint[] memory _reserves1)= sampleReserves(granularity, 1); uint reserveAverageCumulative0; uint reserveAverageCumulative1; for (uint i = 0; i < _reserves0.length; ++i) {
  1. Link:
function totalSupplyAvg(uint granularity) external view returns(uint) { uint[] memory _totalSupplyAvg = sampleSupply(granularity, 1); uint totalSupplyCumulativeAvg; for (uint i = 0; i < _totalSupplyAvg.length; ++i) {
Recommendation
  1. Change to
function reserves(uint granularity) external view returns(uint, uint) { (uint[] memory _reserves0, uint[] memory _reserves1)= sampleReserves(granularity, 1); uint reserveAverageCumulative0; uint reserveAverageCumulative1; //HERE for (uint i = 0; i < granularity; ++i) {
  1. Change to
function totalSupplyAvg(uint granularity) external view returns(uint) { uint[] memory _totalSupplyAvg = sampleSupply(granularity, 1); uint totalSupplyCumulativeAvg; //HERE for (uint i = 0; i < granularity; ++i) {

NC-6. Functions without comments

Description

Some functions do not have comments describing them.

Instances
Recommendation

Add comments.

NC-7. Require statement may be placed before allocating memory for arrays

Instances
  1. Link:
uint[] memory _reserves0 = new uint[](points); uint[] memory _reserves1 = new uint[](points); uint lastIndex = observations.length-1; require(lastIndex >= points * window, "PAIR::NOT READY FOR PRICING");
  1. Link:
uint[] memory _totalSupply = new uint[](points); uint lastIndex = observations.length-1; require(lastIndex >= points * window, "PAIR::NOT READY FOR PRICING");
Recommendation
  1. Change to
uint lastIndex = observations.length-1; require(lastIndex >= points * window, "PAIR::NOT READY FOR PRICING"); uint[] memory _reserves0 = new uint[](points); uint[] memory _reserves1 = new uint[](points);
  1. Change to
uint lastIndex = observations.length-1; require(lastIndex >= points * window, "PAIR::NOT READY FOR PRICING"); uint[] memory _totalSupply = new uint[](points);

#0 - 0xean

2022-10-13T14:35:29Z

L-1 - non critical L-2 - non critical L-3 - Low L-4 - Low L-5 - Low

Agree with all the rest of the classifications here.

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