Read-only reentrancy is possible
The transmuter contract's swap and redeem functions lack reentrancy guards, allowing an attacker with an ERC777 collateral token to reenter during a swap before the agToken is minted. This causes the collateral ratio to be misreported, leading to incorrect minting of agToken rewards in SavingsVest.
Originally disclosed on Code4rena
Submitted by auditor0517
https://github.com/AngleProtocol/angle-transmuter/blob/9707ee4ed3d221e02dcfcd2ebaa4b4d38d280936/contracts/transmuter/facets/Swapper.sol#L206 https://github.com/AngleProtocol/angle-transmuter/blob/9707ee4ed3d221e02dcfcd2ebaa4b4d38d280936/contracts/transmuter/facets/Redeemer.sol#L131 https://github.com/AngleProtocol/angle-transmuter/blob/9707ee4ed3d221e02dcfcd2ebaa4b4d38d280936/contracts/savings/SavingsVest.sol#L110
The agToken might be minted wrongly as rewards due to the reentrancy attack.
Proof of Concept
There are redeem/swap logics in the transmuter contract and all functions don’t have a nonReentrant modifier.
So the typical reentrancy attack is possible during redeem/swap as I mentioned in my other report.
But besides that, the read-only reentrancy attack is possible from the SavingsVest contract, and the agToken might be minted/burnt incorrectly like this.
- The collatRatio is
BASE_9(100%)now and Alice starts a swap from collateral to agToken inSwappercontract. - In
_swap(), it mints the agToken after depositing the collaterals.
if (mint) {
uint128 changeAmount = (amountOut.mulDiv(BASE_27, ts.normalizer, Math.Rounding.Up)).toUint128();
// The amount of stablecoins issued from a collateral are not stored as absolute variables, but
// as variables normalized by a `normalizer`
collatInfo.normalizedStables += uint216(changeAmount);
ts.normalizedStables += changeAmount;
if (permitData.length > 0) {
PERMIT_2.functionCall(permitData);
} else if (collatInfo.isManaged > 0)
IERC20(tokenIn).safeTransferFrom(
msg.sender,
LibManager.transferRecipient(collatInfo.managerData.config),
amountIn
);
else IERC20(tokenIn).safeTransferFrom(msg.sender, address(this), amountIn); //@audit reentrancy
if (collatInfo.isManaged > 0) {
LibManager.invest(amountIn, collatInfo.managerData.config);
}
IAgToken(tokenOut).mint(to, amountOut);
}
After depositing the collaterals, Alice might have a hook in the case of ERC777 tokens before the agToken is minted.
- Then Alice calls
SavingsVest.accrue()inside the hook and getCollateralRatio() will return the incorrect ratio as the agToken isn’t minted yet. - So
collatRatiowill be larger than the real value and additional rewards would be minted ifcollatRatio > BASE_9 + BASE_6.
Then Alice would get more rewards from the SavingsVest.
Recommended Mitigation Steps
Recommend adding the nonReentrant modifer to getCollateralRatio() as well as redeem()/swap() functions.
Picodes (Angle) confirmed and commented:
So the assumption is that there is an accepted collateral
ERC777, which is really unlikely as there is no credible candidate and it would bring additional risk. But the scenario is valid.
PR: https://github.com/AngleProtocol/angle-transmuter/commit/864c1c47cb550f8e337244f0f70409a171a4e671 Adds a reentrancy guard to several functions.
Status: Mitigation confirmed. Full details in reports from Lambda, auditor0517, and Jeiwan.
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
Likely the swap and redeem functions lack a reentrancy guard and update state after external calls, allowing a read-only reentrancy that misreports the collateral ratio.
Impact
The agToken could be minted incorrectly as rewards, giving the attacker more rewards than deserved; the exploit requires an accepted ERC777 collateral, which the protocol deems unlikely.
What the attacker needed
An accepted ERC777 collateral token; attacker can trigger a swap with that token
The fix
A reentrancy guard was added to several functions, including getCollateralRatio() and redeem()/swap().
How it was found
- Alice starts a swap from collateral to agToken in the Swapper contract.
- During the swap, collateral is deposited and an ERC777 hook is triggered before the agToken is minted.
- Inside the hook, Alice calls SavingsVest.accrue().
- getCollateralRatio() returns an incorrect (higher) ratio because the agToken is not yet minted.
- Additional rewards are minted if the ratio exceeds the threshold, and Alice receives more rewards.
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 reentrancy attack happens when a contract calls another contract before it has finished updating its own records, letting the attacker call back into the first contract and exploit the inconsistent state. Here, during a swap, the contract transfers collateral (which can trigger a callback if the token is ERC777) before minting the corresponding agToken. The attacker uses that callback to check the collateral ratio, which appears higher than it really is, and earns extra rewards.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.