Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QA Report #160

Open
code423n4 opened this issue Sep 8, 2022 · 1 comment
Open

QA Report #160

code423n4 opened this issue Sep 8, 2022 · 1 comment
Labels
bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax

Comments

@code423n4
Copy link
Contributor

code423n4 commented Sep 8, 2022

QA Report for Canto Dex Oracle contest

Overview

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

Title Risk Rating Instance Count
L-1 Check zero denominator Low 2
L-2 Missing check for input variables Low 2
L-3 Large number of observations may cause out-of-gas error Low 2
L-4 Incorrect comment Low 1
L-5 Misleading comment Low 1
NC-1 Order of Functions Non-Critical 5
NC-2 Maximum line length exceeded Non-Critical 2+
NC-3 Constants may be used Non-Critical 18
NC-4 Inconsistent comment spacing and location Non-Critical 1
NC-5 Loop parameter may be changed for clarity Non-Critical 2
NC-6 Functions without comments Non-Critical 4
NC-7 Require statement may be placed before allocating memory for arrays Non-Critical 2

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);
@code423n4 code423n4 added bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax labels Sep 8, 2022
code423n4 added a commit that referenced this issue Sep 8, 2022
code423n4 added a commit that referenced this issue Sep 8, 2022
@0xean
Copy link
Collaborator

0xean commented Oct 13, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Projects
None yet
Development

No branches or pull requests

2 participants