Open code423n4 opened 2 years ago
Warden created this issue as a placeholder, because their submission was too large for the contest form. They then emailed their md file to our team. I've updated this issue with their md file content.
Note: my original copy/paste did not capture all of the warden's content. I've updated this issue to now contain the entirety of the original submission. I've also notified the sponsor. Contest has not yet moved to judging.
Misleading comment, now is deprecated and Open TODOs in the Low Risk Issues section should be Non-critical
.
Vulnerability details:
Low Risk Issues
New min/max values should be checked against the current stored value
If
citadelPriceInAsset
is above the new max or below the new min, the next update will likely have a similar value and immediately cause problems. The code should require that the current value falls within the new rangeLoss of precision
If
tokenOutPrice
is less thantokenInNormalizationValue
, then the amount will be zero for some amounts. The caller ofgetAmountOut()
should revert iftokenOutAmount
ends up being zeroUnsafe calls to optional ERC20 functions
decimals()
,name()
andsymbol()
are optional parts of the ERC20 specification, so there are tokens that do not implement them. It's not safe to cast arbitrary token addresses in order to call these functions. IfIERC20Metadata
is to be relied on, that should be the variable type of the token variable, rather than it beingaddress
, so the compiler can verify that types correctly match, rather than this being a runtime failure. See this prior instance of this issue which was marked as Low risk. Do this to resolve the issue.File: src/interfaces/erc20/IERC20.sol (lines 14-18)
Missing checks for
address(0x0)
when assigning values toaddress
state variablesinitialize
functions can be front-runSee this finding from a prior badger-dao contest for details
now
is deprecatedUse
block.timestamp
insteadsafeApprove()
is deprecatedDeprecated in favor of
safeIncreaseAllowance()
andsafeDecreaseAllowance()
Open TODOs
Code architecture, incentives, and error handling/reporting questions/issues should be resolved before deployment
Upgradeable contract is missing a
__gap[50]
storage variable to allow for new storage variables in later versionsSee this link for a description of this storage variable. While some contracts may not currently be sub-classed, adding the variable now protects against forgetting to add it in the future.
Misleading comment
The value of
transferFromDisabled
is never updated, let alone in aninitialize()
function. I don't see any bugs related to this, but this comment makes it seem as though something was overlooked when branching.Unbounded loop
If there are too many pools, the function may run out of gas while returning them. It's best to allow for a start offset and maximum length, so data can be returned in batches that don't run out of gas
Non-critical Issues
Multiple definitions of an interface
These are the only two differences between
IEmptyStrategy
andIStrategy
.IEmptyStrategy
should be changed to beis IStrategy
and remove the duplicate functionsFile: src/interfaces/badger/IEmptyStrategy.sol (lines 12-14)
Unused file
Contract header not updated after branching
Comment not moved when function was moved
Comments not updated after branching
There are a lot of references to the old owner-related code. The comments should be updated to talk about the new RBAC system
The price calulation seems inverted since this comment was first written, so it should be updated to reflect the new calculation:
Remove
include
for ds-testTest code should not be mixed in with production code. The production version should be extended and have its functions overridden for testing purposes
The
nonReentrant
modifier
should occur before all other modifiersThis is a best-practice to protect against reentrancy in other modifiers
Solidity versions greater than the current version should not be included in the pragma range
The below pragmas should be
<
0.9.0, not<=
Adding a
return
statement when the function defines a named return variable, is redundantrequire()
/revert()
statements should have descriptive reason stringspublic
functions not called by the contract should be declaredexternal
insteadContracts are allowed to override their parents' functions and change the visibility from
external
topublic
.constant
s should be defined rather than using magic numbersNumeric values having to do with time should use time units for readability
There are units for seconds, minutes, hours, days, and weeks
Constant redefined elsewhere
Consider defining in only one contract so that values cannot become out of sync when only one location is updated
File: src/Funding.sol (lines 21-22)
seen in src/CitadelMinter.sol
File: src/Funding.sol (lines 23-24)
seen in src/CitadelMinter.sol
File: src/GlobalAccessControl.sol (lines 25-26)
seen in src/Funding.sol
File: src/GlobalAccessControl.sol (lines 32-33)
seen in src/Funding.sol
File: src/GlobalAccessControl.sol (lines 34-35)
seen in src/Funding.sol
File: src/GlobalAccessControl.sol (line 37)
seen in src/Funding.sol
File: src/GlobalAccessControl.sol (lines 46-47)
seen in src/CitadelToken.sol
File: src/KnightingRound.sol (lines 19-20)
seen in src/GlobalAccessControl.sol
File: src/KnightingRound.sol (lines 21-22)
seen in src/GlobalAccessControl.sol
File: src/KnightingRound.sol (lines 24-25)
seen in src/GlobalAccessControl.sol
File: src/KnightingRound.sol (lines 26-27)
seen in src/GlobalAccessControl.sol
File: src/lib/GlobalAccessControlManaged.sol (line 15)
seen in src/GlobalAccessControl.sol
File: src/lib/GlobalAccessControlManaged.sol (line 16)
seen in src/GlobalAccessControl.sol
File: src/StakedCitadel.sol (line 112)
seen in src/Funding.sol
File: src/StakedCitadelVester.sol (lines 20-21)
seen in src/KnightingRound.sol
File: src/SupplySchedule.sol (lines 22-23)
seen in src/StakedCitadelVester.sol
Non-library/interface files should use fixed compiler versions, not floating ones
Typos
File: external/StakedCitadelLocker.sol (line 300)
futher
File: src/CitadelMinter.sol (line 102)
expection
File: src/Funding.sol (line 289)
cumulatiive
File: src/Funding.sol (line 333)
deposi)t
File: src/KnightingRound.sol (line 342)
receipient
File: src/lib/GlobalAccessControlManaged.sol (line 24)
inhereiting
File: src/lib/GlobalAccessControlManaged.sol (line 60)
faciliate
File: src/StakedCitadel.sol (line 81)
too -> to
File does not contain an SPDX Identifier
File is missing NatSpec
NatSpec is incorrect
Wrong parameter description
NatSpec is incomplete
File: src/Funding.sol (lines 95-112)
Missing:
@param _citadelPriceInAssetOracle
File: src/KnightingRound.sol (lines 98-119)
Missing:
@param _globalAccessControl
File: src/StakedCitadel.sol (lines 154-179)
Missing:
@param _vesting
File: src/StakedCitadel.sol (lines 357-367)
Missing:
@param proof
Event is missing
indexed
fieldsEach
event
should use threeindexed
fields if there are three or more fieldsNon-exploitable reentrancies