Platform: Code4rena
Start Date: 03/05/2022
Pot Size: $30,000 USDC
Total HM: 6
Participants: 93
Period: 3 days
Judge: gzeon
Id: 118
League: ETH
Rank: 62/93
Findings: 2
Award: $45.77
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: defsec
Also found by: 0v3rf10w, 0x1f8b, 0x4non, 0x52, 0xDjango, 0xf15ers, 0xkatana, 0xliumin, AuditsAreUS, BowTiedWardens, CertoraInc, Cr4ckM3, Funen, GimelSec, Hawkeye, IllIllI, Kulk0, M0ndoHEHE, MaratCerby, Picodes, Ruhum, TerrierLover, TrungOre, VAD37, WatchPug, berndartmueller, broccolirob, catchup, cccz, cryptphi, csanuragjain, delfin454000, dirk_y, eccentricexit, ellahi, fatherOfBlocks, gzeon, hake, hansfriese, hickuphh3, horsefacts, hubble, hyh, ilan, joestakey, kebabsec, kenta, kenzo, leastwood, m9800, marximimus, minhquanym, oyc_109, p4st13r4, pauliax, pedroais, peritoflores, plotchy, rajatbeladiya, reassor, rfa, robee, rotcivegaf, samruna, shenwilly, shung, simon135, sorrynotsorry, sseefried, teddav, throttle, tintin, unforgiven, z3s
30.2759 USDC - $30.28
The return value of an external transfer/transferFrom call is not checked.
/ForgottenRunesWarriorsGuild.sol::175 => token.transfer(msg.sender, amount); /ForgottenRunesWarriorsMinter.sol::402 => IERC20(weth).transfer(to, amount); /ForgottenRunesWarriorsMinter.sol::629 => token.transfer(msg.sender, amount);
Use SafeERC20
, or ensure that the transfer/transferFrom return value is checked.
ForgottenRunesWarriorsMinter.sol
/** * @notice returns the current dutch auction price */ function currentDaPrice() public view returns (uint256) {
/** * @notice returns whether the dutch auction has started */ function daStarted() public view returns (bool) {
/** * @notice returns whether the mintlist has started */ function mintlistStarted() public view returns (bool) {
/** * @notice returns whether the public mint has started */ function publicStarted() public view returns (bool) {
/** * @notice returns whether the claims phase has started */ function claimsStarted() public view returns (bool) {
/** * @notice returns whether self refunds phase has started */ function selfRefundsStarted() public view returns (bool) {
/** * @notice returns the number of minter addresses in the DA phase (includes duplicates) */ function numDaMinters() public view returns (uint256) {
Add natspec @return
comments.
Manual, Slither.
🌟 Selected for report: BowTiedWardens
Also found by: 0v3rf10w, 0x1f8b, 0x4non, 0xDjango, 0xNazgul, 0xProf, 0xc0ffEE, 0xf15ers, 0xkatana, 0xliumin, ACai, AlleyCat, CertoraInc, Cityscape, Cr4ckM3, DavidGialdi, Dinddle, FSchmoede, Funen, GimelSec, Hawkeye, IllIllI, Kulk0, M0ndoHEHE, MaratCerby, MiloTruck, Picodes, RoiEvenHaim, Tadashi, TerrierLover, TrungOre, VAD37, WatchPug, antonttc, catchup, defsec, delfin454000, dirk_y, eccentricexit, ellahi, fatherOfBlocks, gzeon, hake, hansfriese, hickuphh3, horsefacts, ilan, joestakey, kebabsec, kenta, kenzo, marximimus, minhquanym, noobie, oyc_109, p4st13r4, pauliax, rajatbeladiya, reassor, rfa, robee, rotcivegaf, saian, samruna, shenwilly, shung, simon135, slywaters, sorrynotsorry, throttle, unforgiven, z3s
15.491 USDC - $15.49
All the contracts in scope use pragma solidity ^0.8.0
, allowing wide enough range of versions.
^0.8.0 (contracts/ForgottenRunesWarriorsGuild.sol#1) ^0.8.0 (contracts/ForgottenRunesWarriorsMinter.sol#1)
Consider locking compiler version, for example pragma solidity 0.8.6
.
This can have additional benefits, for example using custom errors to save gas and so forth.
!= 0
is cheapear than > 0
when comparing unsigned integers in require statements.
/ForgottenRunesWarriorsMinter.sol::141 => numWarriors > 0 && numWarriors <= 20, /ForgottenRunesWarriorsMinter.sol::211 => numWarriors > 0 && numWarriors <= 20, /ForgottenRunesWarriorsMinter.sol::378 => if (owed > 0) {
Use != 0
instead of > 0
.
If a variable is not set/initialized, it is assumed to have the default value (0, false, 0x0 etc depending on the data type). Explicitly initializing it with its default value is an anti-pattern and wastes gas.
/ForgottenWarriorsGuild.sol::24 => uint256 public numMinted = 0; /ForgottenRunesWarriorsMinter.sol::162 => for (uint256 i = 0; i < numWarriors; i++) { /ForgottenRunesWarriorsMinter.sol::220 => for (uint256 i = 0; i < numWarriors; i++) { /ForgottenRunesWarriorsMinter.sol::259 => for (uint256 i = 0; i < count; i++) {
Remove explicit zero initialization.
Functions can be
external`.public
functions that are never called by the contract should be declared external
to save gas.
initialize(address) should be declared external: - ForgottenRunesWarriorsGuild.initialize(address) (contracts/ForgottenRunesWarriorsGuild.sol#52-54) exists(uint256) should be declared external: - ForgottenRunesWarriorsGuild.exists(uint256) (contracts/ForgottenRunesWarriorsGuild.sol#85-87) mint(address) should be declared external: - ForgottenRunesWarriorsGuild.mint(address) (contracts/ForgottenRunesWarriorsGuild.sol#94-106) burn(uint256) should be declared external: - ForgottenRunesWarriorsGuild.burn(uint256) (contracts/ForgottenRunesWarriorsGuild.sol#113-119) setProvenanceHash(string) should be declared external: - ForgottenRunesWarriorsGuild.setProvenanceHash(string) (contracts/ForgottenRunesWarriorsGuild.sol#145-147) withdrawAll() should be declared external: - ForgottenRunesWarriorsGuild.withdrawAll() (contracts/ForgottenRunesWarriorsGuild.sol#163-165) forwardERC20s(IERC20,uint256) should be declared external: - ForgottenRunesWarriorsGuild.forwardERC20s(IERC20,uint256) (contracts/ForgottenRunesWarriorsGuild.sol#173-176) numDaMinters() should be declared external: - ForgottenRunesWarriorsMinter.numDaMinters() (contracts/ForgottenRunesWarriorsMinter.sol#337-339) issueRefunds(uint256,uint256) should be declared external: - ForgottenRunesWarriorsMinter.issueRefunds(uint256,uint256) (contracts/ForgottenRunesWarriorsMinter.sol#350-358) refundAddress(address) should be declared external: - ForgottenRunesWarriorsMinter.refundAddress(address) (contracts/ForgottenRunesWarriorsMinter.sol#364-366) selfRefund() should be declared external: - ForgottenRunesWarriorsMinter.selfRefund() (contracts/ForgottenRunesWarriorsMinter.sol#371-374) pause() should be declared external: - ForgottenRunesWarriorsMinter.pause() (contracts/ForgottenRunesWarriorsMinter.sol#427-429) unpause() should be declared external: - ForgottenRunesWarriorsMinter.unpause() (contracts/ForgottenRunesWarriorsMinter.sol#434-436) setSelfRefundsStartTime(uint256) should be declared external: - ForgottenRunesWarriorsMinter.setSelfRefundsStartTime(uint256) (contracts/ForgottenRunesWarriorsMinter.sol#469-471) setPhaseTimes(uint256,uint256,uint256,uint256) should be declared external: - ForgottenRunesWarriorsMinter.setPhaseTimes(uint256,uint256,uint256,uint256) (contracts/ForgottenRunesWarriorsMinter.sol#480-500) setMintlist1MerkleRoot(bytes32) should be declared external: - ForgottenRunesWarriorsMinter.setMintlist1MerkleRoot(bytes32) (contracts/ForgottenRunesWarriorsMinter.sol#505-507) setMintlist2MerkleRoot(bytes32) should be declared external: - ForgottenRunesWarriorsMinter.setMintlist2MerkleRoot(bytes32) (contracts/ForgottenRunesWarriorsMinter.sol#513-515) setClaimlistMerkleRoot(bytes32) should be declared external: - ForgottenRunesWarriorsMinter.setClaimlistMerkleRoot(bytes32) (contracts/ForgottenRunesWarriorsMinter.sol#520-522) setStartPrice(uint256) should be declared external: - ForgottenRunesWarriorsMinter.setStartPrice(uint256) (contracts/ForgottenRunesWarriorsMinter.sol#550-552) setLowestPrice(uint256) should be declared external: - ForgottenRunesWarriorsMinter.setLowestPrice(uint256) (contracts/ForgottenRunesWarriorsMinter.sol#557-559) setDaPriceCurveLength(uint256) should be declared external: - ForgottenRunesWarriorsMinter.setDaPriceCurveLength(uint256) (contracts/ForgottenRunesWarriorsMinter.sol#564-566) setDaDropInterval(uint256) should be declared external: - ForgottenRunesWarriorsMinter.setDaDropInterval(uint256) (contracts/ForgottenRunesWarriorsMinter.sol#571-573) setFinalPrice(uint256) should be declared external: - ForgottenRunesWarriorsMinter.setFinalPrice(uint256) (contracts/ForgottenRunesWarriorsMinter.sol#579-581) setMaxDaSupply(uint256) should be declared external: - ForgottenRunesWarriorsMinter.setMaxDaSupply(uint256) (contracts/ForgottenRunesWarriorsMinter.sol#586-588) setMaxForSale(uint256) should be declared external: - ForgottenRunesWarriorsMinter.setMaxForSale(uint256) (contracts/ForgottenRunesWarriorsMinter.sol#593-595) setMaxForClaim(uint256) should be declared external: - ForgottenRunesWarriorsMinter.setMaxForClaim(uint256) (contracts/ForgottenRunesWarriorsMinter.sol#600-602) withdraw(uint256) should be declared external: - ForgottenRunesWarriorsMinter.withdraw(uint256) (contracts/ForgottenRunesWarriorsMinter.sol#608-611) withdrawAll() should be declared external: - ForgottenRunesWarriorsMinter.withdrawAll() (contracts/ForgottenRunesWarriorsMinter.sol#616-619) forwardERC20s(IERC20,uint256) should be declared external: - ForgottenRunesWarriorsMinter.forwardERC20s(IERC20,uint256) (contracts/ForgottenRunesWarriorsMinter.sol#627-630)
Use the external
attribute for functions never called from the contract.
++i
costs less gas compared to i++
or i += 1
++i
costs less gas compared to i++
or i += 1
for unsigned integer, as pre-increment is cheaper (about 5 gas per iteration). This statement is true even with the optimizer enabled.
/ForgottenRunesWarriorsMinter.sol::162 => for (uint256 i = 0; i < numWarriors; i++) { /ForgottenRunesWarriorsMinter.sol::220 => for (uint256 i = 0; i < numWarriors; i++) { /ForgottenRunesWarriorsMinter.sol::259 => for (uint256 i = 0; i < count; i++) { /ForgottenRunesWarriorsMinter.sol::355 => for (uint256 i = startIdx; i < endIdx + 1; i++) {
Use ++i
instead of i++
to increment the value of an uint variable.
Same thing for --i
and i--
.
Custom errors from Solidity 0.8.4 are cheaper than revert strings (cheaper deployment cost and runtime cost when the revert condition is met)
Use custom errors instead of revert strings.
c4udit, manual, slither.