Open howlbot-integration[bot] opened 3 months ago
koolexcrypto marked the issue as satisfactory
koolexcrypto marked the issue as selected for report
koolexcrypto changed the severity to 3 (High Risk)
koolexcrypto changed the severity to 2 (Med Risk)
Lines of code
https://github.com/code-423n4/2024-07-traitforge/blob/279b2887e3d38bc219a05d332cbcb0655b2dc644/contracts/NukeFund/NukeFund.sol#L20 https://github.com/code-423n4/2024-07-traitforge/blob/279b2887e3d38bc219a05d332cbcb0655b2dc644/contracts/NukeFund/NukeFund.sol#L147-L148
Vulnerability details
Bug description
The Nuke Fund accumulates ETH from new mints and economic activity. After a 3-day maturity period, anyone can nuke their entity to claim a share of the ETH in the Fund. Every entity has a parameter, called
initialNukeFactor
, set on mint which represents how much of the Fund can be claimed on nuke. The maximum total nukeFactor is 50%, expressed as 50_000.The calculations of
finalNukeFactor
consist ofadjustedAge
,defaultNukeFactorIncrease
andinitialNukeFactor
.NukeFund.sol#L145-L148
The age is calculated via
calculateAge()
function.NukeFund.sol#L121-L131
The idea behind age calculations is quite simple: we calculate how many days have passed since token creation and convert that into years.
However, the default value of the
nukeFactorIncrease
set to 250 is extremely low. While whitepaper mentions that the fastest maturing NFT should mature (reach nukeFactor of 50_000) in around 30 days and the slowest in 600 days, in reality it would take 4050 days for the best possible NFT to fully mature.To showcase this let's do some math:
To mature NFT must reach
finalNukeFactor
of 50_000. The best possible NFT would have 25000initialNukeFactor
andperformanceFactor
of 9.defaultNukeFactor
is set to 250.finalNukeFactor = adjustedAge * defaultNukeFactorIncrease + initialNukeFactor
50000 = x * 250 + 25000
25000 = 250x
x = 100
adjustedAge = daysOld * performanceFactor / 365
100 = x * 9 / 365
9x = 100 * 365
x = 365000 / 9 = 4055
.For the best NFT to mature fully in 30 days, the
defaultNukeFactor
would need to be 135 times bigger, more precisely 33750.Impact
NFTs mature extremely slowly with default settings, to the point where
performanceFactor
of an NFT does not play any role andfinalNukeFactor
is determined solely by theinitialNukeFactor
.Proof of Concept
To set up the following POC in Foundry please follow the steps. Inside Hardhat project working directory:
yarn add --dev @nomicfoundation/hardhat-foundry
- Install the hardhat-foundry plugin.require("@nomicfoundation/hardhat-foundry");
to the top of your hardhat.config.js file.npx hardhat init-foundry
in your terminal. This will generate a foundry.toml file based on your Hardhat project’s existing configuration, and will install the forge-std library.Run it with
forge test --match-test 'test_matureToSlowly' -vv
.The console output of the test:
Recommended Mitigation
defaultNukeFactorIncrease
variable should be set to reasonable value, that will correctly reflect the speed at which NFTs should mature. Judging by the docs, its value should be set to at least 33750.Assessed type
Other