Gas: Improve validateWeights
uniqueness check
#226
Labels
bug
Warden finding
duplicate
Another warden found this issue
G (Gas Optimization)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
cmichel
Vulnerability details
The
Basket.validateWeights
function checks the uniqueness of the tokens by iterating over all tokens for each token.This runs in
O(_tokens.length^2)
and is very inefficient as the number of tokens increases.Recommended Mitigation Steps
Sort the tokens off-chain and provide them already in a sorted (ascending) way.
Then the
validateWeights
function only needs to verify that the tokens are indeed strictly sorted which runs in linear time:The text was updated successfully, but these errors were encountered: