Closed code423n4 closed 2 years ago
kenzo
The function creates and populates a new array to check for duplicates, this is not necessary.
Some amount of gas unnecessarily spent.
The relevant area: https://github.com/code-423n4/2021-09-defiProtocol/blob/52b74824c42acbcd64248f68c40128fe3a82caf6/contracts/contracts/Basket.sol#L56:#L69
Manual analysis, hardhat gas estimator.
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]); } }
Duplicate of #160
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: