RobinNagpal / compound-comet

Other
4 stars 0 forks source link

Review Tasks #35

Open RobinNagpal opened 1 month ago

RobinNagpal commented 1 month ago

Structure of Contracts

Check Variable and function names

Check for events, errors and requires

Things to check

Checklist

Check order of Arguments (what is the best order)

MSamiTariq commented 1 month ago

Checklist of things that conform to the styling guide as mentioned in https://docs.soliditylang.org/en/latest/style-guide.html

MSamiTariq commented 1 month ago

Solidity recommends the following three points for ordering of functions, modifier and contracts:

  1. Inside each contract, library or interface, use the following order:
  1. Functions should be grouped according to their visibility and ordered:
  1. The modifier order for a function should be:

Type declarations (enums, structs) are always used at the top level followed by state variables. There are only a few exceptions to this image image

Found this anomaly in Comet.sol where a constructor is defined before a modifier image

Found this pattern of constructor before modifier in Ownable.sol and TransparentUpgradableProxy.sol too image image

Since Compound almost always follows this convention, we too can follow this.

At some places, Compound is declaring errors before events, though the recommended way is events before errors. Although there is no clear pattern used by Compound regarding this image

For the grouping of functions:

Constructors are always at top except for the cases I already mentioned above where a constructor is used before a modifier.

Receive function should be declared before fallback, but anomaly was detected image

There is also a case where the receive function was found at the end of the contract image

Another case where receive function is used between other functions image

Similarly found the fallback function defined at the end of the contract image

image

At few places, Compound defines fallback at the end of the contract, but at some places, it follows the convention recommended by Solidity like in the following case image

Solidity recommends to group external functions before internal, but Compound doesn't follow this convention image

There is no strict convention that Compound follows regarding external functions before internal or vice versa. It basically follows a mixture.

Similar is the case for public functions, these should be placed after external functions before internal, but compound doesn't follow a strict convention for this either image

Similarly, private functions should be placed at the end, but compound doesn't follow any convention there either image

Next we analyze the modifier order in functions

According to Solidity's recommended way, visibility should always be the first modifier, but in Compound, I noticed that override is the first modifier: image image

Next is that mutability should come after visibility, and Compound follows this convention image

Next is that custom modifier should always come last, and Compound also follows this convention image