Incorrect percentage calculation in NukeFund and EntityForging when taxCut is changed from default value
The contracts NukeFund and EntityForging calculate the developer's share by dividing the amount by taxCut, which only works correctly when taxCut is 10. If the owner changes taxCut to any other value, the percentage taken as fee becomes incorrect, leading to wrong fund distribution.
In both NukeFund::receive and EntityForging::forgeWithListed, if the owner changes taxCut from its default value of 10, the percentage calculations for fee distribution become severely inaccurate. This flaw can lead to:
Incorrect distribution of funds between developers, users, and the protocol.
Potential for significant financial losses or unintended gains.
Undermining of the protocol’s economic model.
Loss of user trust if discrepancies are noticed.
The root cause is the use of simple division instead of proper percentage calculation:
This is a test for the NukeFund, EntityForging is the same scenario just longer so I chose to send you the more concise test. We are going to set the taxCut to 5:
You can clearly see when it’s supposed to be “5%” tax, it’s instead 20%, leading the dev to get 2e17 of the 1e18 and the NukeFund getting 8e17.
Tools Used
Foundry
Recommended Mitigation Steps
Implement a basis point (BPS) system for precise percentage calculations. This means now that with a BPS value of 10_000 you would represent 10% as 1000 and 5% in our tests as 500.
Add the following changes:
At the top of EntityForging and NukeFund where state variables reside, add the following BPS state variable and change default taxCut of 10% to correspond to the BPS values:
+ uint256 private constant BPS = 10_000;
- uint256 public taxCut = 10;
+ uint256 public taxCut = 10_000;
Update the calculations in EntityForging and NukeFund where taxCut is used.
@Koolex - I think this issue depends on assumptions that were not confirmed when the audit was running.
What we see in the codebase is a taxCut variable that represent a part of the whole. Nowhere it was said that this cut has to be in percents. In fact, the only place where percents are mentioned, is the second link attached to the report that says 10%. And really, when you divide by 10, you get 10%.
I think this issue is pretty easy to solve so it’s actually not a valid issue. Here, if we want 5% rate, we just set taxcut to 20. If we want 20%, set it to 5. Nothing will be changed, so this issue looks like an admin input error.
Nowhere it was said that this cut has to be in percents
All examples in the docs are referred to a %, not a share.
In fact, the only place where percents are mentioned, is the second link attached to the report that says 10%. And really, when you divide by 10, you get 10%.
There is an explicit setTaxCut function on every contract that demonstrates tax fees can change.
@jesjupyter - What you are proposing is just a workaround. Semantically, the tax represents a fee percentage and that’s how it is expected by admins to work when calling setTaxCut.
function setTaxCut(uint256 _taxCut) external onlyOwner {
taxCut = _taxCut;
}
All owner actions are trusted. The owners can still set the taxCut to their desired value, so nothing is really broken. Nowhere it was mentioned that setting taxCut to 20 should mean 20%. TRUSTED function and still works anyway, probably a low/info.
It is clearly intended to be a percentage. We can see this from the comment in the code:
// Fallback function to receive ETH and update fund balance
receive() external payable {
uint256 devShare = msg.value / taxCut; // Calculate developer's share (10%)
uint256 remainingFund = msg.value - devShare; // Calculate remaining funds to add to the fund
@Koolex - I don’t understand why it is clearly intended to be a percentage in the following code. I believe it is meant to be a denominator, as 1/10 equals 10%.
This is the code from a audit in which I participated.
// 20% of last users receive rewards
uint256 Amount;
if (share == 0 && block.timestamp >= time) {
share = totalSupply() / 5;
}
Perhaps it would be better to use taxcut as a percentage, but that’s a design choice rather than an issue.
The original report as published on Code4rena, by 0xDarko. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The code uses division by taxCut instead of multiplying by a percentage, so the calculation only yields the intended percentage when taxCut equals 10.
Impact
The incorrect fee calculation could lead to significant financial losses or unintended gains and undermine the protocol's economic model.
What the attacker needed
Owner changes taxCut from default; contract has funds or receives payments
The fix
The fix is to implement a basis point system where taxCut is expressed in basis points (e.g., 10_000 for 100%) and calculations use multiplication and division by 10_000, and to add a boundary check in setTaxCut.
How it was found
Set taxCut to 5 using the setTaxCut function.
Send 1 ether to the NukeFund contract.
Observe that the developer receives 0.2 ether (20%) instead of the intended 0.05 ether (5%).
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
These smart contracts take a small cut of each payment as a fee for the developer. The code assumes the fee setting is always 10, so it divides by that number. If the owner changes the setting to 5, the fee becomes 20% instead of 5%, which is not what anyone intended.
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.