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

1 stars 0 forks source link

Unnecessary new list in Basket's validateWeights() #32

Closed code423n4 closed 2 years ago

code423n4 commented 3 years ago

Handle

kenzo

Vulnerability details

The function creates and populates a new array to check for duplicates, this is not necessary.

Impact

Some amount of gas unnecessarily spent.

Proof of Concept

The relevant area: https://github.com/code-423n4/2021-09-defiProtocol/blob/52b74824c42acbcd64248f68c40128fe3a82caf6/contracts/contracts/Basket.sol#L56:#L69

Tools Used

Manual analysis, hardhat gas estimator.

Recommended Mitigation Steps

Change the check to the following:

for (uint i = 0; i < length; i++) {
    require(_tokens[i] != address(0));
    require(_weights[i] > 0);
    for (uint256 x = 0; x < i; x++) {
        require(_tokens[i] != _tokens[x]);
    }
}
GalloDaSballo commented 2 years ago

Duplicate of #160