PhiNFT1155 contracts continue sending fees/royalties to old protocol destination address
Existing PhiNFT1155 contracts store the protocol fee destination address at initialisation and never update it, so after the factory owner changes the address, royalties and art creation fees continue to be sent to the old address. An attacker who controls the old address could keep receiving these funds.
MrPotatoMagic Follow with hgrano, 20centclub and 2 others
Originally disclosed on Code4rena
Submitted by MrPotatoMagic, also found by hgrano, 20centclub, 0xNirix, and 0xCiphky
When a PhiNFT1155.sol contract instance is created from the PhiFactory contract, the initialize() function is called to setup it. One of the parameters passed along is the protocolFeeDestination address, which is used as the default royalty recipient (see here) and the address that will receive the artCreate fees (see here).
Issue
The issue is that if the protocolFeeDestinationAddress contract is changed in the PhiFactory contract by the owner using function setProtocolFeeDestination(), the existing PhiNFT1155.sol contract instances created would still be using the old protocol fee destination address stored in them since it is not being dynamically retrieved from the PhiFactory contract. The protocolFeeDestination address could be updated for several reasons such as in case it is compromised, becomes malicious or there has been a decision made to make the address non-privileged.
Impact
Due to this, the old protocol fee destination address would still be receiving all the royalties (i.e., 500 bps = 5%) from all PhiNFT1155.sol contract instances. It would also be receiving all the artCreateFee amount of tokens when art is created through the createArtFromFactory() function.
Proof of Concept
- First we’ll take a look at the
protocolFeeDestinationaddress. As we can see below, once theprotocolFeeDestinationaddress is set through theinitialize()function on Line 122, there is no way to update it to the new address or no way to dynamically retrieve the latest address from the PhiFactory contract.
File: PhiNFT1155.sol
43: address public protocolFeeDestination;
... ...
File: PhiNFT1155.sol
095: function initialize(
096: uint256 credChainId_,
097: uint256 credId_,
098: string memory verificationType_,
099: address protocolFeeDestination_
100: )
101: external
102: initializer
103: {
104: ...
109: initializeRoyalties(protocolFeeDestination_);
110:
111: ...
120: phiFactoryContract = IPhiFactory(payable(msg.sender));
121:
122: protocolFeeDestination = phiFactoryContract.protocolFeeDestination();
123: ...
126: }
- Now let’s say the owner of the PhiFactory contract calls the
setProtocolFeeDestination()function to update theprotocolFeeDestinationaddress in case the address is compromised, malicious or there has been a decision made to make the address non-privileged.
File: PhiFactory.sol
426: function setProtocolFeeDestination(address protocolFeeDestination_)
427: external
428: nonZeroAddress(protocolFeeDestination_)
429: onlyOwner
430: {
431: protocolFeeDestination = protocolFeeDestination_;
432: emit ProtocolFeeDestinationSet(protocolFeeDestination_);
433: }
- Now although the address has changed, the PhiNFT1155.sol contracts, which inherit the CreatorRoyaltiesControl.sol contract, still return the configuration
royaltyRecipientas the old address whenroyaltyInfo()function is called (which is used by external marketplaces). This is because wheninitializeRoyalties()was called, it permanently set theroyaltyRecipientequal to the old protocol fee destination address. SinceroyaltyRecipientdoes not dynamically retrieve the latest value through the factory, the royalties are paid to the old address.
File: CreatorRoyaltiesControl.sol
17: function initializeRoyalties(address _royaltyRecipient) internal {
18: if (_royaltyRecipient == address(0)) revert InvalidRoyaltyRecipient();
19: if (initialized) revert AlreadyInitialized();
20: royaltyRecipient = _royaltyRecipient;
21: initialized = true;
22: }
... ...
43: function royaltyInfo(
44: uint256 tokenId,
45: uint256 salePrice
46: )
47: public
48: view
49: returns (address receiver, uint256 royaltyAmount)
50: {
51: RoyaltyConfiguration memory config = getRoyalties(tokenId);
52: royaltyAmount = (config.royaltyBPS * salePrice) / ROYALTY_BPS_TO_PERCENT;
53: receiver = config.royaltyRecipient;
54: }
- Secondly, when multiple art creations occur through functions
_createNewNFTContract()and_useExistingNFTContract()in the PhiFactory contract, it calls thecreateArtFromFactory()function in the respective PhiNFT1155.sol contracts. Over here as we can see below, theartCreateFeeis still sent to the oldprotocolFeeDestinationaddress.
File: PhiNFT1155.sol
139: function createArtFromFactory(uint256 artId_) external payable onlyPhiFactory whenNotPaused returns (uint256) {
140: ...
143:
144: uint256 artFee = phiFactoryContract.artCreateFee();
145:
146: protocolFeeDestination.safeTransferETH(artFee);
147:
...
159: }
- To note, if the old
protocolFeeDestinationaddress is a contract implementation that turns out to be malicious (which could be one of the reasons why it is being replaced), it can revert in its fallback function to DOS art creations from factory for a credential; i.e.,credId. This impact is unlikely to occur since in most cases the fee destination would be an EOA. But the impacts mentioned in step 3 and 4 would be troublesome since all the existing PhiNFT1155.sol contracts would still be sending all the royalties and art creation fees to it.
Recommended Mitigation Steps
To solve the issue in CreatorRoyaltiesControl, consider retrieving the default royalty recipient variable dynamically from the phiFactory contract. The same would also need to be applied to the protocolFeeDestination address currently stored in the PhiNFT1155.sol contract.
Using dynamic retrieval from the factory would solve the issue for all PhiNFT1155.sol contract instances that were created.
Assessed type
Error
ZaK3939 (Phi) confirmed and commented:
This is a good observation. I appreciate it.
MrPotatoMagic (warden) commented:
@0xDjango - Could you please re-consider this issue and its dups for High-severity? It seems like the impact is rather suited as a high-severity bug since the protocol would be losing all the fees and royalties from all the PhiNFT1155.sol instances ever created as well as considering that the accumulated amount would become large over time.
bronze_pickaxe (warden) commented:
This has been correctly identified as a Medium severity issue. The preconditions are very unlikely - project changing their
protocolFeeDestinationaddress is extremely unlikely. Low likelihood + High impact = Medium severity.
I agree that this issue has high impact, but requires that the fee destination address be changed, which is rather unlikely in practice. Even in the case of a fee address update, the older fee address may still be functional and the desired location for the older fee accrual. Sticking with medium for these reasons.
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 fee destination and royalty recipient are stored as immutable values in each NFT contract instead of being read dynamically from the factory.
Impact
All royalties and art creation fees from existing PhiNFT1155 contracts would continue to go to the old address, which could be compromised or malicious; a malicious old address could also block art creation by reverting, though the report notes this is unlikely.
What the attacker needed
Factory owner changes the fee destination address; old address is compromised or malicious
The fix
The default royalty recipient and protocol fee destination should be retrieved dynamically from the factory contract instead of being stored in each NFT contract.
How it was found
- A PhiNFT1155 contract is created and initialised with the current protocol fee destination address.
- The factory owner calls setProtocolFeeDestination to change the address.
- Existing PhiNFT1155 contracts still return the old address as royalty recipient.
- Art creation fees are still sent to the old address.
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.
When a new NFT contract is created, it saves a copy of the address that should receive fees and royalties. If the owner later changes that address in the main factory, the old copies are not updated, so money keeps going to the old address. This is a problem if the old address is no longer trusted.
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.