Platform: Code4rena
Start Date: 21/06/2022
Pot Size: $55,000 USDC
Total HM: 29
Participants: 88
Period: 5 days
Judge: gzeon
Total Solo HM: 7
Id: 134
League: ETH
Rank: 52/88
Findings: 2
Award: $128.26
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: defsec
Also found by: 0x1f8b, 0x29A, 0xDjango, 0xNazgul, 0xNineDec, 0xf15ers, 0xkowloon, 0xmint, Bnke0x0, BowTiedWardens, Chom, ElKu, Funen, GalloDaSballo, GimelSec, IllIllI, JC, Kenshin, Kulk0, Lambda, Limbooo, MadWookie, Metatron, Picodes, Soosh, StErMi, TomJ, WatchPug, Waze, Yiko, _Adam, ak1, asutorufos, aysha, bardamu, catchup, datapunk, delfin454000, dipp, fatherOfBlocks, grGred, hake, hansfriese, hyh, joestakey, kebabsec, kenzo, kirk-baird, oyc_109, pashov, poirots, rfa, robee, saian, sashik_eth, shenwilly, simon135, slywaters, z3s, zeesaw, zer0dot
65.8003 USDC - $65.80
For example, the function declarations are generally done in multiline, but in some cases written over a single long line. References below:
a. function setPrincipal(uint8 p, address u, uint256 m, address a) external authorized(admin) returns (bool) { b. function mint(address u, uint256 m, uint256 uA, uint256 ptA, uint256 minRatio, uint256 maxRatio) external returns (uint256, uint256, uint256) { c. function mintWithUnderlying(address u, uint256 m, uint256 a, uint256 ptBought, uint256 minRatio, uint256 maxRatio) external returns (uint256, uint256, uint256) { d. function burn(address u, uint256 m, uint256 minRatio, uint256 maxRatio) external returns (uint256, uint256, uint256) { e. function burnForUnderlying(address u, uint256 m, uint256 minRatio, uint256 maxRatio) external returns (uint256, uint256) { f. function approve(address[] calldata u, address[] calldata a) external authorized(admin) returns (bool) {
type(uint256).max
to get the max value of a uint256, for readabilityuint256 max = 2**256 - 1;
on lines 84 and 112
Once the market is created or the principle is set, it cannot be changed.
Impact:
If the admin makes a mistake in setting these addresses the first time, then there is no way to change it later.
Mitigation:
Since the admin is assumed to be trusted and has been given enough authority, he should be able to change the market addresses too. Since the purpose for admin to be able to change the market address is that he can rectify his mistake(for example a typing error the first time he sets it), we can put a maximum timePeriod for this. When the address is set for the first time, we set a variable as follows:
//Admin can change the address multiple times for the next one hour. uint256 adminFlexibilityTimestamp = block.timestamp + 3600;
Redundant code statements in the if else statement. The code could be rewritten as:
if (p == uint8(MarketPlace.Principals.Yield)) { // Purchase yield PTs to lender.sol (address(this)) uint256 returned = yield(u, y, a - calculateFee(a), address(this)); // Mint and distribute equivalent illuminate PTs IERC5095(principalToken(u, m)).mint(msg.sender, returned); } else { // Purchase illuminate PTs directly to msg.sender uint256 returned = yield(u, y, a - calculateFee(a), msg.sender); } emit Lend(p, u, m, returned); return returned; }
if (address(0) != (address(uToken))) {
.Swap operands and remove the extra bracket from the 2nd operand.
if (address(uToken) != address(0))
natspec
comments.a) /// @notice sets the feenominator to the given value
is a copy pasted text from setFee function.
Spelling mistakes in natspec comments:
a) intializes
b) withdrawl
c) prinicpal
a) unsighed
b) gauruntee
c) remaing
d) for for
e) prinicipal
🌟 Selected for report: BowTiedWardens
Also found by: 0v3rf10w, 0x1f8b, 0x29A, 0xKitsune, 0xNazgul, 0xf15ers, 0xkatana, 0xkowloon, Bnke0x0, ElKu, Fitraldys, Funen, GalloDaSballo, IllIllI, JC, Kaiziron, Lambda, MadWookie, Noah3o6, Nyamcil, RoiEvenHaim, TomJ, Tomio, UnusualTurtle, Waze, _Adam, ajtra, asutorufos, bardamu, c3phas, catchup, datapunk, defsec, delfin454000, fatherOfBlocks, grGred, hake, hansfriese, hyh, ignacio, joestakey, kebabsec, ladboy233, oyc_109, pashov, poirots, rfa, robee, sach1r0, samruna, sashik_eth, simon135, slywaters, z3s, zer0dot
62.4602 USDC - $62.46
Lender.sol
:This reduces both deployment and runtime gas usage. See this link for an example.
require (when != 0, 'no withdrawal scheduled'); and require (block.timestamp >= when, 'withdrawal still on hold');
o
before using it in for loopfor (uint256 i = 0; i < o.length; ) {
could be rewritten as:
uint256 len = o.length; for (uint256 i = 0; i < len; )
calldata
instead of memory
for external functionsDeclare read-only dynamic inputs as calldata instead of memory for external functions.
a) address[8] memory t, b) uint256[] memory a,
These can be rewritten as: a) address[8] calldata t b) uint256[] calldata a