Skip to content

Same trait can appear twice in URI#

Low Risk

In URI.sol, there is getTraitsAndParams function that combines selected traits with static or random traits. In case that some traits are static and some are selected, getStaticTraits will be executed first to get the static traits and getSelectedTraits will be executed after to get the selected traits and combine them. In getSelectedTraits a trait will be assigned only if it is selectable and the selected value is not zero (meaning trait is not selected). In getStaticTraits all possible traits will be assigned. No matter if they are selectable or not. This results in the traits that are selected appearing twice. Once with the selected value and once with the default (first in array) value.

Recommendation#

Add an if statement in getStaticTraits function, that checks if trait is selectable and only add the ones that aren't to encodedTraits string. If the intended use case of the selected trait zero value is that it is not displayed, then also add a check if the selected value is zero.

for (uint256 i = 0; i < canvasTraits.length;) {
    if (!canvasTraits[i].selectable) {
        encodedTraits = string(abi.encodePacked(
        encodedTraits,
        '{"trait_type":"',
        canvasTraits[i].trait,
        '", "value":"',
        canvasTraits[i].values[0],
        '"},')
        );
    }
    unchecked { i++; }
}