Skip to content

Uint8 Comparison#


In ERC721Wrapper.sol wrap and unwrap functions, the for loop counter is a uint8

function wrapMany(uint256[] calldata tokenIds) external {
    for (uint8 i; i < tokenIds.length; i++) {
        _wrap(msg.sender, tokenIds[i]);
    _onTokenWrap(msg.sender, uint16(tokenIds.length));

uint8 is more expensive than uint256 because it is implicitly upcast to uint256 for each comparison to tokenIds.length.


  • Change uint8 counters to uint256
  • If the intent is to cap the number of wrappable NFTs to 255 via overflow reverts, this intent should be documented accordingly with a comment.