Gas Optimization Wrt. Token Uniqueness #160
Labels
bug
Warden finding
G (Gas Optimization)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
leastwood
Vulnerability details
Impact
The
validateWeights()
function can be better optimised by using a hashmap to measure token uniqueness. Currently, the function utilises anO(n^2)
solution. By first iterating through each hashmap index for_tokens
, any previously set tokens can be first cleared . This improves the current solution toO(n)
.Proof of Concept
https://github.com/code-423n4/2021-09-defiProtocol/blob/main/contracts/contracts/Basket.sol#L53-L70
Tools Used
Manual code review
Recommended Mitigation Steps
Consider using a hashmap to measure token uniqueness. However, this hashmap needs to first be cleared out before using it each time in
validateWeights()
.The text was updated successfully, but these errors were encountered: