From 8d30164067b6a76e160756d498fe03e4df76054e Mon Sep 17 00:00:00 2001 From: Peter Robinson Date: Tue, 22 Oct 2024 12:56:32 +1000 Subject: [PATCH] Resolve solhint and slither issues --- contracts/access/MintingAccessControl.sol | 2 +- contracts/bridge/x/v4/CoreV4.sol | 1 + .../deployer/create/OwnableCreateDeploy.sol | 4 +- .../create2/OwnableCreate2Deployer.sol | 2 +- .../create3/OwnableCreate3Address.sol | 3 + .../create3/OwnableCreate3Deployer.sol | 2 +- .../token/erc1155/abstract/ERC1155Permit.sol | 67 ++++++------------- .../erc1155/abstract/ImmutableERC1155Base.sol | 3 +- .../ImmutableERC20MinterBurnerPermit.sol | 3 +- .../erc721/abstract/ImmutableERC721Base.sol | 8 +-- .../abstract/ImmutableERC721HybridBase.sol | 8 +-- .../v1/interfaces/SIP5Interface.sol | 2 + .../v1/interfaces/SIP6EventsAndErrors.sol | 2 + .../v1/interfaces/SIP7EventsAndErrors.sol | 1 + .../v1/interfaces/SIP7Interface.sol | 2 + .../v2/interfaces/SIP5Interface.sol | 2 + .../v2/interfaces/SIP6EventsAndErrors.sol | 2 + .../v2/interfaces/SIP6Interface.sol | 2 +- .../v2/interfaces/SIP7EventsAndErrors.sol | 2 + .../v2/interfaces/SIP7Interface.sol | 2 + 20 files changed, 52 insertions(+), 68 deletions(-) diff --git a/contracts/access/MintingAccessControl.sol b/contracts/access/MintingAccessControl.sol index d12695b4..8cf06574 100644 --- a/contracts/access/MintingAccessControl.sol +++ b/contracts/access/MintingAccessControl.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.19; // solhint-disable no-unused-import -import {AccessControlEnumerable, AccessControl, IAccessControl} from "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; +import {AccessControlEnumerable} from "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; abstract contract MintingAccessControl is AccessControlEnumerable { /// @notice Role to mint tokens diff --git a/contracts/bridge/x/v4/CoreV4.sol b/contracts/bridge/x/v4/CoreV4.sol index 69f39ed6..bc643384 100644 --- a/contracts/bridge/x/v4/CoreV4.sol +++ b/contracts/bridge/x/v4/CoreV4.sol @@ -9,6 +9,7 @@ // the StarkEx contract ABI that was provided by StarkWare via slack. pragma solidity ^0.8.19; +// solhint-disable func-name-mixedcase interface CoreV4 { fallback() external payable; diff --git a/contracts/deployer/create/OwnableCreateDeploy.sol b/contracts/deployer/create/OwnableCreateDeploy.sol index 5f42ad71..5fad1a78 100644 --- a/contracts/deployer/create/OwnableCreateDeploy.sol +++ b/contracts/deployer/create/OwnableCreateDeploy.sol @@ -22,10 +22,10 @@ contract OwnableCreateDeploy { * @param bytecode The bytecode of the contract to be deployed */ // slither-disable-next-line locked-ether - function deploy(bytes memory bytecode) external payable { - // solhint-disable-next-line custom-errors + // solhint-disable-next-line custom-errors, reason-string require(msg.sender == owner, "CreateDeploy: caller is not the owner"); + // solhint-disable no-inline-assembly assembly { if iszero(create(callvalue(), add(bytecode, 32), mload(bytecode))) { revert(0, 0) diff --git a/contracts/deployer/create2/OwnableCreate2Deployer.sol b/contracts/deployer/create2/OwnableCreate2Deployer.sol index bb3891da..07e9e37f 100644 --- a/contracts/deployer/create2/OwnableCreate2Deployer.sol +++ b/contracts/deployer/create2/OwnableCreate2Deployer.sol @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache 2.0 pragma solidity 0.8.19; -import "@openzeppelin/contracts/access/Ownable.sol"; +import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {Deployer} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/deploy/Deployer.sol"; import {Create2} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/deploy/Create2.sol"; diff --git a/contracts/deployer/create3/OwnableCreate3Address.sol b/contracts/deployer/create3/OwnableCreate3Address.sol index 4fa726a5..34b8896b 100644 --- a/contracts/deployer/create3/OwnableCreate3Address.sol +++ b/contracts/deployer/create3/OwnableCreate3Address.sol @@ -15,6 +15,9 @@ abstract contract OwnableCreate3Address { bytes32 internal immutable createDeployBytecodeHash; constructor() { + // Slither is mistakenly seeing the expansion of type(OwnableCreateDeploy).creationCode + // as a very large number. + // slither-disable-next-line too-many-digits createDeployBytecodeHash = keccak256(type(OwnableCreateDeploy).creationCode); } diff --git a/contracts/deployer/create3/OwnableCreate3Deployer.sol b/contracts/deployer/create3/OwnableCreate3Deployer.sol index 1bc5bed5..ea5d67b4 100644 --- a/contracts/deployer/create3/OwnableCreate3Deployer.sol +++ b/contracts/deployer/create3/OwnableCreate3Deployer.sol @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache 2.0 pragma solidity 0.8.19; -import "@openzeppelin/contracts/access/Ownable.sol"; +import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {Deployer} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/deploy/Deployer.sol"; import {OwnableCreate3} from "./OwnableCreate3.sol"; diff --git a/contracts/token/erc1155/abstract/ERC1155Permit.sol b/contracts/token/erc1155/abstract/ERC1155Permit.sol index c522fe84..1dc60e78 100644 --- a/contracts/token/erc1155/abstract/ERC1155Permit.sol +++ b/contracts/token/erc1155/abstract/ERC1155Permit.sol @@ -2,26 +2,23 @@ // SPDX-License-Identifier: Apache 2.0 pragma solidity 0.8.19; -import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol"; -import "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; -import "@openzeppelin/contracts/interfaces/IERC1271.sol"; -import "solidity-bytes-utils/contracts/BytesLib.sol"; -import "./IERC1155Permit.sol"; +import {ERC1155Burnable, ERC1155} from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol"; +import {EIP712, ECDSA} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; +import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol"; +import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol"; +import {IERC1155Permit} from "./IERC1155Permit.sol"; import {IImmutableERC1155Errors} from "../../../errors/Errors.sol"; abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImmutableERC1155Errors { - bytes32 private immutable _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,bool approved,uint256 nonce,uint256 deadline)"); - mapping(address => uint256) private _nonces; + mapping(address account => uint256 nonce) private _nonces; - constructor(string memory name, string memory uri) - ERC1155(uri) - EIP712(name, "1") - {} + constructor(string memory name, string memory uri) ERC1155(uri) EIP712(name, "1") {} function permit(address owner, address spender, bool approved, uint256 deadline, bytes memory sig) external { + // solhint-disable-next-line not-rely-on-time if (deadline < block.timestamp) { revert PermitExpired(); } @@ -30,7 +27,7 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm // smart contract signature validation if (_isValidERC1271Signature(owner, digest, sig)) { - _setApprovalForAll(owner, spender, approved); + _setApprovalForAll(owner, spender, approved); return; } @@ -63,9 +60,7 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm * @param owner The address for which to retrieve the nonce. * @return Current nonce of the given token. */ - function nonces( - address owner - ) external view returns (uint256) { + function nonces(address owner) external view returns (uint256) { return _nonces[owner]; } @@ -73,6 +68,7 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm * @notice Returns the domain separator used in the encoding of the signature for permits, as defined by EIP-712 * @return the bytes32 domain separator */ + // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view override returns (bytes32) { return _domainSeparatorV4(); } @@ -82,16 +78,10 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm * @param interfaceId The interface identifier, which is a 4-byte selector. * @return True if the contract implements `interfaceId` and the call doesn't revert, otherwise false. */ - function supportsInterface(bytes4 interfaceId) - public - view - virtual - override(ERC1155) - returns (bool) - { - return - interfaceId == type(IERC1155Permit).interfaceId || // 0x9e3ae8e4 - super.supportsInterface(interfaceId); + function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155) returns (bool) { + return + interfaceId == type(IERC1155Permit).interfaceId || // 0x9e3ae8e4 + super.supportsInterface(interfaceId); } /** @@ -107,18 +97,10 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm bool approved, uint256 deadline ) internal returns (bytes32) { - return _hashTypedDataV4( - keccak256( - abi.encode( - _PERMIT_TYPEHASH, - owner, - spender, - approved, - _nonces[owner]++, - deadline - ) - ) - ); + return + _hashTypedDataV4( + keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, approved, _nonces[owner]++, deadline)) + ); } /** @@ -128,14 +110,10 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm * @param sig The actual signature bytes. * @return True if the signature is valid according to EIP-1271, otherwise false. */ - function _isValidERC1271Signature(address spender, bytes32 digest, bytes memory sig) private view returns(bool) { + function _isValidERC1271Signature(address spender, bytes32 digest, bytes memory sig) private view returns (bool) { // slither-disable-next-line low-level-calls (bool success, bytes memory res) = spender.staticcall( - abi.encodeWithSelector( - IERC1271.isValidSignature.selector, - digest, - sig - ) + abi.encodeWithSelector(IERC1271.isValidSignature.selector, digest, sig) ); if (success && res.length == 32) { @@ -154,8 +132,7 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm * @param owner The owner of the tokens. * @return True if the signature is from an approved operator or owner, otherwise false. */ - function _isValidEOASignature(address recoveredSigner, address owner) private pure returns(bool) { + function _isValidEOASignature(address recoveredSigner, address owner) private pure returns (bool) { return recoveredSigner != address(0) && recoveredSigner == owner; } - } diff --git a/contracts/token/erc1155/abstract/ImmutableERC1155Base.sol b/contracts/token/erc1155/abstract/ImmutableERC1155Base.sol index 5fc6b72a..c298e3f7 100644 --- a/contracts/token/erc1155/abstract/ImmutableERC1155Base.sol +++ b/contracts/token/erc1155/abstract/ImmutableERC1155Base.sol @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache 2.0 pragma solidity 0.8.19; -import {ERC1155, ERC1155Permit} from "../../../token/erc1155/abstract/ERC1155Permit.sol"; +import {ERC1155Permit, ERC1155} from "../../../token/erc1155/abstract/ERC1155Permit.sol"; // Allowlist import {ERC2981} from "@openzeppelin/contracts/token/common/ERC2981.sol"; @@ -10,7 +10,6 @@ import {OperatorAllowlistEnforced} from "../../../allowlist/OperatorAllowlistEnf import {AccessControlEnumerable, MintingAccessControl} from "../../../access/MintingAccessControl.sol"; - abstract contract ImmutableERC1155Base is OperatorAllowlistEnforced, ERC1155Permit, ERC2981, MintingAccessControl { /// @dev Contract level metadata string public contractURI; diff --git a/contracts/token/erc20/preset/ImmutableERC20MinterBurnerPermit.sol b/contracts/token/erc20/preset/ImmutableERC20MinterBurnerPermit.sol index e9ed7948..16bff296 100644 --- a/contracts/token/erc20/preset/ImmutableERC20MinterBurnerPermit.sol +++ b/contracts/token/erc20/preset/ImmutableERC20MinterBurnerPermit.sol @@ -5,7 +5,8 @@ pragma solidity 0.8.19; import {ERC20Permit, ERC20} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; import {ERC20Capped} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol"; -import {MintingAccessControl, AccessControl, IAccessControl} from "../../../access/MintingAccessControl.sol"; +import {AccessControl, IAccessControl} from "@openzeppelin/contracts/access/AccessControl.sol"; +import {MintingAccessControl} from "../../../access/MintingAccessControl.sol"; import {IImmutableERC20Errors} from "./Errors.sol"; /** diff --git a/contracts/token/erc721/abstract/ImmutableERC721Base.sol b/contracts/token/erc721/abstract/ImmutableERC721Base.sol index 14c708ec..d9dac8b5 100644 --- a/contracts/token/erc721/abstract/ImmutableERC721Base.sol +++ b/contracts/token/erc721/abstract/ImmutableERC721Base.sol @@ -197,13 +197,7 @@ abstract contract ImmutableERC721Base is OperatorAllowlistEnforced, MintingAcces */ function supportsInterface( bytes4 interfaceId - ) - public - view - virtual - override(ERC721Permit, ERC2981, AccessControlEnumerable) - returns (bool) - { + ) public view virtual override(ERC721Permit, ERC2981, AccessControlEnumerable) returns (bool) { return super.supportsInterface(interfaceId); } diff --git a/contracts/token/erc721/abstract/ImmutableERC721HybridBase.sol b/contracts/token/erc721/abstract/ImmutableERC721HybridBase.sol index 942d0a02..154277e1 100644 --- a/contracts/token/erc721/abstract/ImmutableERC721HybridBase.sol +++ b/contracts/token/erc721/abstract/ImmutableERC721HybridBase.sol @@ -52,13 +52,7 @@ abstract contract ImmutableERC721HybridBase is /// @dev Returns the supported interfaces function supportsInterface( bytes4 interfaceId - ) - public - view - virtual - override(ERC721HybridPermit, ERC2981, AccessControlEnumerable) - returns (bool) - { + ) public view virtual override(ERC721HybridPermit, ERC2981, AccessControlEnumerable) returns (bool) { return super.supportsInterface(interfaceId); } diff --git a/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP5Interface.sol b/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP5Interface.sol index 1e434266..df422dbc 100644 --- a/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP5Interface.sol +++ b/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP5Interface.sol @@ -9,6 +9,8 @@ import {Schema} from "seaport-types/src/lib/ConsiderationStructs.sol"; * @dev SIP-5: Contract Metadata Interface for Seaport Contracts * https://github.com/ProjectOpenSea/SIPs/blob/main/SIPS/sip-5.md */ +// This contract name re-use is OK because the SIP5Interface is an interface and not a deployable contract. +// slither-disable-next-line name-reused interface SIP5Interface { /** * @dev An event that is emitted when a SIP-5 compatible contract is deployed. diff --git a/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP6EventsAndErrors.sol b/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP6EventsAndErrors.sol index 307518ed..d21ae7b1 100644 --- a/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP6EventsAndErrors.sol +++ b/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP6EventsAndErrors.sol @@ -7,6 +7,8 @@ pragma solidity ^0.8.17; * @notice SIP6EventsAndErrors contains errors and events * related to zone interaction as specified in the SIP6. */ +// This contract name re-use is OK because the SIP6EventsAndErrors is an interface and not a deployable contract. +// slither-disable-next-line name-reused interface SIP6EventsAndErrors { /** * @dev Revert with an error if SIP6 version is not supported diff --git a/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP7EventsAndErrors.sol b/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP7EventsAndErrors.sol index bd0caeb3..b41770ad 100644 --- a/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP7EventsAndErrors.sol +++ b/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP7EventsAndErrors.sol @@ -7,6 +7,7 @@ pragma solidity ^0.8.17; * @notice SIP7EventsAndErrors contains errors and events * related to zone interaction as specified in the SIP7. */ + interface SIP7EventsAndErrors { /** * @dev Emit an event when a new signer is added. diff --git a/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP7Interface.sol b/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP7Interface.sol index 9b96be0a..c3e60e8d 100644 --- a/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP7Interface.sol +++ b/contracts/trading/seaport/zones/immutable-signed-zone/v1/interfaces/SIP7Interface.sol @@ -11,6 +11,8 @@ pragma solidity ^0.8.17; * https://github.com/ProjectOpenSea/SIPs/blob/main/SIPS/sip-7.md * */ +// This contract name re-use is OK because the SIP7Interface is an interface and not a deployable contract. +// slither-disable-next-line name-reused interface SIP7Interface { /** * @dev The struct for storing signer info. diff --git a/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP5Interface.sol b/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP5Interface.sol index cfc156fd..47358aa9 100644 --- a/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP5Interface.sol +++ b/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP5Interface.sol @@ -11,6 +11,8 @@ import {SIP5EventsAndErrors} from "./SIP5EventsAndErrors.sol"; * @dev SIP-5: Contract Metadata Interface for Seaport Contracts * https://github.com/ProjectOpenSea/SIPs/blob/main/SIPS/sip-5.md */ +// This contract name re-use is OK because the SIP5Interface is an interface and not a deployable contract. +// slither-disable-next-line name-reused interface SIP5Interface is SIP5EventsAndErrors { /** * @dev Returns Seaport metadata for this contract, returning the diff --git a/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP6EventsAndErrors.sol b/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP6EventsAndErrors.sol index b4244c30..149e12eb 100644 --- a/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP6EventsAndErrors.sol +++ b/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP6EventsAndErrors.sol @@ -8,6 +8,8 @@ pragma solidity ^0.8.17; * @notice SIP6EventsAndErrors contains errors and events * related to zone interaction as specified in the SIP-6. */ +// This contract name re-use is OK because the SIP6EventsAndErrors is an interface and not a deployable contract. +// slither-disable-next-line name-reused interface SIP6EventsAndErrors { /** * @dev Revert with an error if SIP-6 version byte is not supported. diff --git a/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP6Interface.sol b/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP6Interface.sol index 2bc63899..3739500c 100644 --- a/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP6Interface.sol +++ b/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP6Interface.sol @@ -4,11 +4,11 @@ // solhint-disable compiler-version pragma solidity ^0.8.17; -import {Schema} from "seaport-types/src/lib/ConsiderationStructs.sol"; import {SIP6EventsAndErrors} from "./SIP6EventsAndErrors.sol"; /** * @dev SIP-6: Multi-Zone ExtraData * https://github.com/ProjectOpenSea/SIPs/blob/main/SIPS/sip-6.md */ +// solhint-disable no-empty-blocks interface SIP6Interface is SIP6EventsAndErrors {} diff --git a/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP7EventsAndErrors.sol b/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP7EventsAndErrors.sol index 52c0877b..e36d9f8f 100644 --- a/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP7EventsAndErrors.sol +++ b/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP7EventsAndErrors.sol @@ -8,6 +8,8 @@ pragma solidity ^0.8.17; * @notice SIP7EventsAndErrors contains errors and events * related to zone interaction as specified in the SIP-7. */ +// This contract name re-use is OK because the SIP7EventsAndErrors is an interface and not a deployable contract. +// slither-disable-next-line name-reused interface SIP7EventsAndErrors { /** * @dev Emit an event when a new signer is added. diff --git a/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP7Interface.sol b/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP7Interface.sol index 5e35d36e..ddad8419 100644 --- a/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP7Interface.sol +++ b/contracts/trading/seaport/zones/immutable-signed-zone/v2/interfaces/SIP7Interface.sol @@ -14,6 +14,8 @@ import {SIP7EventsAndErrors} from "./SIP7EventsAndErrors.sol"; * https://github.com/ProjectOpenSea/SIPs/blob/main/SIPS/sip-7.md * */ +// This contract name re-use is OK because the SIP7Interface is an interface and not a deployable contract. +// slither-disable-next-line name-reused interface SIP7Interface is SIP7EventsAndErrors { /** * @dev The struct for storing signer info.