Canto contest - Bronicle's results

Execution layer for original work.

General Information

Platform: Code4rena

Start Date: 14/06/2022

Pot Size: $100,000 USDC

Total HM: 26

Participants: 59

Period: 7 days

Judge: GalloDaSballo

Total Solo HM: 9

Id: 133

League: ETH

Canto

Findings Distribution

Researcher Performance

Rank: 46/59

Findings: 1

Award: $212.99

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

101.8823 USDC - $101.88

687.9945 CANTO - $111.11

Labels

bug
QA (Quality Assurance)

External Links

1. Variable reference prior to variable declaration

Summary

The variable UniGovModAcct is referenced within a local scope prior to be declared within the global scope.

Details

It is of good practice, for the sake of readability, to declare at the beginning of the contract all the state variables, followed by the modifiers and finally by the cosntructor and functions. In this particular contract, this good practice is unfollowed. This yields to certain head-scratchers when reading the code, such as in the particular case of declaring the modifier OnlyUniGov (which uses in its local scope the UniGovModAcct state variable) before the UniGovModAcct state variable.

Github Permalinks

Mitigation

Consider following the best practices: declare first the state variables, followed by modifieras and finally constructor and functions.

2. Overall lack of comments/documentation on Proposal-Store.sol functions

Summary

The file Proposal-Store.sol, which contains the ProposalStore contract, lacks documentation around its functions.

Details

For the sake of readability, it would be an improvement to add some additional natspec around, for example, AddProposal and QueryProp, which are the contract's functions.

Github Permalinks

Mitigation

Consider adding comments/natspec documenting these functions.

3. Misleading comment colliding with codebase

Summary

There is a comment which states exactly the contrary that is declared on the codebase.

Details

On line 43 of BaseV1-core.sol, there is a comment stating that the stable state variable is NOT immutable. However, this variable is in fact explicitly declared as immutable. Is it an mistake in the implementation or in the codebase?

Github Permalinks

Mitigation

Consider revising this part of the contract, and depending on the contract specs, either re-write the comment or declare the stable variable as mutable.

4. Remove stale comments

Summary

Stale comments pollute the codebase with old code which quickly becomes deprecated in new versions.

Details

It is of good practice not to have stale comments, as commented code quickly becomes deprecated because it does not evolve with the codebase. Thus, uncommenting it in later versions may lead to error or unexpected behaviors.

Github Permalinks

Mitigation

Consider deleting stale comments

5. Define contract type prior to its usage

Summary

It is of good practice to declare all dependencies, even if they are smart contracts themselves, prior to their usage. For the sake of readability.

Details

The BaseV1Factory contract type is referenced within the BaseV1Pair, but it is declared much later. This makes more difficult to understand the codebase, as it doesn't follow the good practices.

Github Permalinks

Mitigation

Consider defining the BaseV1Factory contract right after the interface definitions.

6. Custom getter functions do not follow the same return style

Summary

Solidity allows different return styles: implicitly returning variables by assgning them the same name as in the returns() part of the function declaration, or explicitly calling return() on a variable. For the sake of readability, similar functions should not mix these styles up.

Details

Several (custom) getter functions are declared within BaseV1Pair, but not all of them follow the same return style. This might look confusing at first.

Github permalinks

Mitigation

Consider choosing one style and stick with it during the entire codebase, to improve readability. That means, for example, declare getReserves() as follows:

function getReserves() public view returns (uint _reserve0, uint _reserve1, uint _blockTimestampLast) { return(reserve0, reserve1, blockTimestampLast); }

7. Missing/unclear error string within require statements

Summary

Require statements should usually provide error strings explaining why the revert has occurred. These error strings should be easy to interpret.

Details

Error string should be present on important require checks, and they should be easy to interpret. However within the BaseV1Pair, some functions like mint, contain error strings that are explained in the comments present in the codebase. A user facing a revert by triggering it from mint's require statement, would get an error string stating "ILM" instead of a more readable alternative like "INSUFFICIENT LIQUIDITY MINTED" (which is present as a comment).

Github Permalinks

Mitigation

Consider writing more error strings, and improving the readability of some of the existent error strings.

8. Separate common used interfaces and libraries into their own files

Summary

It is of good practice to modularize code instead of hard-coding it over and over among several files within a same project. This helps mantainability and avoids unexpected behaviors due to typos.

Details

Files BaseV1-periphery.sol and BaseV1-core.sol declare the same interfaces and libraries. These declarations should be made on a separate file, and then BaseV1-periphery.sol and BaseV1-core.sol could just import said file, for the sake of mantainability and security.

Github Permalinks

Mitigation

Consider deleting the shared definitions from their original codebases, creating a interfaces.sol and a library.sol files to group these definitions together, and then importing them into the appropriate codebases.

9. Unnecesary safemath-like function declarations

Summary

Overflow/underflow were common points of failure of smart contracts. However, since solc version 0.8.0, these checks happen in automatically by the compiler. Thus, safemath-like functions are no longer necessary.

Details

The GovernorBravoDelegate.sol declares the add256() and sub256() functions, which perform overflow/underflow checks. Since the pragma declared is pragma solidity ^0.8.10;, they aren'treally needed because this compiler version does the overflow/underflow by default. In addition to that, they aren't used within any unchecked blocks. Removing these functions and using ordinary addition/subtraction operators is safe, and more gas efficient.

Github Permalinks

Mitigation

Remove these function declarations and substitute them for the addition/subtraction operators.

10. Unused function declared

Summary

Contract contains a function that is not used in its codebase.

Details

The sub256 function is declared but not used (in addition to not being necessary due to issue number 9 of this report).

Github Permalinks

Mitigation

Remove this function declaration from the codebase

#0 - GalloDaSballo

2022-08-02T20:01:17Z

1. Variable reference prior to variable declaration

Valid Ref

2. Overall lack of comments/documentation on Proposal-Store.sol functions

Valid NC

3. Misleading comment colliding with codebase

Valid Ref

4. Remove stale comments

Valid R

5. Define contract type prior to its usage

Disagree as the factory is using the Pair, the current order logically makes more sense (and this argument cuts both ways

6. Custom getter functions do not follow the same return style

Valid R

7. Missing/unclear error string within require statements

NC

8. Separate common used interfaces and libraries into their own files

Valid R

9. Unnecesary safemath-like function declarations

Valid R

10. Unused function declared

Valid R

7R 2NC

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