Omniscia Arcade XYZ Audit

ArcadeItemsVerifier Code Style Findings

ArcadeItemsVerifier Code Style Findings

AIV-01C: Loop Iterator Optimization

Description:

The linked for loop increments / decrements the iterator "safely" due to Solidity's built-in safe arithmetics (post-0.8.X).

Example:

contracts/verifiers/ArcadeItemsVerifier.sol
102for (uint256 i = 0; i < items.length; i++) {

Recommendation:

We advise the increment / decrement operation to be performed in an unchecked code block as the last statement within the for loop to optimize its execution cost.

Alleviation (7a4e1dc948e94ded7385dbb74818bcf93ecc207c):

The loop iterator has been optimized as advised, relocating it to a dedicated unchecked code block that optimizes its execution.

AIV-02C: Optimization of if Structure

Description:

The if-else-if structure within the ArcadeItemsVerifier::verifyPredicates function's for loop can be optimized as the last condition is redundantly evaluated.

Example:

contracts/verifiers/ArcadeItemsVerifier.sol
112if (item.cType == CollateralType.ERC_721) {
113 IERC721 asset = IERC721(item.asset);
114
115 // Wildcard, but vault has no assets or not enough specified
116 if (item.anyIdAllowed && asset.balanceOf(vault) < item.amount) return false;
117 // Does not own specifically specified asset
118 if (!item.anyIdAllowed && asset.ownerOf(item.tokenId) != vault) return false;
119} else if (item.cType == CollateralType.ERC_1155) {
120 IERC1155 asset = IERC1155(item.asset);
121
122 // Wildcard not allowed, since we can't check overall 1155 balances
123 if (item.anyIdAllowed) revert IV_InvalidWildcard(item.asset);
124
125 // Does not own specifically specified asset
126 if (asset.balanceOf(vault, item.tokenId) < item.amount) return false;
127} else if (item.cType == CollateralType.ERC_20) {

Recommendation:

Given that the CollateralType contract member represents an enum, the Solidity decoding mechanism will disallow values that cannot be cast to the enum.

As such, we advise the last else if conditional to be made a simple else clause optimizing the gas cost of the contract during EIP-20 balance validations.

Alleviation (7a4e1dc948e94ded7385dbb74818bcf93ecc207c):

The if-else-if structure has been optimized as advised, reducing the conditional's worst-case evaluation gas cost.