Incorrect fee handling prevents protocol from updating fees
The fee setter functions in the Phi protocol incorrectly limit fees to 10,000 wei, while the intended fees are 0.00005 ETH (50,000,000,000 wei). This prevents the protocol from updating its mint and art creation fees to the documented values.
kn0t Follow with 0xc0ffEE, 0xrafaelnicolau and 7 others
Originally disclosed on Code4rena
Submitted by kn0t, also found by 0xc0ffEE, 0xrafaelnicolau, Decap, federodes, Ruhum (1, 2), CAUsr, OpaBatyo (1, 2), 0xNirix, 0xBugSlayer, 20centclub (1, 2), MrPotatoMagic, rbserver (1, 2), and 0xCiphky
The primary impact of this bug is that the protocol cannot change the mint and art creation fees as intended. This limitation has the following consequences:
The protocol is unable to set the correct mint fee of 0.00005 ETH per NFT minted, as documented in the specifications:
Mint Fee
This fee is applied when a Minter wants to mint a Cred NFT.
Protocol will have a mint price/fee of 0.00005 ETH.
function setProtocolFee(uint256 protocolFee_) external onlyOwner {
if (protocolFee_ > 10_000) revert ProtocolFeeTooHigh(); // @audit <== This check is incorrect
mintProtocolFee = protocolFee_;
emit ProtocolFeeSet(protocolFee_);
}
function setArtCreatFee(uint256 artCreateFee_) external onlyOwner {
if (artCreateFee_ > 10_000) revert ArtCreatFeeTooHigh(); // @audit <== This check is incorrect
artCreateFee = artCreateFee_;
emit ArtCreatFeeSet(artCreateFee_);
}
This discrepancy between the intended fee (0.00005 ETH) and the maximum settable fee (10,000 wei) renders the fee adjustment mechanism ineffective.
The protocol loses the ability to adjust its revenue model in response to market conditions or strategic decisions, as both the mint fee and art creation fee are effectively locked at their initial values.
Below lines demonstrate that the fees are being applied as direct values rather than percentages, contrary to the setter functions’ assumptions.
From src/PhiFactory.sol:
function _processClaim(
uint256 artId_,
address minter_,
address ref_,
address verifier_,
uint256 quantity_,
bytes32 data_,
string memory imageURI_,
uint256 etherValue_
)
private
{
PhiArt storage art = arts[artId_];
// Handle refund
uint256 mintFee = getArtMintFee(artId_, quantity_);
if ((etherValue_ - mintFee) > 0) {
_msgSender().safeTransferETH(etherValue_ - mintFee);
}
protocolFeeDestination.safeTransferETH(mintProtocolFee * quantity_); // @audit
From src/art/PhiNFT1155.sol:
function createArtFromFactory(uint256 artId_) external payable onlyPhiFactory whenNotPaused returns (uint256) {
_artIdToTokenId[artId_] = tokenIdCounter;
_tokenIdToArtId[tokenIdCounter] = artId_;
uint256 artFee = phiFactoryContract.artCreateFee();
protocolFeeDestination.safeTransferETH(artFee); // @audit
It’s important to note that while the immediate financial impact may be limited if the initial fees were set correctly, the long-term implications of this inflexibility could be significant for the protocol’s adaptability and financial management.
Proof of Concept
This POC demonstrates the inability to set the correct protocol and art creation fees as intended by the protocol.
- Add the test to the
TestPhiFactorycontract intest/PhiFactory.t.sol. - Run
forge test --mt test_ChangeProtocolFees.
function test_ChangeProtocolFees() public {
assertEq(phiFactory.owner(), owner, "owner is correct");
assertEq(phiFactory.mintProtocolFee(), PROTOCOL_FEE, "protocolFee is correct");
vm.startPrank(owner);
// maximum 10000 wei is allowed, but according to protocol documentations and deploy script it should be 0.00005 ether
vm.expectRevert(IPhiFactory.ProtocolFeeTooHigh.selector);
phiFactory.setProtocolFee(10001);
vm.expectRevert(IPhiFactory.ProtocolFeeTooHigh.selector);
phiFactory.setProtocolFee(0.00005 ether);
vm.expectRevert(IPhiFactory.ArtCreatFeeTooHigh.selector);
phiFactory.setArtCreatFee(10001);
vm.expectRevert(IPhiFactory.ArtCreatFeeTooHigh.selector);
phiFactory.setArtCreatFee(0.00005 ether);
vm.stopPrank();
}
Recommended Mitigation Steps
+ uint constant MAX_PROTOCOL_FEE = 0.00005 ether;
+ uint constant MAX_ART_CREATE_FEE = 0.00005 ether;
function setProtocolFee(uint256 protocolFee_) external onlyOwner {
- if (protocolFee_ > 10_000) revert ProtocolFeeTooHigh();
+ if (protocolFee_ > MAX_PROTOCOL_FEE) revert ProtocolFeeTooHigh();
mintProtocolFee = protocolFee_;
emit ProtocolFeeSet(protocolFee_);
}
function setArtCreatFee(uint256 artCreateFee_) external onlyOwner {
- if (artCreateFee_ > 10_000) revert ArtCreatFeeTooHigh();
+ if (artCreateFee_ > MAX_ART_CREATE_FEE) revert ArtCreatFeeTooHigh();
artCreateFee = artCreateFee_;
emit ArtCreatFeeSet(artCreateFee_);
}
ZaK3939 (Phi) confirmed and commented via duplicate Issue #13
To address this, we will modify the set function to use absolute values instead of percentages.
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
The setter functions use a hardcoded limit of 10,000 wei, which is far below the intended fee of 0.00005 ETH, likely due to confusion between percentages and absolute values.
Impact
The protocol cannot adjust its mint and art creation fees to the intended values, limiting its ability to adapt its revenue model.
What the attacker needed
Owner privileges
The fix
The setter functions should use the correct maximum fee values (0.00005 ether) instead of 10,000 wei.
How it was found
- Add the test to the TestPhiFactory contract in test/PhiFactory.t.sol.
- Run forge test --mt test_ChangeProtocolFees.
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.
The protocol has functions to change fees, but they have a check that only allows fees up to 10,000 wei (a tiny amount). The intended fee is 0.00005 ETH, which is much larger, so the owner can never set the correct fee. This means the protocol is stuck with whatever fees were set initially.
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.