The TempusController contract's depositAndProvideLiquidity function accepted an arbitrary tempusAMM address, allowing an attacker to supply a fake contract that returned manipulated values for tokens and shares. This let the attacker transfer any ERC20 tokens held by the contract to themselves.
The problem is due to the fact that you supply an arbitrary tempusAMM to depositAndProvideLiquidity and thus to \_depositAndProvideLiquidity. tempusAMM could be a fake contract that supplies values that are completely fake.
At the end of the function \_depositAndProvideLiquidity, ERC20 tokens are send to the user. If you can manipulate the variables ammTokens, mintedShares and sharesUsed you can send back any tokens held in the contract “ammTokens[0].safeTransfer(msg.sender, mintedShares - sharesUsed[0]);”
The Proof of Concept shows an approach to do this.
Create a fake Vault contract (fakeVault) with the following functions: fakeVault.getPoolTokens(poolId) —> returns {TokenToSteal1,TokenToSteal2},{fakeBalance1,fakeBalance2},0 fakeVault.JoinPoolRequest() —> do nothing fakeVault.joinPool() —> do nothing
Create a fake Pool contract (fakePool) with the following functions: fakePool.yieldBearingToken() —> returns fakeYieldBearingToken fakePool.deposit() —> returns fakeMintedShares,…
Create a fake ammTokens contract with the following functions: tempusAMM.getVault() —> returns fakeVault tempusAMM.getPoolId() —> returns 0 tempusAMM.tempusPool() —> returns fakePool
call depositAndProvideLiquidity(fakeTempusAMM,1,false) // false -> yieldBearingToken _getAMMDetailsAndEnsureInitialized returns fakeVault,0, {token1,token2},{balance1,balance2} _deposit(fakePool,1,false) calls _depositYieldBearing which calls fakePool.deposit() and returns fakeMintedShares _provideLiquidity(…) calculates a vale of ammLiquidityProvisionAmounts _provideLiquidity(…) skips the safeTransferFrom because sender == address(this)) the calls to fakeVault.JoinPoolRequest() and fakeVault.joinPool() can be faked. _provideLiquidity(…) returns the value ammLiquidityProvisionAmounts
Now fakeMintedShares - ammLiquidityProvisionAmounts number of TokenToSteal1 and TokenToSteal2 are transferred to msg.sender
As you can both manipulate TokenToSteal1 and fakeMintedShares, you can transfer any token to msg.sender
This is a good point. However, these tokens that are locked in TempusController are coming from dust that was left when the user is doing early redemption. As this needs to be done with equal shares, we have a threshold parameter that is used as the maximum leftover behind redemption (usually there is a need to do a swap before redemption to make this work). So, this is going to be pennies always.
I would not consider this as high risk, and we are not planning to fix this as steps to make this hack are too complicated to steal pennies… Also, the gas cost of doing it costs by far more than the funds that someone can steal.
We changed point of view here a little bit. Will add registry of TempusAMMs and TempusPools that can be used with controller, just to prevent possible attacks with fake amms and pools.
Added whitelist registry for both TempusAMM and TempusPool in this PR https://github.com/tempus-finance/tempus-protocol/pull/365 However, as amount of tokens that TempusController holds is so small (I would say this is of severity 2)
The C4 docs don’t speculate on the amount of assets stolen in the TLDR of risk assessment.
3 — High: Assets can be stolen/lost/compromised directly (or indirectly if there is a valid attack path that does not have hand-wavy hypotheticals).
Given the fact that some amount of assets could be stolen, i believe this is the correct severity for the issue.
The original report as published on Code4rena, by gpersoon. 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 a minute. 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 function accepted an arbitrary tempusAMM address without verifying it against a whitelist, so a fake contract could return manipulated values that controlled the token transfer.
Impact
An attacker could steal any ERC20 tokens held by the TempusController contract, though the amount is limited to dust left from early redemptions and the gas cost may exceed the value.
What the attacker needed
Ability to deploy fake contracts; knowledge of the contract's functions
The fix
The project added a whitelist registry for both TempusAMM and TempusPool to prevent use of fake contracts.
How it was found
Create a fake Vault contract that returns chosen tokens and balances from getPoolTokens and does nothing in JoinPoolRequest and joinPool.
Create a fake Pool contract that returns a fake yield-bearing token from yieldBearingToken and fake minted shares from deposit.
Create a fake tempusAMM contract that returns the fake Vault from getVault, zero from getPoolId, and the fake Pool from tempusPool.
Call depositAndProvideLiquidity with the fake tempusAMM, amount 1, and false for yield-bearing token.
The function uses the fake values to compute mintedShares and sharesUsed, then transfers the difference of tokens to the caller.
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 a minute. 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
A smart contract held some tokens. A function that was supposed to work with a specific type of contract (a tempusAMM) did not check that the address passed to it was genuine. An attacker could pass a fake contract that lied about token amounts and shares, tricking the function into sending real tokens to the attacker.
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.
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.