Open code423n4 opened 2 years ago
Valid L
L -> May bump up
Disagree because you'd need to be able to create a second pair with the same addresses, which you cannot
Valid L
Disagree as once note
is non-zero you cannot initialize
Disputed that's on the caller to be aware not on the token dev
Valid Low
Valid Bulked with the zero check above
L
I ran the math on a previous contest and it would take longer for the sun to extinguish than the overflow to happen, for that reason NC
NC
R
NC
Disputed as Slither will give false positives and some devs do that as mitigation
NC
NC
NC
R
NC
NC
R
Dispute in lack of details
NC
R
NC
NC
Rest I disagree
Overall this report feels like a dump of regex based queries
5 L 4 R 11 NC
Headings for report
L01 - assert statement should not be used
L02 - CloseFactor unbounded
L03 - Immutable addresses lack zero-address check
L04 Receive function
L05 - Local variable shadowing
L06 - AVOID USING .TRANSFER
TO TRANSFER NATIVE TOKENS (#142)
NC01 - Underflow desired but not possible
NC02 -Comment Missing function parameter
NC03 - Constants instead of magic numbers
NC04 - Constructor visibility
NC05 - Events indexing
NC06 - Event should be emitted in setters
NC07 - Function missing comments
NC08 - Function order
NC09 - Non-library files should use fixed compiler versions
NC10 - open TODOs
NC11 - Public functions can be external
NC12 - Require statements should have descriptive strings
NC13 - Scientific notation
NC14 - Styling
NC15 - Typos
QA Report
Table of Contents
summary
assert statement should not be used
IMPACT
Properly functioning code should never reach a failing assert statement. If it happened, it would indicate the presence of a bug in the contract. A failing assert uses all the remaining gas, which can be financially painful for a user.
SEVERITY
Low
PROOF OF CONCEPT
Instances include:
lending-market/Comptroller.sol
stableswap/BaseV1-periphery.sol
TOOLS USED
Manual Analysis
MITIGATION
Replace the assert statements with a require statement or a custom error
CloseFactor unbounded
PROBLEM
In
Comptroller.sol
, it is mentioned thatcloseFactorMantissa
should be greater thancloseFactorMinMantissa
and less thancloseFactorMaxMantissa
. But in_setCloseFactor
, these are not checked, meaningcloseFactorMantissa
can be set to a value outside the boundaries defined by the protocol.SEVERITY
Low
PROOF OF CONCEPT
Instances include:
lending-market/Comptroller.sol
TOOLS USED
Manual Analysis
MITIGATION
Add checks in
_setCloseFactor
to ensurecloseFactorMantissa
is greater thancloseFactorMinMantissa
and less thancloseFactorMaxMantissa
hash collision with abi.encodePacked
IMPACT
strings and bytes are encoded with padding when using
abi.encodePacked
. This can lead to hash collision when passing the result tokeccak256
SEVERITY
Low
PROOF OF CONCEPT
Instances include:
stableswap/BaseV1-periphery.sol
TOOLS USED
Manual Analysis
MITIGATION
Use
abi.encode()
instead.Immutable addresses lack zero-address check
IMPACT
constructors should check the address written in an immutable address variable is not the zero address
SEVERITY
Low
PROOF OF CONCEPT
Instances include:
stableswap/BaseV1-core.sol
stableswap/BaseV1-periphery.sol
TOOLS USED
Manual Analysis
MITIGATION
Add a zero address check for the immutable variables aforementioned.
Initialize can be called more than once
IMPACT
in
AccountantDelegate
andTreasuryDelegate
, theinitialize()
function has no check to make sure it has not been called before. This means a maliciousadmin
can call these functions more than once and change thenote
andCnote
token contracts used.SEVERITY
Low
PROOF OF CONCEPT
Instances include:
lending-market/AccountantDelegate.sol
lending-market/TreasuryDelegate.sol
TOOLS USED
Manual Analysis
MITIGATION
Add a
require
statement or modifier to ensureinitialize()
can only be called once.Race conditions using old approve function
PROBLEM
The old
approve()
method of managing allowances has a race condition issue. Users of this token will be open to front-running attacks.SEVERITY
Low
PROOF OF CONCEPT
lending-market/WETH.sol
TOOLS USED
Manual Analysis
MITIGATION
Use an increase/decrease allowance type of methods instead.
Receive function
PROBLEM
AccountantDelegate
has areceive()
function, but does not have any withdrawal function. Any Manifest mistakenly sent to this contract would be locked.SEVERITY
Low
PROOF OF CONCEPT
lending-market/AccountantDelegate.sol
TOOLS USED
Manual Analysis
MITIGATION
Add
require(0 == msg.value)
inreceive()
or remove the function altogether.Setters should check the input value
PROBLEM
Setters and initializers should check the input value - ie make revert if it is the zero address or zero
SEVERITY
Low
PROOF OF CONCEPT
Instances include:
lending-market/GovernorBravoDelegate.sol
lending-market/Comptroller.sol
lending-market/Comptroller.sol
lending-market/AccountantDelegate.sol
lending-market/AccountantDelegator.sol
lending-market/TreasuryDelegate.sol
lending-market/TreasuryDelegator.sol
lending-market/CNote.sol
stableswap/BaseV1-core.sol
TOOLS USED
Manual Analysis
MITIGATION
Add non-zero checks - address or uint256 - to the setters aforementioned.
Transfer should check recipient not address zero
PROBLEM
ERC20 token implementations typically include zero-address checks on both sender and recipient addresses of transfer functions. This is not the case in
WETH.sol
, where no check is performed on the recipientSEVERITY
Low
PROOF OF CONCEPT
Instances include:
lending-market/WETH.sol
TOOLS USED
Manual Analysis
MITIGATION
Add a zero-address check on
dst
Underflow desired but not possible
PROBLEM
Underflow is desired in several price update functions of
stableswap/BaseV1Pair
, but as overflow/underflow checks are automatically performed since Solidity 0.8.0, the functions currently revert if there is underflowSEVERITY
Low
PROOF OF CONCEPT
Instances include:
stableswap/BaseV1-core.sol
TOOLS USED
Manual Analysis
MITIGATION
Place these statements in an
unchecked
block to allow underflowComment Missing function parameter
PROBLEM
Some of the function comments are missing function parameters or returns
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
lending-market/GovernorBravoDelegate.sol
lending-market/CNote.sol
lending-market/NoteInterest.sol
TOOLS USED
Manual Analysis
MITIGATION
Add a comment for these parameters
Commented code
PROBLEM
There are portions of commented code in some files.
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
lending-market/WETH.sol
lending-market/CNote.sol
stableswap/BaseV1-core.sol
TOOLS USED
Manual Analysis
MITIGATION
Remove commented code
Constants instead of magic numbers
PROBLEM
It is best practice to use constant variables rather than literal values to make the code easier to understand and maintain.
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
lending-market/NoteInterest.sol
TOOLS USED
Manual Analysis
MITIGATION
Define constant variables for the literal values aforementioned.
Constructor visibility
PROBLEM
Visibility (public / external) is not needed for constructors anymore since Solidity 0.7.0, see here
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
lending-market/AccountantDelegator.sol
TOOLS USED
Manual Analysis
MITIGATION
Remove the
public
modifier from constructors.Events emitted early
PROBLEM
It is not recommended to emit events before the end of the computations, as the function might revert based on conditions ahead of the event emission
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
CNote.sol
TOOLS USED
Manual Analysis
MITIGATION
Place the defense hook before the two event emissions.
Events indexing
PROBLEM
Events should use indexed fields
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
lending-market/Comptroller.sol
lending-market/AccountantInterfaces.sol
lending-market/TreasuryInterfaces.sol
lending-market/CNote.sol
lending-market/NoteInterest.sol
stableswap/BaseV1-core.sol
TOOLS USED
Manual Analysis
MITIGATION
Add indexed fields to these events so that they have the maximum number of indexed fields possible.
Event should be emitted in setters
PROBLEM
Setters should emit an event so that Dapps can detect important changes to storage
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
lending-market/WETH.sol
lending-market/GovernorBravoDelegate.sol
stableswap/BaseV1-core.sol
TOOLS USED
Manual Analysis
MITIGATION
emit an event in all setters
Function missing comments
PROBLEM
Some functions are missing Natspec comments
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
manifest/Proposal-Store.sol
lending-market/WETH.sol
All the functions are missing comments
lending-market/GovernorBravoDelegate.sol
lending-market/Comptroller.sol
lending-market/CNote.sol
stableswap/BaseV1-core.sol
All the functions are missing proper Natspec comments.
stableswap/BaseV1-periphery.sol
All the functions are missing proper Natspec comments.
TOOLS USED
Manual Analysis
MITIGATION
Add comments to these functions
Function order
PROBLEM
Functions should be ordered following the Soldiity conventions:
receive()
function should be placed after the constructor and before every other function.SEVERITY
Non-Critical
PROOF OF CONCEPT
Several contracts have
receive()
andfallback()
at the end:lending-market/AccountantDelegate.sol
lending-market/AccountantDelegator.sol
lending-market/TreasuryDelegator.sol
TOOLS USED
Manual Analysis
MITIGATION
Place the
receive()
andfallback()
functions after the constructor, before all the other functions.Local variable shadowing
IMPACT
In
lending-market/NoteInterest.sol
, there is local variable shadowing: the constructor parameter has the same name as the storage variablebaseRatePerYear
. This will not lead to any error but can be confusing, especially in the constructor wherebaseRatePerBlock
is computed using the constructor parameterbaseRatePerYear
.SEVERITY
Non-critical
PROOF OF CONCEPT
Instances include:
lending-market/NoteInterest.sol
TOOLS USED
Manual Analysis
MITIGATION
Add an underscore to the constructor parameter (
_baseRatePerYear
) to avoid shadowing.Non-library files should use fixed compiler versions
PROBLEM
contracts should be compiled using a fixed compiler version. Locking the pragma helps ensure that contracts do not accidentally get deployed using a different compiler version with which they have been tested the most
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
ZoneInteraction.sol
WETH.sol
,GovernorBravoDelegate.sol
,Comptroller.sol
,AccountantDelegate.sol
,AccountantDelegator.sol
,AccountantInterfaces.sol
,TreasuryDelegate.sol
,TreasuryDelegator.sol
,TreasuryInterfaces.sol
,CNote.sol
andNoteInterest.sol
have floating pragmas.TOOLS USED
Manual Analysis
MITIGATION
Used a fixed compiler version
Non-library files should use the same compiler version
PROBLEM
contracts within the scope should be compiled using the same compiler version.
SEVERITY
Non-Critical
PROOF OF CONCEPT
WETH.sol
,GovernorBravoDelegate.sol
,Comptroller.sol
,AccountantDelegate.sol
,AccountantDelegator.sol
,AccountantInterfaces.sol
,TreasuryDelegate.sol
,TreasuryDelegator.sol
,TreasuryInterfaces.sol
,CNote.sol
andNoteInterest.sol
have the compiler version set to^0.8.10
, whileBaseV1-core.sol
andBaseV1-periphery
have the0.8.11
version.TOOLS USED
Manual Analysis
MITIGATION
Use the same compiler version throughout the contracts
open TODOs
PROBLEM
There are open TODOs in the code. Code architecture, incentives, and error handling/reporting questions/issues should be resolved before deployment.
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
lending-market/Comptroller.sol
TOOLS USED
Manual Analysis
MITIGATION
Remove the TODOs
Public functions can be external
PROBLEM
It is good practice to mark functions as
external
instead ofpublic
if they are not called by the contract where they are defined.SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
manifest/Proposal-Store.sol
lending-market/GovernorBravoDelegate.sol
lending-market/Comptroller.sol
lending-market/AccountantDelegate.sol
lending-market/AccountantDelegator.sol
lending-market/TreasuryDelegate.sol
lending-market/TreasuryDelegator.sol
lending-market/CNote.sol
lending-market/NoteInterest.sol
TOOLS USED
Manual Analysis
MITIGATION
Declare these functions as
external
instead ofpublic
Related data should be grouped in struct
PROBLEM
When there are mappings that use the same key value, having separate fields is error prone, for instance in case of deletion or with future new fields.
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
stableswap/BaseV1-core.sol
TOOLS USED
Manual Analysis
MITIGATION
Group the related data in a struct and use one mapping:
And it would be used as a state variable:
Require statements should have descriptive strings
PROBLEM
Some require statements are missing error strings, which makes it more difficult to debug when the function reverts.
SEVERITY
Non-critical
PROOF OF CONCEPT
lending-market/WETH.sol
lending-market/GovernorBravoDelegate.sol
stableswap/BaseV1-core.sol
stableswap/BaseV1-periphery.sol
TOOL USED
Manual Analysis
MITIGATION
Add error strings to all require statements.
Scientific notation
PROBLEM
For readability, it is best to use scientific notation (e.g
10e5
) rather than decimal literals(100000
) or exponentiation(10**5
)SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
stableswap/BaseV1-periphery.sol
TOOLS USED
Manual Analysis
MITIGATION
Replace
10**3
with10e3
Styling
PROBLEM
There should be space between operands in mathematical computations
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
stableswap/BaseV1-periphery.sol
TOOLS USED
Manual Analysis
MITIGATION
Add spaces, e.g
Typos
PROBLEM
There are a few typos in the contracts.
SEVERITY
Non-Critical
PROOF OF CONCEPT
Instances include:
lending-market/NoteInterest.sol
stableswap/BaseV1-periphery.sol
TOOLS USED
Manual Analysis
MITIGATION
Correct the typos.
Uint256 alias
IMPACT
uint
is an alias foruint256
.It is better to use uint256: it brings readability and consistency in the code, and it future proofs it in case of any changes to the alias of uint
SEVERITY
Non-Critical
PROOF OF CONCEPT
All the contracts in scope use
uint
instead ofuint256
TOOLS USED
Manual Analysis
MITIGATION
replace
uint
withuint256
Update Solidity version
IMPACT
Use a solidity version of at least 0.8.12 to get
string.concat()
to be used instead ofabi.encodePacked()
SEVERITY
Non-Critical
PROOF OF CONCEPT
All the contracts in scope have a Solidity compiler version <0.8.12, and
string.concat
could be used in the following location:stableswap/BaseV1-core.sol
TOOLS USED
Manual Analysis
MITIGATION
Use Solidity
0.8.12
and replacestring(abi.encodePacked(..)
withstring.concat()