code-423n4 / 2021-09-defiprotocol-findings

1 stars 0 forks source link

Only validateWeights when it is needed #95

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

itsmeSTYJ

Vulnerability details

Impact

Minor gas optimisation

Recommended Mitigation Steps

function publishNewIndex(address[] memory _tokens, uint256[] memory _weights) onlyPublisher public override {
    // validateWeights(_tokens, _weights); // delete this

    if (pendingWeights.pending) {
        require(block.number >= pendingWeights.block + TIMELOCK_DURATION);
        if (auction.auctionOngoing() == false) {
            auction.startAuction();

            emit PublishedNewIndex(publisher);
        } else if (auction.hasBonded()) {

        } else {
            auction.killAuction();
                        validateWeights(_tokens, _weights); // add here
            pendingWeights.tokens = _tokens;
            pendingWeights.weights = _weights;
            pendingWeights.block = block.number;
        }
    } else {
                validateWeights(_tokens, _weights); // add here
        pendingWeights.pending = true;
        pendingWeights.tokens = _tokens;
        pendingWeights.weights = _weights;
        pendingWeights.block = block.number;
    }
}
GalloDaSballo commented 2 years ago

Agree with the finding, saves gas in the best case