Template implementations doesn't validate configurations properly
The NFT template contracts fail to validate royalty configuration fields in their initialize and update functions, allowing an admin to set a royalty percentage above 100%. An attacker with admin access could set an excessive royalty, causing users to pay more than the sale price in royalties.
ElKu Follow with rvierdiiev, obront and 9 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-10-nftport-judging/issues/83
Found by
ElKu, rvierdiiev, obront, pashov, ctf_sec, joestakey, ak1, JohnnyTime, GimelSec, Dravee, JohnSmith, cccz
Summary
In past audits, we have seen contract admins claim that invalidated configuration setters are fine since “admins are trustworthy”. However, cases such as Nomad got drained for over $150M and Misconfiguration in the Acala stablecoin project allows attacker to steal 1.2 billion aUSD have shown again and again that even trustable entities can make mistakes. Thus any fields that might potentially result in insolvency of protocol should be thoroughly checked.
NftPort template implementations often ignore checks for config fields. For the rest of the issue, we take royalty related fields as an example to illustrate potential consequences of misconfigurations. Notably, lack of check is not limited to royalty, but exists among most config fields.
Admins are allowed to set a wrong royaltiesBps which is higher than ROYALTIES_BASIS. royaltyInfo() will accept this invalid royaltiesBps and users will pay a large amount of royalty.
Vulnerability Detail
EIP-2981 (NFT Royalty Standard) defines royaltyInfo() function that specifies how much to pay for a given sale price. In general, royalty should not be higher than 100%. NFTCollection.sol checks that admins can't set royalties to more than 100%:
/// Validate a runtime configuration change
function _validateRuntimeConfig(RuntimeConfig calldata config)
internal
view
{
// Can't set royalties to more than 100%
require(config.royaltiesBps <= ROYALTIES_BASIS, "Royalties too high");
...
But NFTCollection only check royaltiesBps when admins call updateConfig(), it doesn't check royaltiesBps in initialize() function, leading to admins could set an invalid royaltiesBps (higher than 100%) when initializing contracts.
The same problem exists in ERC721NFTProduct and ERC1155NFTProduct. Both ERC721NFTProduct and ERC1155NFTProduct don't check royaltiesBasisPoints in initialize() function. Furthermore, these contracts also don't check royaltiesBasisPoints when admins call update() function. It means that admins could set an invalid royaltiesBasisPoints which may be higher than 100% in any time.
Impact
EIP-2981 only defines royaltyInfo() that it should return royalty amount rather than royalty percentage. It means that if the contract has an invalid royalty percentage which is higher than 100%, royaltyInfo() doesn't revert and users will pay a large amount of royalty.
Code Snippet
https://github.com/sherlock-audit/2022-10-nftport/blob/main/evm-minting-master/contracts/templates/NFTCollection.sol#L348 https://github.com/sherlock-audit/2022-10-nftport/blob/main/evm-minting-master/contracts/templates/NFTCollection.sol#L153 https://github.com/sherlock-audit/2022-10-nftport/blob/main/evm-minting-master/contracts/templates/ERC721NFTProduct.sol#L91 https://github.com/sherlock-audit/2022-10-nftport/blob/main/evm-minting-master/contracts/templates/ERC721NFTProduct.sol#L201 https://github.com/sherlock-audit/2022-10-nftport/blob/main/evm-minting-master/contracts/templates/ERC1155NFTProduct.sol#L96 https://github.com/sherlock-audit/2022-10-nftport/blob/main/evm-minting-master/contracts/templates/ERC1155NFTProduct.sol#L238
Tool used
Manual Review
Recommendation
Check royaltiesBps <= ROYALTIES_BASIS both in initialize() and update() functions.
Discussion
hyperspacebunny
Fixed in https://github.com/nftport/evm-minting-sherlock-fixes/pull/11
rayn731
LGTM, It checks royaltiesBps both in initialize() and update() functions.
And uses _validatePropertyChange() to check values both in initialize() and updateConfig() functions.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the initialize and update functions lack the same validation check that exists in the updateConfig function, so invalid royalty values can be set.
Impact
If an admin sets an invalid royalty percentage above 100%, users will pay a large amount of royalty because the royaltyInfo function does not revert.
What the attacker needed
Admin access to set config
The fix
The contracts were fixed by adding checks for royaltiesBps in both initialize and update functions.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
These smart contracts let an administrator set a royalty percentage, which is how much of each sale goes to the creator. The contracts check this percentage in some places but not when the contract is first set up or when the admin updates it later. So an admin could accidentally set a royalty above 100%, and buyers would end up paying more than the item's price in fees.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.