CoCo Bottle Exchange
Smart Contract Audit Report
Audit Summary
CoCo Bottle Exchange is building a new platform where users can purchase and bid on NFTs.
For this audit, we reviewed the project team's BottleCollection contract at 0x92673ce80e22d22c62422f6b0aee761793ffce8e and BottleExchange contract at 0x7c97b834b4c3a56120d1c441d55193efbd7e2ee2 on the Polygon Mainnet.
Audit Findings
Low findings were identified and the team should consider resolving these issues. In addition, centralized aspects are present.
Date: August 26th, 2022.
Updated: September 9th, 2022 to reflect the project's newly deployed Mainnet addresses.Finding #1 - BottleCollection - High (Resolved)
Description: Any user can use the safeTransferFrom() or transferFrom() functions to transfer another user's NFTs without an approval as the _isApprovedOrOwner() function is not enforced.
Risk/Impact: Any user's NFTs can be transferred to another address without an approval.function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public override { require( lastOffer.bidder != from || (lastOffer.active == false || lastOffer.expirationDate <= block.timestamp), "You can't transfer NFTs if you have an offer active" ); _safeTransfer(from, to, tokenId, _data); transferOwnerTokens(from, to, tokenId); } ... function transferFrom( address from, address to, uint256 tokenId ) public virtual override { require( lastOffer.bidder != from || (lastOffer.active == false || lastOffer.expirationDate <= block.timestamp), "You can't transfer NFTs if you have an offer active" ); _transfer(from, to, tokenId); transferOwnerTokens(from, to, tokenId); }
Recommendation: The team should modify the safeTransferFrom() and transferFrom() functions to enforce the _isApprovedOrOwner() function which ensures that NFTs can only be transferred on behalf of another user if an approval has been granted.
Resolution: The team has implemented the above recommendation.
Finding #2 - BottleCollection - Medium (Resolved)
Description: Although the safeMint() function utilizes the onlyQuantityAllowed() modifier to enforce a maximum NFT limit per user, thequantityTokensMinted
for each user is not updated after minting NFTs.
Risk/Impact: Users are able to mint NFTs passed themaxTokensPerAddress
limit.
Recommendation:quantityTokensMinted
should be updated for each user after minting NFTs.
Resolution: The team has implemented the above recommendation.
Finding #3 - BottleCollection - Low
Description: Any excess ETH supplied to the contract during minting is not returned to the user.
Risk/Impact: Users will lose any excess funds sent as payment.
Recommendation: The contract should require the user supplies the exact amount of ETH needed to mint the desired amount of NFTs.
Resolution: The team has not yet addressed this issue.
Finding #4 - BottleCollection - Low (Resolved)
Description: The makeAnOfferForAll() unnecessarily enforces the payable() modifier as the sent funds are not used in the function.
Risk/Impact: Users will lose any ETH sent as payment.
Recommendation: The contract should remove the payable() modifier from the makeAnOfferForAll() function.
Resolution: The team has removed the payable() modifier from the makeAnOfferForAll() function.
Contracts Overview
BottleExchange Contract:
- As the contracts are implemented with Solidity v0.8.0, they are safe from any possible overflows/underflows.
BottleCollection Contract:
- The Collections Modificator role can add a new collection address at any time.
- Any user can exchange an added collection by specifying the collection address.
- The user must own every NFT in the collection in order for the exchange to occur successfully.
- Each owned NFT in the collection is burned and, in exchange, the user is minted an NFT from this contract.
- The contract uses a for loop to burn each NFT up to the maximum supply. The team must ensure the maximum supply is capped to prevent this loop from hitting the block gas limit.
- The Manually Exchange role can exchange a collection on behalf of any user. The users' NFTs are not burned during this method.
- The Collections Modificator role can edit an existing collection at any time by specifying a new collection address and URI.
- Any user can mint NFTs up to the maximum supply by specifying a quantity of NFTs, an amount of ETH, and a token address for payment.
- The contract uses a Chainlink Aggregator to fetch the latest price based on the latest "round data" of the contract. The Aggregator contract was outside of the scope of this audit so we cannot give an assessment with regard to security.
- If the user specified WETH as the token address, the payment will be with ETH.
- Users should exercise caution and ensure that the correct amount of ETH is supplied, as the contract will not return any excess ETH to the user.
- If the user specified a token address other than WETH, the token must have been previously added as a valid payment address by the team.
- The user must grant the contract an approval for the cost in order for the transaction to successfully occur when the payment is with a valid token.
- Any user can make an offer once the maximum supply of the collection has been minted by specifying an amount per token.
- Users must own at least 85% of the collection in order to make an offer.
- The specified amount per token must cover the price per NFT as well as the contract's additional pay per token percentage (set by the team).
- New offers cannot be made if an active offer currently exists.
- The user's offer in USDC will be transferred from the user to the contract.
- A 30 day expire time is automatically assigned to each offer.
- If the user decreases their offer amount, they can withdraw the difference between their original offer and the new offer when the new offer is currently expired.
- The last bidder can cancel their last active offer at any time which will transfer USDC back to the user for the amount that was originally supplied.
- Users can manually accept or decline the last active offer at any time.
- When the offer is accepted, the NFT(s) are transferred to the last bidder and USDC is transferred from the contract to the user that accepted the offer for the offer value of each NFT.
- When the number of non-answered offers for an NFT owner reaches the limit set by the team, the NFT(s) are transferred to the last bidder and USDC is transferred from the contract to the user that accepted the offer for the offer value of each NFT.
- A for loop is used to transfer tokens during this functionality. The team must ensure that the minimum percentage to offer value is high enough to prevent this loop from hitting the block gas limit.
- NFTs cannot be transferred if there is currently an active offer.
- The Limit Modificator role can update the max supply to any value at any time.
- The Limit Modificator role can update the default offer expiration time to any value at any time.
- The Limit Modificator role can update the quantity of non-answered offers threshold to any value at any time.
- The Limit Modificator role can update the percentage of a collection a user must own to make an offer to any value at any time.
- The Limit Modificator role can update the extra percentage of the minting price to pay when making an offer to any value at any time.
- The Limit Modificator role can set the max tokens per address to any value at any time.
- The Token/Addresses Modificator role can update the Exchange address at any time.
- The Token/Addresses Modificator role can update the price feed Aggregator at any time.
- The Price Modificator role can set the USD price to any value at any time.
- The Withdraw Modificator can withdraw any ETH or tokens sent as payment from the contract at any time.
- The URI Modificator role can update the Base URI at any time.
Audit Results
Vulnerability Category | Notes | Result |
---|---|---|
Arbitrary Jump/Storage Write | N/A | PASS |
Centralization of Control | The team can update the number of non-answered offers threshold that automatically triggers a transfer to any value. | PASS |
Compiler Issues | N/A | PASS |
Delegate Call to Untrusted Contract | N/A | PASS |
Dependence on Predictable Variables | N/A | PASS |
Ether/Token Theft | N/A | PASS |
Flash Loans | N/A | PASS |
Front Running | N/A | PASS |
Improper Events | N/A | PASS |
Improper Authorization Scheme | N/A | PASS |
Integer Over/Underflow | N/A | PASS |
Logical Issues | N/A | PASS |
Oracle Issues | N/A | PASS |
Outdated Compiler Version | N/A | PASS |
Race Conditions | N/A | PASS |
Reentrancy | N/A | PASS |
Signature Issues | N/A | PASS |
Unbounded Loops | The team should ensure that a proper limit is placed on the for loops in the exchangeCollectionManually() and makeAnOfferForAll() functions to prevent these loops from hitting the block gas limit. | WARNING |
Unused Code | N/A | PASS |
Overall Contract Safety | PASS |
Inheritance Chart
Function Graph
Functions Overview
($) = payable function
# = non-constant function
Int = Internal
Ext = External
Pub = Public
+ [Int] IERC165
- [Ext] supportsInterface
+ [Int] IERC721 (IERC165)
- [Ext] balanceOf
- [Ext] ownerOf
- [Ext] safeTransferFrom #
- [Ext] safeTransferFrom #
- [Ext] transferFrom #
- [Ext] approve #
- [Ext] setApprovalForAll #
- [Ext] getApproved
- [Ext] isApprovedForAll
+ [Int] IERC721Receiver
- [Ext] onERC721Received #
+ [Int] IERC721Metadata (IERC721)
- [Ext] name
- [Ext] symbol
- [Ext] tokenURI
+ [Lib] Address
- [Int] isContract
- [Int] sendValue #
- [Int] functionCall #
- [Int] functionCall #
- [Int] functionCallWithValue #
- [Int] functionCallWithValue #
- [Int] functionStaticCall
- [Int] functionStaticCall
- [Int] functionDelegateCall #
- [Int] functionDelegateCall #
- [Int] verifyCallResultFromTarget
- [Int] verifyCallResult
- [Prv] _revert
+ Context
- [Int] _msgSender
- [Int] _msgData
+ [Lib] Strings
- [Int] toString
- [Int] toHexString
- [Int] toHexString
- [Int] toHexString
+ ERC165 (IERC165)
- [Pub] supportsInterface
+ ERC721 (Context, ERC165, IERC721, IERC721Metadata)
- [Pub] #
- [Pub] supportsInterface
- [Pub] balanceOf
- [Pub] ownerOf
- [Pub] name
- [Pub] symbol
- [Pub] tokenURI
- [Int] _baseURI
- [Pub] approve #
- [Pub] getApproved
- [Pub] setApprovalForAll #
- [Pub] isApprovedForAll
- [Pub] transferFrom #
- [Pub] safeTransferFrom #
- [Pub] safeTransferFrom #
- [Int] _safeTransfer #
- [Int] _exists
- [Int] _isApprovedOrOwner
- [Int] _safeMint #
- [Int] _safeMint #
- [Int] _mint #
- [Int] _burn #
- [Int] _transfer #
- [Int] _approve #
- [Int] _setApprovalForAll #
- [Int] _requireMinted
- [Prv] _checkOnERC721Received #
- [Int] _beforeTokenTransfer #
- [Int] _afterTokenTransfer #
+ ERC721URIStorage (ERC721)
- [Pub] tokenURI
- [Int] _setTokenURI #
- [Int] _burn #
+ Pausable (Context)
- [Pub] #
- [Pub] paused
- [Int] _requireNotPaused
- [Int] _requirePaused
- [Int] _pause #
- modifiers: whenNotPaused
- [Int] _unpause #
- modifiers: whenPaused
+ Ownable (Context)
- [Pub] #
- [Pub] owner
- [Int] _checkOwner
- [Pub] renounceOwnership #
- modifiers: onlyOwner
- [Pub] transferOwnership #
- modifiers: onlyOwner
- [Int] _transferOwnership #
+ [Lib] Counters
- [Int] current
- [Int] increment #
- [Int] decrement #
- [Int] reset #
+ [Int] IAccessControl
- [Ext] hasRole
- [Ext] getRoleAdmin
- [Ext] grantRole #
- [Ext] revokeRole #
- [Ext] renounceRole #
+ AccessControl (Context, IAccessControl, ERC165)
- [Pub] supportsInterface
- [Pub] hasRole
- [Int] _checkRole
- [Int] _checkRole
- [Pub] getRoleAdmin
- [Pub] grantRole #
- modifiers: onlyRole
- [Pub] revokeRole #
- modifiers: onlyRole
- [Pub] renounceRole #
- [Int] _setupRole #
- [Int] _setRoleAdmin #
- [Int] _grantRole #
- [Int] _revokeRole #
+ [Int] IERC20
- [Ext] totalSupply
- [Ext] balanceOf
- [Ext] transfer #
- [Ext] allowance
- [Ext] approve #
- [Ext] transferFrom #
+ [Int] IERC20Metadata (IERC20)
- [Ext] name
- [Ext] symbol
- [Ext] decimals
+ ERC20 (Context, IERC20, IERC20Metadata)
- [Pub] #
- [Pub] name
- [Pub] symbol
- [Pub] decimals
- [Pub] totalSupply
- [Pub] balanceOf
- [Pub] transfer #
- [Pub] allowance
- [Pub] approve #
- [Pub] transferFrom #
- [Pub] increaseAllowance #
- [Pub] decreaseAllowance #
- [Int] _transfer #
- [Int] _mint #
- [Int] _burn #
- [Int] _approve #
- [Int] _spendAllowance #
- [Int] _beforeTokenTransfer #
- [Int] _afterTokenTransfer #
+ [Int] AggregatorV3Interface
- [Ext] decimals
- [Ext] description
- [Ext] version
- [Ext] getRoundData
- [Ext] latestRoundData
+ ReentrancyGuard
- [Pub] #
- [Prv] _nonReentrantBefore #
- [Prv] _nonReentrantAfter #
+ BottleCollection (ERC721, ERC721URIStorage, Pausable, AccessControl, Ownable)
- [Pub] #
- modifiers: ERC721
- [Pub] getPrice
- [Pub] isTokenAllowed
- [Pub] tokenIndex
- [Pub] pause #
- modifiers: onlyRole
- [Pub] unpause #
- modifiers: onlyRole
- [Int] buyWithToken #
- [Int] buyWithCurrency #
- [Ext] addTokenToBuy #
- modifiers: onlyRole
- [Ext] removeTokenToBuy #
- modifiers: onlyRole
- [Pub] safeMint ($)
- modifiers: whenNotPaused,onlyQuantityAllowed
- [Int] transferOwnerTokens #
- [Pub] safeTransferFrom #
- [Pub] transferFrom #
- [Int] _burn #
- [Pub] burn #
- [Int] checkAddress
- [Ext] makeAnOfferForAll ($)
- [Pub] cancelLastOffer #
- [Pub] getOfferAmountBack #
- [Int] _transferUSDC #
- [Pub] respondAnOffer #
- [Pub] getHaveAnsweredLastOffer
- [Pub] tokenURI
- [Ext] totalSupply
- [Pub] setBaseURI #
- modifiers: onlyRole
- [Ext] setUsdPrice #
- modifiers: onlyRole
- [Ext] setExchange #
- modifiers: onlyRole
- [Ext] setPriceFeed #
- modifiers: onlyRole
- [Ext] setMaxTokensPerAddress #
- modifiers: onlyRole
- [Ext] setMaxTokenSupply #
- modifiers: onlyRole
- [Ext] setExpirationOfferTimeDefault #
- modifiers: onlyRole
- [Ext] setPassiveNoUntilTransfer #
- modifiers: onlyRole
- [Ext] setMinimumPercentageToOffer #
- modifiers: onlyRole
- [Ext] setPercentageExtraToPayPerToken #
- modifiers: onlyRole
- [Pub] getOwnerTokens
- [Pub] withdrawMoneyTo #
- modifiers: onlyRole
- [Pub] withdrawTokensTo #
- modifiers: onlyRole
- [Pub] supportsInterface
+ BottleExchange (ERC721, AccessControl, Ownable)
- [Pub] #
- modifiers: ERC721
- [Pub] exchangeCollection #
- [Pub] exchangeCollectionManually #
- modifiers: onlyRole
- [Pub] addCollection #
- modifiers: onlyRole
- [Pub] editCollection #
- modifiers: onlyRole
- [Pub] tokenURI
- [Ext] totalSupply
- [Pub] safeTransferFrom #
- [Pub] transferFrom #
- [Pub] supportsInterface
Contract Source Summary and Visualizations
Name |
Address/Source Code |
Visualized |
{ContractName} |
{GitHub (Not yet deployed on mainnet) / ETH Mainnet / BSC Mainnet} |
About Solidity Finance
Solidity Finance was founded in 2020 and quickly grew to have one of the most experienced and well-equipped smart contract auditing teams in the industry. Our team has conducted 1300+ solidity smart contract audits covering all major project types and protocols, securing a total of over $50 billion U.S. dollars in on-chain value across 1500 projects!.
Our firm is well-reputed in the community and is trusted as a top smart contract auditing company for the review of solidity code, no matter how complex. Our team of experienced solidity smart contract auditors performs audits for tokens, NFTs, crowdsales, marketplaces, gambling games, financial protocols, and more!
Contact us today to get a free quote for a smart contract audit of your project!
What is a Solidity Audit?
Typically, a smart contract audit is a comprehensive review process designed to discover logical errors, security vulnerabilities, and optimization opportunities within code. A Solidity Audit takes this a step further by verifying economic logic to ensure the stability of smart contracts and highlighting privileged functionality to create a report that is easy to understand for developers and community members alike.
How Do I Interpret the Findings?
Each of our Findings will be labeled with a Severity level. We always recommend the team resolve High, Medium, and Low severity findings prior to deploying the code to the mainnet. Here is a breakdown on what each Severity level means for the project:
- High severity indicates that the issue puts a large number of users' funds at risk and has a high probability of exploitation, or the smart contract contains serious logical issues which can prevent the code from operating as intended.
- Medium severity issues are those which place at least some users' funds at risk and has a medium to high probability of exploitation.
- Low severity issues have a relatively minor risk association; these issues have a low probability of occurring or may have a minimal impact.
- Informational issues pose no immediate risk, but inform the project team of opportunities for gas optimizations and following smart contract security best practices.