Forgotten Runes Warrior Guild contest - defsec's results

16,000 Warrior NFTs sold in a phased Dutch Auction.

General Information

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

Forgotten Runes

Findings Distribution

Researcher Performance

Rank: 6/93

Findings: 5

Award: $1,428.33

🌟 Selected for report: 1

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: pedroais

Also found by: AuditsAreUS, BowTiedWardens, GimelSec, IllIllI, WatchPug, defsec, leastwood

Labels

bug
duplicate
2 (Med Risk)
upgraded by judge

Awards

542.7657 USDC - $542.77

External Links

Judge has assessed an item in Issue #225 as Medium risk. The relevant finding follows:

C4-010 : The Dutch Auction Parameters Can be Manipulated By Owner After The Auction Started - LOW

Impact - LOW

Dutch Auction parameters can be changed by a malicious owner, after It is started. The malicious owner can manipulate all contract behaviour.

Proof of Concept

  1. Navigate to the following contract.

  2. The contract should implement the pause modifier on the setter functions.

https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L120
function setDaStartTime(uint256 _newTime) public onlyOwner { daStartTime = _newTime; } /** * @notice set the mintlist start timestamp */ function setMintlistStartTime(uint256 _newTime) public onlyOwner { mintlistStartTime = _newTime; } /** * @notice set the public sale start timestamp */ function setPublicStartTime(uint256 _newTime) public onlyOwner { publicStartTime = _newTime; } /** * @notice set the claims phase start timestamp */ function setClaimsStartTime(uint256 _newTime) public onlyOwner { claimsStartTime = _newTime; } /** * @notice set the self refund phase start timestamp */ function setSelfRefundsStartTime(uint256 _newTime) public onlyOwner { selfRefundsStartTime = _newTime; }

Tools Used

Code Review

Implement whenNotPaused modifier on the setter function. The variables should be changed when the contract is paused.

function setDaStartTime(uint256 _newTime) public onlyOwner whenNotPaused { daStartTime = _newTime; }

#0 - gzeoneth

2022-06-20T17:29:23Z

Duplicate of #38

Findings Information

🌟 Selected for report: throttle

Also found by: 0xDjango, BowTiedWardens, WatchPug, defsec, dipp, fatherOfBlocks, gzeon, hake, reassor, shung, unforgiven

Labels

bug
duplicate
2 (Med Risk)
upgraded by judge

Awards

296.7571 USDC - $296.76

External Links

Judge has assessed an item in Issue #225 as Medium risk. The relevant finding follows:

C4-005 : # Missing sanity check on the timestamps

Impact

During the code review, It has been observed that all timestamps are missing sanity checks. With the following scenario, that can have serious consequences.

Scenario

  • Admin initialize variables.
  • Auction/Bidding begans.
  • Admin set mistakenly old value (smaller than block.timestamp).
  • Auction bidding began with previous date instead of future date.

Proof of Concept

  1. Navigate to the following contracts.
https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L463 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L456 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L449 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L442

Tools Used

Code Review

Consider adding sanity check in the discussed setter functions: require(time >= block.timestamp);.

#0 - gzeoneth

2022-06-20T17:32:38Z

Duplicate of #27

Findings Information

🌟 Selected for report: Kulk0

Also found by: 0x1f8b, 0xDjango, BowTiedWardens, Dinddle, broccolirob, defsec, dirk_y, hyh, rajatbeladiya, throttle, unforgiven

Labels

bug
duplicate
2 (Med Risk)
upgraded by judge

Awards

246.5367 USDC - $246.54

External Links

Judge has assessed an item in Issue #225 as Medium risk. The relevant finding follows:

C4-011 : Centralization Risk On The teamSummon Function - LOW

Impact - LOW

With the teamSummon function, owner can mint unlimited warriors. This poses a security risk. The max/min limit should be implemented at the beginning of the function.

Proof of Concept

  1. Navigate to the following contract.

  2. The following contract function has an onlyOwner modifier and there is no limitation on the minting.

https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L257
function teamSummon(address recipient, uint256 count) external onlyOwner { require(address(recipient) != address(0), 'address req'); for (uint256 i = 0; i < count; i++) { _mint(recipient); } }

Tools Used

Code Review

It is recommended to implement limitation on the teamSummon function. The team should not mint without any restriction.

#0 - gzeoneth

2022-06-19T16:00:33Z

ISSUE LIST

C4-001: Missing events for only functions that change critical parameters - Non Critical

C4-002 : Critical changes should use two-step procedure - Non Critical

C4-003 : Pragma Version - Non Critical

C4-004 : Missing zero-address check in the setter functions and initiliazers - Low

C4-005 : Missing sanity check on the timestamps - Low

C4-006 : transferOwnership should be two step - Non critical

C4-007 : Bump OZ packages to ^4.5.0. - Non critical

C4-008 : Use safeTransfer/safeTransferFrom consistently instead of transfer/transferFrom - Non critical

C4-009 : Front-running is possible over the bidding mechanism - LOW

C4-010 : The Dutch Auction Parameters Can be Manipulated By Owner After The Auction Started - LOW

C4-011 : Centralization Risk On The teamSummon Function - LOW

ISSUES

C4-001 : Missing events for only functions that change critical parameters

Impact - Non critical

The afunctions that change critical parameters should emit events. Events allow capturing the changed parameters so that off-chain tools/interfaces can register such changes with timelocks that allow users to evaluate them and consider if they would like to engage/exit based on how they perceive the changes as affecting the trustworthiness of the protocol or profitability of the implemented financial services. The alternative of directly querying on-chain contract state for such changes is not considered practical for most users/usages.

Missing events and timelocks do not promote transparency and if such changes immediately affect users’ perception of fairness or trustworthiness, they could exit the protocol causing a reduction in liquidity which could negatively impact protocol TVL and reputation.

Proof of Concept

  1. Navigate to the following contract.
https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L441 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L448 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L455 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L462 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L469 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L480

See similar High-severity H03 finding OpenZeppelin’s Audit of Audius (https://blog.openzeppelin.com/audius-contracts-audit/#high) and Medium-severity M01 finding OpenZeppelin’s Audit of UMA Phase 4 (https://blog.openzeppelin.com/uma-audit-phase-4/)

Tools Used

None

Add events to all functions that change critical parameters.

C4-002 : Critical changes should use two-step procedure

Impact - NON CRITICAL

The critical procedures should be two step process.

Proof of Concept

  1. Navigate to the following contract.
https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L441 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L448 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L455 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L462 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L469 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L480

Tools Used

Code Review

Lack of two-step procedure for critical operations leaves them error-prone. Consider adding two step procedure on the critical functions.

C4-003 : # Pragma Version

Impact

In the contracts, floating pragmas should not be used. Contracts should be deployed with the same compiler version and flags that they have been tested with thoroughly. Locking the pragma helps to ensure that contracts do not accidentally get deployed using, for example, an outdated compiler version that might introduce bugs that affect the contract system negatively.

## Proof of Concept

https://swcregistry.io/docs/SWC-103

All Contracts

Tools Used

Manual code review

Lock the pragma version: delete pragma solidity 0.8.10 in favor of pragma solidity 0.8.10.

C4-004 : # Missing zero-address check in the setter functions and initiliazers

Impact

Missing checks for zero-addresses may lead to infunctional protocol, if the variable addresses are updated incorrectly.

Proof of Concept

  1. Navigate to the following contracts.
https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L544 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L528

Tools Used

Code Review

Consider adding zero-address checks in the discussed constructors: require(newAddr != address(0));.

C4-005 : # Missing sanity check on the timestamps

Impact

During the code review, It has been observed that all timestamps are missing sanity checks. With the following scenario, that can have serious consequences.

Scenario

  • Admin initialize variables.
  • Auction/Bidding begans.
  • Admin set mistakenly old value (smaller than block.timestamp).
  • Auction bidding began with previous date instead of future date.

Proof of Concept

  1. Navigate to the following contracts.
https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L463 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L456 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L449 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L442

Tools Used

Code Review

Consider adding sanity check in the discussed setter functions: require(time >= block.timestamp);.

C4-006: transferOwnership should be two step

Impact - NON CRITICAL

The owner is the authorized user in the solidity contracts. Usually, an owner can be updated with transferOwnership function. However, the process is only completed with single transaction. If the address is updated incorrectly, an owner functionality will be lost forever.

Proof of Concept

  1. Navigate to the following contracts.
https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L15 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsGuild.sol#L14

Tools Used

Code Review

Lack of two-step procedure for critical operations leaves them error-prone. Consider adding two step procedure on the critical functions.

C4-007: Bump OZ packages to ^4.5.0.

Impact - NON CRITICAL

Line Reference

https://github.com/code-423n4/2022-05-runes/blob/main/package.json#L68

Description

I can verify that the installed version is 4.2.0 by executing the following commands:

yarn install yarn list @openzeppelin/contracts

Update the versions of @openzeppelin/contracts and @openzeppelin/contracts-upgradeable to be the latest in package.json. I also recommend double checking the versions of other dependencies as a precaution, as they may include important bug fixes.

C4-008 : Use safeTransfer/safeTransferFrom consistently instead of transfer/transferFrom

Impact - NON-CRITICAL

Impact

It is good to add a require() statement that checks the return value of token transfers or to use something like OpenZeppelin’s safeTransfer/safeTransferFrom unless one is sure the given token reverts in case of a failure. Failure to do so will cause silent failures of transfers and affect token accounting in contract.

Reference: This similar medium-severity finding from Consensys Diligence Audit of Fei Protocol: https://consensys.net/diligence/audits/2021/01/fei-protocol/#unchecked-return-value-for-iweth-transfer-call

Proof of Concept

  1. Navigate to the following contract.

  2. transfer/transferFrom functions are used instead of safe transfer/transferFrom on the following contracts.

https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsGuild.sol#L175

Tools Used

Code Review

Consider using safeTransfer/safeTransferFrom or require() consistently.

C4-009 : Front-running is possible over the minting process - LOW

Impact - LOW

Impact

During the code review, It has been noticed that to bidding mechanism is vulnerable to front-running. The bidding mechanism can have EOA check on the contract.

Proof of Concept

  1. Navigate to the following contract.

  2. The contract does not check for the External Owned Accounts. Without the check, any contract can interact with the function.

https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L120

Tools Used

Code Review

Consider to check EOA at the beginning of the function.

msg.sender == tx.origin && !isContract(msg.sender)

C4-010 : The Dutch Auction Parameters Can be Manipulated By Owner After The Auction Started - LOW

Impact - LOW

Dutch Auction parameters can be changed by a malicious owner, after It is started. The malicious owner can manipulate all contract behaviour.

Proof of Concept

  1. Navigate to the following contract.

  2. The contract should implement the pause modifier on the setter functions.

https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L120
function setDaStartTime(uint256 _newTime) public onlyOwner { daStartTime = _newTime; } /** * @notice set the mintlist start timestamp */ function setMintlistStartTime(uint256 _newTime) public onlyOwner { mintlistStartTime = _newTime; } /** * @notice set the public sale start timestamp */ function setPublicStartTime(uint256 _newTime) public onlyOwner { publicStartTime = _newTime; } /** * @notice set the claims phase start timestamp */ function setClaimsStartTime(uint256 _newTime) public onlyOwner { claimsStartTime = _newTime; } /** * @notice set the self refund phase start timestamp */ function setSelfRefundsStartTime(uint256 _newTime) public onlyOwner { selfRefundsStartTime = _newTime; }

Tools Used

Code Review

Implement whenNotPaused modifier on the setter function. The variables should be changed when the contract is paused.

function setDaStartTime(uint256 _newTime) public onlyOwner whenNotPaused { daStartTime = _newTime; }

C4-011 : Centralization Risk On The teamSummon Function - LOW

Impact - LOW

With the teamSummon function, owner can mint unlimited warriors. This poses a security risk. The max/min limit should be implemented at the beginning of the function.

Proof of Concept

  1. Navigate to the following contract.

  2. The following contract function has an onlyOwner modifier and there is no limitation on the minting.

https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L257
function teamSummon(address recipient, uint256 count) external onlyOwner { require(address(recipient) != address(0), 'address req'); for (uint256 i = 0; i < count; i++) { _mint(recipient); } }

Tools Used

Code Review

It is recommended to implement limitation on the teamSummon function. The team should not mint without any restriction.

#0 - gzeoneth

2022-06-20T17:40:49Z

5, 10, 11 upgraded 4, 9(#147) Low 1, 2, 3, 6, 7, 8 Non-Critical

ISSUE LIST

C4-001: Revert String Size Optimization

C4-002 : Adding unchecked directive can save gas

C4-003 : Check if amount > 0 before token transfer can save gas

C4-004 : There is no need to assign default values to variables

C4-005: > 0 can be replaced with != 0 for gas optimization

C4-006 : Free gas savings for using solidity 0.8.10+

C4-007 : ++i is more gas efficient than i++ in loops forwarding

C4-008 : Using operator && used more gas

C4-009 : Redundant Msg Sender Check

C4-010 : Non-strict inequalities are cheaper than strict ones

C4-011 : Use Custom Errors instead of Revert Strings to save Gas

C4-001: Revert String Size Optimization

Impact

Shortening revert strings to fit in 32 bytes will decrease deploy time gas and will decrease runtime gas when the revert condition has been met.

Revert strings that are longer than 32 bytes require at least one additional mstore, along with additional overhead for computing memory offset, etc.

Proof of Concept

Revert strings > 32 bytes are here:

https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsGuild.sol#L70 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsGuild.sol#L116

Tools Used

Manual Review

Shorten the revert strings to fit in 32 bytes. That will affect gas optimization.

C4-002 : Adding unchecked directive can save gas

Impact

For the arithmetic operations that will never over/underflow, using the unchecked directive (Solidity v0.8 has default overflow/underflow checks) can save some gas from the unnecessary internal over/underflow checks.

Proof of Concept

https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsGuild.sol#L104 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L219 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L220

Tools Used

None

Consider applying unchecked arithmetic where overflow/underflow is not possible. Example can be seen from below.

Unchecked{i++};

C4-003 : Check if amount > 0 before token transfer can save gas

Impact

Since _amount can be 0. Checking if (_amount != 0) before the transfer can potentially save an external call and the unnecessary gas cost of a 0 token transfer.

Proof of Concept

https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L627 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L610

All Contracts

Tools Used

None

Consider checking amount != 0.

C4-004 : There is no need to assign default values to variables

Impact - Gas Optimization

When a variable is declared solidity assigns the default value. In case the contract assigns the value again, it costs extra gas.

Example: uint x = 0 costs more gas than uint x without having any different functionality.

Proof of Concept

https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L259 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L162

Tools Used

Code Review

uint x = 0 costs more gas than uint x without having any different functionality.

C4-005: > 0 can be replaced with != 0 for gas optimization

Impact

!= 0 is a cheaper operation compared to > 0, when dealing with uint. (Before Pragma 0.8.13)

Proof of Concept

  1. Navigate to the following contracts.
https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L211 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L378 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L141

Tools Used

Code Review

Use "!=0" instead of ">0" for the gas optimization.

C4-006 : Free gas savings for using solidity 0.8.10+

Impact

Using newer compiler versions and the optimizer gives gas optimizations and additional safety checks are available for free.

Proof of Concept

All Contracts

Solidity 0.8.10 has a useful change which reduced gas costs of external calls which expect a return value: https://blog.soliditylang.org/2021/11/09/solidity-0.8.10-release-announcement/

Solidity 0.8.13 has some improvements too but not well tested.

Code Generator: Skip existence check for external contract if return data is expected. In this case, the ABI decoder will revert if the contract does not exist

All Contracts

Tools Used

None

Consider to upgrade pragma to at least 0.8.10.

C4-007 : ++i is more gas efficient than i++ in loops forwarding

Impact

++i is more gas efficient than i++ in loops forwarding.

Proof of Concept

  1. Navigate to the following contracts.
https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L259 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L162

Tools Used

Code Review

It is recommend to use unchecked{++i} and change i declaration to uint256.

C4-008 : Using operator && used more gas

Impact

Using double require instead of operator && can save more gas.

Proof of Concept

  1. Navigate to the following contracts.
https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L141 https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L211

Tools Used

Code Review

Example

using &&: function check(uint x)public view{ require(x == 0 && x < 1 ); } // gas cost 21630 using double require: require(x == 0 ); require( x < 1); } } // gas cost 21622

C4-009 : Redundant Msg Sender Check

Impact

During the code review, It has been observed that the following check is redundant. Msg.sender can not be never zero address.

require(address(msg.sender) != address(0));

Proof of Concept

  1. Navigate to the following contract.

https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L628

Tools Used

Code Review

Delete redundant check.

C4-010 : Non-strict inequalities are cheaper than strict ones

Impact

Strict inequalities add a check of non equality which costs around 3 gas.

Proof of Concept

https://github.com/code-423n4/2022-05-runes/blob/main/contracts/ForgottenRunesWarriorsMinter.sol#L355

Tools Used

Code Review

Use >= or <= instead of > and < when possible.

C4-011 : Use Custom Errors instead of Revert Strings to save Gas

Custom errors from Solidity 0.8.4 are cheaper than revert strings (cheaper deployment cost and runtime cost when the revert condition is met)

Source Custom Errors in Solidity:

Starting from Solidity v0.8.4, there is a convenient and gas-efficient way to explain to users why an operation failed through the use of custom errors. Until now, you could already use strings to give more information about failures (e.g., revert("Insufficient funds.");), but they are rather expensive, especially when it comes to deploy cost, and it is difficult to use dynamic information in them.

Custom errors are defined using the error statement, which can be used inside and outside of contracts (including interfaces and libraries).

Instances include:

All require Statements

Tools Used

Code Review

Recommended to replace revert strings with custom errors.

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter