zellic-audit
Initial commit
f998fcd
raw
history blame
26.1 kB
{
"language": "Solidity",
"sources": {
"contracts/NFT/facets/BurnToPurchaseFacet.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.13;\n\nimport {LibDiamond} from \"../../shared/libraries/LibDiamond.sol\";\nimport {Modifiers} from \"../libraries/LibAppStorage.sol\";\nimport \"../libraries/LibERC721.sol\";\n\ncontract BurnToPurchaseFacet is Modifiers {\n /// Burns tokens on another contract with bulkBurn function and mints to the current contract\n function purchaseViaBulkBurn(\n address targetAddress,\n uint256[] memory burnTokens,\n address mpDiamond\n ) external payable {\n (bool success, ) = address(mpDiamond).call(abi.encodeWithSignature(\"bulkBurn(uint256[],address)\", burnTokens, msg.sender));\n\n require(success, \"Burning failed\");\n _mint(targetAddress, burnTokens.length);\n }\n\n /// Set to enable and disable bulk burning mint\n function setBulkBurningOpen(bool newBulkBurningOpenValue) external onlyEditor {\n s.bulkBurningOpen = newBulkBurningOpenValue;\n }\n\n /// Returns true if bulk burning mint is open\n function bulkBurningOpen() external view returns (bool) {\n return s.bulkBurningOpen;\n }\n\n /**\n * @dev Mints `quantity` tokens and transfers them to `to`.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - `quantity` must be greater than 0.\n *\n * Emits a {Transfer} event.\n */\n function _mint(address to, uint256 quantity) internal {\n uint256 _startingId = s._currentIndex;\n require(to > address(0), \"Zero address\");\n require(quantity > 0, \"Quantity zero\");\n\n _beforeTokenTransfers(address(0), to, _startingId, quantity);\n\n // Overflows are incredibly unrealistic.\n // balance or numberMinted overflow if current value of either + quantity > 1.8e19 (2**64) - 1\n // updatedIndex overflows if _currentIndex + quantity > 1.2e77 (2**256) - 1\n unchecked {\n s._addressData[to].balance += uint64(quantity);\n s._addressData[to].numberMinted += uint64(quantity);\n\n s._ownerships[_startingId].addr = to;\n s._ownerships[_startingId].startTimestamp = uint64(block.timestamp);\n\n uint256 updatedIndex = _startingId;\n uint256 end = updatedIndex + quantity;\n\n do {\n emit LibERC721.Transfer(address(0), to, updatedIndex++);\n } while (updatedIndex != end);\n\n s._currentIndex = updatedIndex;\n }\n _afterTokenTransfers(address(0), to, _startingId, quantity);\n }\n\n /**\n * @dev Hook that is called before a set of serially-ordered token ids are about to be transferred. This includes minting.\n * And also called before burning one token.\n *\n * _startTokenId - the first token id to be transferred\n * quantity - the amount to be transferred\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be\n * transferred to `to`.\n * - When `from` is zero, `tokenId` will be minted for `to`.\n * - When `to` is zero, `tokenId` will be burned by `from`.\n * - `from` and `to` are never both zero.\n */\n function _beforeTokenTransfers(\n address from,\n address to,\n uint256 _startingId,\n uint256 quantity\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes\n * minting.\n * And also called after one token has been burned.\n *\n * _startingId - the first token id to be transferred\n * quantity - the amount to be transferred\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` has been\n * transferred to `to`.\n * - When `from` is zero, `tokenId` has been minted for `to`.\n * - When `to` is zero, `tokenId` has been burned by `from`.\n * - `from` and `to` are never both zero.\n */\n function _afterTokenTransfers(\n address from,\n address to,\n uint256 _startingId,\n uint256 quantity\n ) internal virtual {}\n}\n"
},
"contracts/shared/libraries/LibDiamond.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.13;\n\n/******************************************************************************\\\n* Author: Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)\n* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535\n/******************************************************************************/\nimport { IDiamondCut } from \"../interfaces/IDiamondCut.sol\";\n\nlibrary LibDiamond {\n bytes32 constant DIAMOND_STORAGE_POSITION = keccak256(\"diamond.standard.diamond.storage\");\n\n struct DiamondStorage {\n // maps function selectors to the facets that execute the functions.\n // and maps the selectors to their position in the selectorSlots array.\n // func selector => address facet, selector position\n mapping(bytes4 => bytes32) facets;\n // array of slots of function selectors.\n // each slot holds 8 function selectors.\n mapping(uint256 => bytes32) selectorSlots;\n // The number of function selectors in selectorSlots\n uint16 selectorCount;\n // Used to query if a contract implements an interface.\n // Used to implement ERC-165.\n mapping(bytes4 => bool) supportedInterfaces;\n // owner of the contract\n address contractOwner;\n }\n\n function diamondStorage() internal pure returns (DiamondStorage storage ds) {\n bytes32 position = DIAMOND_STORAGE_POSITION;\n assembly {\n ds.slot := position\n }\n }\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n function setContractOwner(address _newOwner) internal {\n DiamondStorage storage ds = diamondStorage();\n address previousOwner = ds.contractOwner;\n ds.contractOwner = _newOwner;\n emit OwnershipTransferred(previousOwner, _newOwner);\n }\n\n function contractOwner() internal view returns (address contractOwner_) {\n contractOwner_ = diamondStorage().contractOwner;\n }\n\n function enforceIsContractOwner() internal view {\n require(msg.sender == diamondStorage().contractOwner, \"LibDiamond: Must be contract owner\");\n }\n\n event DiamondCut(IDiamondCut.FacetCut[] _diamondCut, address _init, bytes _calldata);\n\n bytes32 constant CLEAR_ADDRESS_MASK = bytes32(uint256(0xffffffffffffffffffffffff));\n bytes32 constant CLEAR_SELECTOR_MASK = bytes32(uint256(0xffffffff << 224));\n\n // Internal function version of diamondCut\n // This code is almost the same as the external diamondCut,\n // except it is using 'Facet[] memory _diamondCut' instead of\n // 'Facet[] calldata _diamondCut'.\n // The code is duplicated to prevent copying calldata to memory which\n // causes an error for a two dimensional array.\n function diamondCut(\n IDiamondCut.FacetCut[] memory _diamondCut,\n address _init,\n bytes memory _calldata\n ) internal {\n DiamondStorage storage ds = diamondStorage();\n uint256 originalSelectorCount = ds.selectorCount;\n uint256 selectorCount = originalSelectorCount;\n bytes32 selectorSlot;\n // Check if last selector slot is not full\n // \"selectorCount & 7\" is a gas efficient modulo by eight \"selectorCount % 8\" \n if (selectorCount & 7 > 0) {\n // get last selectorSlot\n // \"selectorSlot >> 3\" is a gas efficient division by 8 \"selectorSlot / 8\"\n selectorSlot = ds.selectorSlots[selectorCount >> 3];\n }\n // loop through diamond cut\n for (uint256 facetIndex; facetIndex < _diamondCut.length; facetIndex++) {\n (selectorCount, selectorSlot) = addReplaceRemoveFacetSelectors(\n selectorCount,\n selectorSlot,\n _diamondCut[facetIndex].facetAddress,\n _diamondCut[facetIndex].action,\n _diamondCut[facetIndex].functionSelectors\n );\n }\n if (selectorCount != originalSelectorCount) {\n ds.selectorCount = uint16(selectorCount);\n }\n // If last selector slot is not full\n // \"selectorCount & 7\" is a gas efficient modulo by eight \"selectorCount % 8\" \n if (selectorCount & 7 > 0) {\n // \"selectorSlot >> 3\" is a gas efficient division by 8 \"selectorSlot / 8\"\n ds.selectorSlots[selectorCount >> 3] = selectorSlot;\n }\n emit DiamondCut(_diamondCut, _init, _calldata);\n initializeDiamondCut(_init, _calldata);\n }\n\n function addReplaceRemoveFacetSelectors(\n uint256 _selectorCount,\n bytes32 _selectorSlot,\n address _newFacetAddress,\n IDiamondCut.FacetCutAction _action,\n bytes4[] memory _selectors\n ) internal returns (uint256, bytes32) {\n DiamondStorage storage ds = diamondStorage();\n require(_selectors.length > 0, \"LibDiamondCut: No selectors in facet to cut\");\n if (_action == IDiamondCut.FacetCutAction.Add) {\n enforceHasContractCode(_newFacetAddress, \"LibDiamondCut: Add facet has no code\");\n for (uint256 selectorIndex; selectorIndex < _selectors.length; selectorIndex++) {\n bytes4 selector = _selectors[selectorIndex];\n bytes32 oldFacet = ds.facets[selector];\n require(address(bytes20(oldFacet)) == address(0), \"LibDiamondCut: Can't add function that already exists\");\n // add facet for selector\n ds.facets[selector] = bytes20(_newFacetAddress) | bytes32(_selectorCount);\n // \"_selectorCount & 7\" is a gas efficient modulo by eight \"_selectorCount % 8\" \n uint256 selectorInSlotPosition = (_selectorCount & 7) << 5;\n // clear selector position in slot and add selector\n _selectorSlot = (_selectorSlot & ~(CLEAR_SELECTOR_MASK >> selectorInSlotPosition)) | (bytes32(selector) >> selectorInSlotPosition);\n // if slot is full then write it to storage\n if (selectorInSlotPosition == 224) {\n // \"_selectorSlot >> 3\" is a gas efficient division by 8 \"_selectorSlot / 8\"\n ds.selectorSlots[_selectorCount >> 3] = _selectorSlot;\n _selectorSlot = 0;\n }\n _selectorCount++;\n }\n } else if (_action == IDiamondCut.FacetCutAction.Replace) {\n enforceHasContractCode(_newFacetAddress, \"LibDiamondCut: Replace facet has no code\");\n for (uint256 selectorIndex; selectorIndex < _selectors.length; selectorIndex++) {\n bytes4 selector = _selectors[selectorIndex];\n bytes32 oldFacet = ds.facets[selector];\n address oldFacetAddress = address(bytes20(oldFacet));\n // only useful if immutable functions exist\n require(oldFacetAddress != address(this), \"LibDiamondCut: Can't replace immutable function\");\n require(oldFacetAddress != _newFacetAddress, \"LibDiamondCut: Can't replace function with same function\");\n require(oldFacetAddress != address(0), \"LibDiamondCut: Can't replace function that doesn't exist\");\n // replace old facet address\n ds.facets[selector] = (oldFacet & CLEAR_ADDRESS_MASK) | bytes20(_newFacetAddress);\n }\n } else if (_action == IDiamondCut.FacetCutAction.Remove) {\n require(_newFacetAddress == address(0), \"LibDiamondCut: Remove facet address must be address(0)\");\n // \"_selectorCount >> 3\" is a gas efficient division by 8 \"_selectorCount / 8\"\n uint256 selectorSlotCount = _selectorCount >> 3;\n // \"_selectorCount & 7\" is a gas efficient modulo by eight \"_selectorCount % 8\" \n uint256 selectorInSlotIndex = _selectorCount & 7;\n for (uint256 selectorIndex; selectorIndex < _selectors.length; selectorIndex++) {\n if (_selectorSlot == 0) {\n // get last selectorSlot\n selectorSlotCount--;\n _selectorSlot = ds.selectorSlots[selectorSlotCount];\n selectorInSlotIndex = 7;\n } else {\n selectorInSlotIndex--;\n }\n bytes4 lastSelector;\n uint256 oldSelectorsSlotCount;\n uint256 oldSelectorInSlotPosition;\n // adding a block here prevents stack too deep error\n {\n bytes4 selector = _selectors[selectorIndex];\n bytes32 oldFacet = ds.facets[selector];\n require(address(bytes20(oldFacet)) != address(0), \"LibDiamondCut: Can't remove function that doesn't exist\");\n // only useful if immutable functions exist\n require(address(bytes20(oldFacet)) != address(this), \"LibDiamondCut: Can't remove immutable function\");\n // replace selector with last selector in ds.facets\n // gets the last selector\n lastSelector = bytes4(_selectorSlot << (selectorInSlotIndex << 5));\n if (lastSelector != selector) {\n // update last selector slot position info\n ds.facets[lastSelector] = (oldFacet & CLEAR_ADDRESS_MASK) | bytes20(ds.facets[lastSelector]);\n }\n delete ds.facets[selector];\n uint256 oldSelectorCount = uint16(uint256(oldFacet));\n // \"oldSelectorCount >> 3\" is a gas efficient division by 8 \"oldSelectorCount / 8\"\n oldSelectorsSlotCount = oldSelectorCount >> 3;\n // \"oldSelectorCount & 7\" is a gas efficient modulo by eight \"oldSelectorCount % 8\" \n oldSelectorInSlotPosition = (oldSelectorCount & 7) << 5;\n }\n if (oldSelectorsSlotCount != selectorSlotCount) {\n bytes32 oldSelectorSlot = ds.selectorSlots[oldSelectorsSlotCount];\n // clears the selector we are deleting and puts the last selector in its place.\n oldSelectorSlot =\n (oldSelectorSlot & ~(CLEAR_SELECTOR_MASK >> oldSelectorInSlotPosition)) |\n (bytes32(lastSelector) >> oldSelectorInSlotPosition);\n // update storage with the modified slot\n ds.selectorSlots[oldSelectorsSlotCount] = oldSelectorSlot;\n } else {\n // clears the selector we are deleting and puts the last selector in its place.\n _selectorSlot =\n (_selectorSlot & ~(CLEAR_SELECTOR_MASK >> oldSelectorInSlotPosition)) |\n (bytes32(lastSelector) >> oldSelectorInSlotPosition);\n }\n if (selectorInSlotIndex == 0) {\n delete ds.selectorSlots[selectorSlotCount];\n _selectorSlot = 0;\n }\n }\n _selectorCount = selectorSlotCount * 8 + selectorInSlotIndex;\n } else {\n revert(\"LibDiamondCut: Incorrect FacetCutAction\");\n }\n return (_selectorCount, _selectorSlot);\n }\n\n function initializeDiamondCut(address _init, bytes memory _calldata) internal {\n if (_init == address(0)) {\n require(_calldata.length == 0, \"LibDiamondCut: _init is address(0) but_calldata is not empty\");\n } else {\n require(_calldata.length > 0, \"LibDiamondCut: _calldata is empty but _init is not address(0)\");\n if (_init != address(this)) {\n enforceHasContractCode(_init, \"LibDiamondCut: _init address has no code\");\n }\n (bool success, bytes memory error) = _init.delegatecall(_calldata);\n if (!success) {\n if (error.length > 0) {\n // bubble up the error\n revert(string(error));\n } else {\n revert(\"LibDiamondCut: _init function reverted\");\n }\n }\n }\n }\n\n function enforceHasContractCode(address _contract, string memory _errorMessage) internal view {\n uint256 contractSize;\n assembly {\n contractSize := extcodesize(_contract)\n }\n require(contractSize > 0, _errorMessage);\n }\n}\n"
},
"contracts/NFT/libraries/LibAppStorage.sol": {
"content": "//SPDX-License-Identifier: MIT\npragma solidity 0.8.13;\nimport {LibDiamond} from \"../../shared/libraries/LibDiamond.sol\";\n\n/// Compiler will pack this into a single 256bit word.\nstruct TokenOwnership {\n /// The address of the owner.\n address addr;\n /// Keeps track of the start time of ownership with minimal overhead for tokenomics.\n uint64 startTimestamp;\n /// Whether the token has been burned.\n bool burned;\n}\n\n/// Compiler will pack this into a single 256bit word.\nstruct AddressData {\n /// Realistically, 2**64-1 is more than enough.\n uint64 balance;\n /// Keeps track of mint count with minimal overhead for tokenomics.\n uint64 numberMinted;\n /// Keeps track of burn count with minimal overhead for tokenomics.\n uint64 numberBurned;\n /// For miscellaneous variable(s) pertaining to the address\n /// (e.g. number of whitelist mint slots used).\n /// If there are multiple variables, please pack them into a uint64.\n uint64 aux;\n}\n\n/// Defines attributes stored in diamond\n/// Many come from ERC721A\nstruct AppStorage {\n /// Name of contract\n string name;\n /// Symbol for contract\n string symbol;\n /// Base URI\n string baseURI;\n /// If true the public mint is open\n bool publicMintOpen;\n /// Price in WEI\n uint256 priceWEI;\n /// Total allowed to be minted\n uint256 saleLimit;\n /// If true the paid allow list mint is open\n bool allowListPaidOpen;\n /// If true the free allow list mint is open\n bool allowListFreeOpen;\n /// Royalty target address for ERC2981\n address _royaltyTarget;\n /// The max tokens allowed to be purchased in one transaction\n uint256 _maxAllowed;\n /// The tokenId of the next token to be minted\n uint256 _currentIndex;\n /// The number of tokens burned\n uint256 _burnCounter;\n /// Total revenue shares\n uint256 _totalShares;\n /// Total revenue released\n uint256 _totalReleased;\n /// Mapping from token ID to ownership details\n /// An empty struct value does not necessarily mean the token is unowned. See _ownershipOf implementation for details.\n mapping(uint256 => TokenOwnership) _ownerships;\n /// Mapping owner address to address data\n mapping(address => AddressData) _addressData;\n /// Mapping from token ID to approved address\n mapping(uint256 => address) _tokenApprovals;\n /// Mapping from owner to operator approvals\n mapping(address => mapping(address => bool)) _operatorApprovals;\n /// Mapping of Editors to contract\n mapping(address => bool) _editors;\n /// Mapping of revenue shares\n mapping(address => uint256) _shares;\n /// Mapping of total revenue released to each address\n mapping(address => uint256) _released;\n /// Mapping of allowed addresses to pay for minting before mint starts\n mapping(address => uint16) _allowListPaid;\n /// Mapping of allowed addresses to mint for free plus gas\n mapping(address => uint16) _allowListFree;\n /// Address of signer for verified mints\n address signer;\n /// Mapping of used verified messages\n mapping(uint32 => bool) _usedVerifiedMessages;\n /// If true the paid public max per wallet is open\n bool maxPerWalletPaidOpen;\n /// If true the free public max per wallet is open\n bool maxPerWalletFreeOpen;\n /// The max tokens allowed to be purchased per wallet\n uint256 _maxPerWallet;\n /// If true the paid public max per wallet is open\n bool bulkBurningOpen;\n //always add new state variables at the end\n}\n\nlibrary LibAppStorage {\n function diamondStorage() internal pure returns (AppStorage storage ds) {\n assembly {\n ds.slot := 0\n }\n }\n}\n\nerror CallerIsNotEditor();\n\ncontract Modifiers {\n AppStorage internal s;\n\n modifier onlyEditor() {\n if (!s._editors[msg.sender]) revert CallerIsNotEditor();\n _;\n }\n\n modifier onlyOwner() {\n LibDiamond.enforceIsContractOwner();\n _;\n }\n}\n"
},
"contracts/NFT/libraries/LibERC721.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.13;\n\nimport \"../interfaces/IERC721TokenReceiver.sol\";\n\nlibrary LibERC721 {\n /// @dev This emits when ownership of any NFT changes by any mechanism.\n /// This event emits when NFTs are created (`from` == 0) and destroyed\n /// (`to` == 0). Exception: during contract creation, any number of NFTs\n /// may be created and assigned without emitting Transfer. At the time of\n /// any transfer, the approved address for that NFT (if any) is reset to none.\n event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);\n\n /// @dev This emits when the approved address for an NFT is changed or\n /// reaffirmed. The zero address indicates there is no approved address.\n /// When a Transfer event emits, this also indicates that the approved\n /// address for that NFT (if any) is reset to none.\n event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);\n\n /// @dev This emits when an operator is enabled or disabled for an owner.\n /// The operator can manage all NFTs of the owner.\n event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);\n\n bytes4 internal constant ERC721_RECEIVED = 0x150b7a02;\n\n function checkOnERC721Received(\n address _operator,\n address _from,\n address _to,\n uint256 _tokenId,\n bytes memory _data\n ) internal {\n uint256 size;\n assembly {\n size := extcodesize(_to)\n }\n if (size > 0) {\n require(\n ERC721_RECEIVED == IERC721TokenReceiver(_to).onERC721Received(_operator, _from, _tokenId, _data),\n \"Transfer rejected/failed by _to\"\n );\n }\n }\n}\n"
},
"contracts/shared/interfaces/IDiamondCut.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.13;\n\n/******************************************************************************\\\n* Author: Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)\n* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535\n/******************************************************************************/\n\ninterface IDiamondCut {\n enum FacetCutAction {Add, Replace, Remove}\n // Add=0, Replace=1, Remove=2\n\n struct FacetCut {\n address facetAddress;\n FacetCutAction action;\n bytes4[] functionSelectors;\n }\n\n /// @notice Add/replace/remove any number of functions and optionally execute\n /// a function with delegatecall\n /// @param _diamondCut Contains the facet addresses and function selectors\n /// @param _init The address of the contract or facet to execute _calldata\n /// @param _calldata A function call, including function selector and arguments\n /// _calldata is executed with delegatecall on _init\n function diamondCut(\n FacetCut[] calldata _diamondCut,\n address _init,\n bytes calldata _calldata\n ) external;\n\n event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);\n}\n"
},
"contracts/NFT/interfaces/IERC721TokenReceiver.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.13;\n\n/// @dev Note: the ERC-165 identifier for this interface is 0x150b7a02.\ninterface IERC721TokenReceiver {\n /// @notice Handle the receipt of an NFT\n /// @dev The ERC721 smart contract calls this function on the recipient\n /// after a `transfer`. This function MAY throw to revert and reject the\n /// transfer. Return of other than the magic value MUST result in the\n /// transaction being reverted.\n /// Note: the contract address is always the message sender.\n /// @param _operator The address which called `safeTransferFrom` function\n /// @param _from The address which previously owned the token\n /// @param _tokenId The NFT identifier which is being transferred\n /// @param _data Additional data with no specified format\n /// @return `bytes4(keccak256(\"onERC721Received(address,address,uint256,bytes)\"))`\n /// unless throwing\n function onERC721Received(\n address _operator,\n address _from,\n uint256 _tokenId,\n bytes calldata _data\n ) external returns (bytes4);\n}\n"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}
}