code-423n4 / 2021-05-visorfinance-findings

0 stars 0 forks source link

Gas optimizations - storage over memory #53

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

a_delamo

Vulnerability details

Impact

In Visor.sol, the functions are using memory keyword, but using storage would reduce the gas cost.


    function _removeNft(address nftContract, uint256 tokenId) internal {
        uint256 len = nfts.length;
        for (uint256 i = 0; i < len; i++) {
            Nft memory nftInfo = nfts[i];
            if (
                nftContract == nftInfo.nftContract && tokenId == nftInfo.tokenId
            ) {
                if (i != len - 1) {
                    nfts[i] = nfts[len - 1];
                }
                nfts.pop();
                emit RemoveNftToken(nftContract, tokenId);
                break;
            }
        }
    }

Proof of Concept

https://docs.soliditylang.org/en/v0.4.21/types.html#reference-types

Tools Used

None

Recommended Mitigation Steps

ghost commented 3 years ago

sponsor confirmed We will be applying this optimization in our next version

ztcrypto commented 3 years ago

patch link