Notional x Index Coop - 0xSolus's results

A collaboration between Notional and Index Coop to create fixed rate yield index tokens.

General Information

Platform: Code4rena

Start Date: 07/06/2022

Pot Size: $75,000 USDC

Total HM: 11

Participants: 77

Period: 7 days

Judge: gzeon

Total Solo HM: 7

Id: 124

League: ETH

Notional

Findings Distribution

Researcher Performance

Rank: 69/77

Findings: 1

Award: $47.60

🌟 Selected for report: 0

🚀 Solo Findings: 0

Redundant, unnecessary code

Starting in L#596 in the _getFCashPositions(), there's no need to repeat the same loop twice as it's unecessary. Instead, the second loop should be only used to allocate the correct memory space to the fCashPositions variable for only the amount of addresses it's going to store already calculated previously with j.

This is my proposed solution:

    function _getFCashPositions(ISetToken _setToken)
    internal
    view
    returns(address[] memory fCashPositions)
    {
        ISetToken.Position[] memory positions = _setToken.getPositions();
        uint positionsLength = positions.length;
        address[] memory tmp = new address[](positionsLength);
        uint j;

        for(uint256 i = 0; i < positionsLength; i++) {
            // Check that the given position is an equity position
            if(positions[i].unit > 0) {
                address component = positions[i].component;
                if(_isWrappedFCash(component)) {
			tmp[j] = component;
			j++;
                }
            }
        }
	// Write to memory with correct space
	fCashPositions = new address[](j);
        for(uint256 i = 0; i < j; i++) {
		fCashPositions[i] = tmp[i];
	}
    }

#0 - ckoopmann

2022-06-17T03:00:39Z

Interesting suggestion, that I don't remember seeing in any of the other issues so far. Will try this out, and probably apply if it passes tests and provides gas savings. (which it should since it avoids calling the rather expensive _isWrappedfCash method again).

Nice catch 👍

#1 - ckoopmann

2022-06-17T03:01:01Z

I guess this could also be considered a Gas optimization report.

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