Forgotten Runes Warrior Guild contest - Cityscape'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: 84/93

Findings: 1

Award: $15.49

🌟 Selected for report: 0

🚀 Solo Findings: 0

Gas Optimazations

Unnecessarily initialized variable

uint256 public numMinted = 0;

change to

uint256 public numMinted;

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

for (uint256 i = 0; i < numWarriors; i++) {
            _mint(msg.sender);
        }

change to

for (uint256 i; i < numWarriors; i++) {
            _mint(msg.sender);
        }

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

for (uint256 i = 0; i < numWarriors; i++) {
            _mint(msg.sender);
        }

change to

    for (uint256 i; i < numWarriors;i++) {
            _mint(msg.sender);
        }

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


Pre-increment loop

for (uint256 i = 0; i < numWarriors; i++) {
            _mint(msg.sender);
        }

change to

for (uint256 i = 0; i < numWarriors;) {
            _mint(msg.sender);
            unchecked{ ++i; }
        }

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

for (uint256 i = 0; i < numWarriors; i++) {
            _mint(msg.sender);
        }

change to

    for (uint256 i = 0; i < numWarriors;) {
            _mint(msg.sender);
            unchecked{ ++i; }
        }

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

for (uint256 i = startIdx; i < endIdx + 1; i++) {
            _refundAddress(daMinters[i]);
        }

change to

for (uint256 i = startIdx; i < endIdx + 1;) {
            _refundAddress(daMinters[i]);
            unchecked{ ++i; }
        }

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


Minimizing storage reads

function currentDaPrice() public view returns (uint256) {

        if (!daStarted()) {
            return startPrice;
        }
        if (block.timestamp >= daStartTime + daPriceCurveLength) {
            // end of the curve
            return lowestPrice;
        }

        uint256 dropPerStep = (startPrice - lowestPrice) /
            (daPriceCurveLength / daDropInterval);

        uint256 elapsed = block.timestamp - daStartTime;
        uint256 steps = elapsed / daDropInterval;
        uint256 stepDeduction = steps * dropPerStep;

        // don't go negative in the next step
        if (stepDeduction > startPrice) {
            return lowestPrice;
        }
        uint256 currentPrice = startPrice - stepDeduction;
        return currentPrice > lowestPrice ? currentPrice : lowestPrice;
    }

change to:

function currentDaPrice() public view returns (uint256) {

        uint256 memory _startPrice = startPrice;
        uint256 memory _lowestPrice = lowestPrice;
        uint256 memory _daStartTime = daStartTime;
        uint256 memory _daPriceCurveLength = daPriceCurveLength;
        uint256 memory _daDropInterval = daDropInterval;

        if (!daStarted()) {
            return _startPrice;
        }
        if (block.timestamp >= _daStartTime + _daPriceCurveLength) {
            // end of the curve
            return _lowestPrice;
        }

        uint256 dropPerStep = (_startPrice - _lowestPrice) /
            (_daPriceCurveLength / _daDropInterval);

        uint256 elapsed = block.timestamp - _daStartTime;
        uint256 steps = elapsed / _daDropInterval;
        uint256 stepDeduction = steps * dropPerStep;

        // don't go negative in the next step
        if (stepDeduction > _startPrice) {
            return _lowestPrice;
        }
        uint256 currentPrice = _startPrice - stepDeduction;
        return currentPrice > _lowestPrice ? currentPrice : _lowestPrice;
    }

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

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