Platform: Code4rena
Start Date: 29/06/2022
Pot Size: $50,000 USDC
Total HM: 20
Participants: 133
Period: 5 days
Judge: hickuphh3
Total Solo HM: 1
Id: 142
League: ETH
Rank: 125/133
Findings: 1
Award: $21.17
๐ Selected for report: 0
๐ Solo Findings: 0
๐ Selected for report: GalloDaSballo
Also found by: 0v3rf10w, 0x1f8b, 0xA5DF, 0xDjango, 0xHarry, 0xKitsune, 0xNazgul, 0xNineDec, 0xc0ffEE, 0xf15ers, 0xkatana, 0xsanson, ACai, Aymen0909, Bnke0x0, BowTiedWardens, Chom, ElKu, Fitraldys, Funen, Haruxe, Hawkeye, IllIllI, JC, JohnSmith, Kaiziron, Kenshin, Lambda, Limbooo, MadWookie, Metatron, MiloTruck, Picodes, PwnedNoMore, Randyyy, RedOneN, ReyAdmirado, Ruhum, Sm4rty, StErMi, StyxRave, TerrierLover, TomJ, Tomio, UnusualTurtle, Waze, Yiko, _Adam, __141345__, ajtra, ak1, apostle0x01, asutorufos, c3phas, cRat1st0s, catchup, codetilda, cryptphi, datapunk, defsec, delfin454000, durianSausage, exd0tpy, fatherOfBlocks, gogo, grrwahrr, hake, hansfriese, horsefacts, ignacio, jayfromthe13th, joestakey, ladboy233, m_Rassska, mektigboy, minhquanym, mrpathfindr, natzuu, oyc_109, rajatbeladiya, reassor, rfa, robee, rokinot, sach1r0, saian, sashik_eth, simon135, slywaters, swit, z3s, zeesaw, zer0dot
21.1705 USDC - $21.17
File Name | SHA-1 Hash |
---|---|
2022-06-putty/contracts/src/PuttyV2.sol | b1dd8c42d4a91451c119b1f50122e3c97dde97d2 |
If a variable is not set/initialized, it is assumed to have the default value (0
, false
, 0x0
, etc depending on the data type). If you explicitly initialize it with its default value, you are just wasting gas.
2022-06-putty/contracts/src/PuttyV2.sol::497 => uint256 feeAmount = 0;
Do not initialize variables with default values.
VS Code
Pre-increments cost less gas compared to post-increments.
2022-06-putty/contracts/src/PuttyV2.sol::556 => for (uint256 i = 0; i < orders.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::594 => for (uint256 i = 0; i < assets.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::611 => for (uint256 i = 0; i < assets.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::627 => for (uint256 i = 0; i < floorTokens.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::637 => for (uint256 i = 0; i < assets.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::647 => for (uint256 i = 0; i < assets.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::658 => for (uint256 i = 0; i < floorTokens.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::670 => for (uint256 i = 0; i < whitelist.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::728 => for (uint256 i = 0; i < arr.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::742 => for (uint256 i = 0; i < arr.length; i++) {
Change i++
to ++i
.
VS Code
In Solidity 0.8+, thereโs a default overflow check on unsigned integers.
2022-06-putty/contracts/src/PuttyV2.sol::556 => for (uint256 i = 0; i < orders.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::594 => for (uint256 i = 0; i < assets.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::611 => for (uint256 i = 0; i < assets.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::627 => for (uint256 i = 0; i < floorTokens.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::637 => for (uint256 i = 0; i < assets.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::647 => for (uint256 i = 0; i < assets.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::658 => for (uint256 i = 0; i < floorTokens.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::670 => for (uint256 i = 0; i < whitelist.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::728 => for (uint256 i = 0; i < arr.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::742 => for (uint256 i = 0; i < arr.length; i++) {
One example is the code would go from:
for (uint i = 0; i < _prices.length; i++) { priceAverageCumulative += _prices[i]; }
to:
for (uint i = 0; i < _prices.length;) { priceAverageCumulative += _prices[i]; unchecked { i++; } }
VS Code
If a variable is not set/initialized, it is assumed to have the default value (0
, false
, 0x0
, etc depending on the data type). If you explicitly initialize it with its default value, you are just wasting gas.
2022-06-putty/contracts/src/PuttyV2.sol::556 => for (uint256 i = 0; i < orders.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::594 => for (uint256 i = 0; i < assets.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::611 => for (uint256 i = 0; i < assets.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::627 => for (uint256 i = 0; i < floorTokens.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::637 => for (uint256 i = 0; i < assets.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::647 => for (uint256 i = 0; i < assets.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::658 => for (uint256 i = 0; i < floorTokens.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::670 => for (uint256 i = 0; i < whitelist.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::728 => for (uint256 i = 0; i < arr.length; i++) {
2022-06-putty/contracts/src/PuttyV2.sol::742 => for (uint256 i = 0; i < arr.length; i++) {
Do not initialize variables with default values.
VS Code
!= 0
rather than > 0
for unsigned integers in require()
statementsWhen the optimizer is enabled, gas is wasted by doing a greater-than operation, rather than a not-equals operation inside require()
statements. When using !=,
the optimizer is able to avoid the EQ
, ISZERO
, and associated operations, by relying on the JUMPI
that comes afterwards, which itself checks for zero.
2022-06-putty/contracts/src/PuttyV2.sol::293 => require(order.baseAsset.code.length > 0, "baseAsset is not contract");
2022-06-putty/contracts/src/PuttyV2.sol::598 => require(token.code.length > 0, "ERC20: Token is not contract");
2022-06-putty/contracts/src/PuttyV2.sol::599 => require(tokenAmount > 0, "ERC20: Amount too small");
Use != 0
rather than > 0
for unsigned integers in require()
statements.
VS Code