Skip to content
Smart contracts Audit finding Advanced

Possible reentrancy during redemption/swap

The redemption function transfers collateral tokens before finishing its state updates, so a recipient of an ERC777 collateral could re-enter redeem and receive more collateral than entitled. An attacker could steal collateral from the contract.

auditor0517 Follow with Lambda

Originally disclosed on Code4rena

Submitted by auditor0517, also found by Lambda

Redeemers might charge more collaterals during redemption/swap by the reentrancy attack.

Proof of Concept

Redeemers can redeem the agToken for collaterals in Redeemer contract and _redeem() burns the agToken and transfers the collaterals.

    function _redeem(
        uint256 amount,
        address to,
        uint256 deadline,
        uint256[] memory minAmountOuts,
        address[] memory forfeitTokens
    ) internal returns (address[] memory tokens, uint256[] memory amounts) {
        TransmuterStorage storage ts = s.transmuterStorage();
        if (ts.isRedemptionLive == 0) revert Paused();
        if (block.timestamp > deadline) revert TooLate();
        uint256[] memory subCollateralsTracker;
        (tokens, amounts, subCollateralsTracker) = _quoteRedemptionCurve(amount);
        // Updating the normalizer enables to simultaneously and proportionally reduce the amount
        // of stablecoins issued from each collateral without having to loop through each of them
        _updateNormalizer(amount, false);

        IAgToken(ts.agToken).burnSelf(amount, msg.sender); //@audit-info burn agToken

        address[] memory collateralListMem = ts.collateralList;
        uint256 indexCollateral;
        for (uint256 i; i < amounts.length; ++i) {
            if (amounts[i] < minAmountOuts[i]) revert TooSmallAmountOut();
            // If a token is in the `forfeitTokens` list, then it is not sent as part of the redemption process
            if (amounts[i] > 0 && LibHelpers.checkList(tokens[i], forfeitTokens) < 0) {
                Collateral storage collatInfo = ts.collaterals[collateralListMem[indexCollateral]];
                if (collatInfo.onlyWhitelisted > 0 && !LibWhitelist.checkWhitelist(collatInfo.whitelistData, to))
                    revert NotWhitelisted();
                if (collatInfo.isManaged > 0)
                    LibManager.release(tokens[i], to, amounts[i], collatInfo.managerData.config);
                else IERC20(tokens[i]).safeTransfer(to, amounts[i]); //@audit reentrancy
            }
            if (subCollateralsTracker[indexCollateral] - 1 <= i) ++indexCollateral;
        }
        emit Redeemed(amount, tokens, amounts, forfeitTokens, msg.sender, to);
    }

During the collateral transfers(direct transfer or in LibManager.release()), there might be a hook for the recipient in the case of ERC777 tokens.

Then the recipient might charge more collaterals by reentrancy like this.

  1. Let’s suppose there are 2 collaterals colA and colB. The transmuter contract contains 1000 amounts of colA and colB. Alice has 20 amounts of agToken.
  2. At the first time, Alice calls redeem() with 10 amounts of agToken and she should receive 10 amounts of colA and colB.
  3. As colA is an ERC777 token, she calls redeem(10) again inside the hook after the colA transfer.
  4. During the second redemption, total collaterals will be colA = 990, colB = 1000 because colB isn’t transferred in the first redemption yet.
  5. After all, Alice will receive more collaterals in the second redemption from this calculation.

I think a similar reentrancy attack might be possible during the swap as well.

Recommended Mitigation Steps

I think we should add the nonReentrant modifier to the major functions like redeem()/swap().

Picodes (Angle) confirmed, but disagreed with severity and commented:

Valid. We had this in mind but thought it was ok as we don’t plan to accept collaterals with callbacks. However better than sorry and we may add the modifier.

hansfriese (Judge) commented:

@Picodes - LibManager.release() is called during the redemption and it might have a callback although the governance doesn’t accept collaterals with hooks.

Because the assumption is practical enough and the users can steal collaterals directly, will keep as High.

Angle mitigated:

PR: https://github.com/AngleProtocol/angle-transmuter/commit/864c1c47cb550f8e337244f0f70409a171a4e671 Adds a reentrancy guard to several functions.

Status: Mitigation confirmed. Full details in reports from auditor0517, Lambda, and Jeiwan.


The original report as published on Code4rena, by auditor0517. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

Angle Protocol's Transmuter lets holders of the protocol's agToken stablecoin redeem it for a basket of collateral tokens. The redemption logic lives in the Redeemer facet of the angle-transmuter repository, and the core of it is the internal _redeem() function. A user calls redeem(), the contract works out how much of each collateral the requested agToken amount is worth, burns the agToken, and then pays out the collaterals. The same contract also exposes a swap path, which the researcher suspected of the same weakness.

The report was filed in the Code4rena invitational audit of Angle Protocol and rated High. The researcher is auditor0517, and the same issue was independently found by Lambda.

Setup

There are no accounts, tools or versions to configure here: this is a code review finding, not a live test. The relevant preconditions, as the report frames them, are:

  1. The Transmuter holds collateral balances that can be redeemed against.
  2. At least one collateral in the basket is a token that can invoke a hook on the recipient during transfer, such as an ERC777 token.
  3. The attacker holds agToken and can therefore call redeem() legitimately.

The report does not name specific deployed addresses, chain, or contract version beyond the linked commit of Redeemer.sol.

Finding it

The researcher read _redeem() and noticed that the agToken is burned before the collateral transfers happen, and that the payout amounts are quoted at the start of the call. The transfers to the recipient occur inside the same function, and for tokens with transfer hooks the recipient gets control of execution mid-redemption, after the burn but before all collaterals have left the contract. That ordering is what makes reentrancy possible.

Here is the function as quoted in the report:

Solidity
    function _redeem(
        uint256 amount,
        address to,
        uint256 deadline,
        uint256[] memory minAmountOuts,
        address[] memory forfeitTokens
    ) internal returns (address[] memory tokens, uint256[] memory amounts) {
        TransmuterStorage storage ts = s.transmuterStorage();
        if (ts.isRedemptionLive == 0) revert Paused();
        if (block.timestamp > deadline) revert TooLate();
        uint256[] memory subCollateralsTracker;
        (tokens, amounts, subCollateralsTracker) = _quoteRedemptionCurve(amount);
        // Updating the normalizer enables to simultaneously and proportionally reduce the amount
        // of stablecoins issued from each collateral without having to loop through each of them
        _updateNormalizer(amount, false);

        IAgToken(ts.agToken).burnSelf(amount, msg.sender); //@audit-info burn agToken

        address[] memory collateralListMem = ts.collateralList;
        uint256 indexCollateral;
        for (uint256 i; i < amounts.length; ++i) {
            if (amounts[i] < minAmountOuts[i]) revert TooSmallAmountOut();
            // If a token is in the `forfeitTokens` list, then it is not sent as part of the redemption process
            if (amounts[i] > 0 && LibHelpers.checkList(tokens[i], forfeitTokens) < 0) {
                Collateral storage collatInfo = ts.collaterals[collateralListMem[indexCollateral]];
                if (collatInfo.onlyWhitelisted > 0 && !LibWhitelist.checkWhitelist(collatInfo.whitelistData, to))
                    revert NotWhitelisted();
                if (collatInfo.isManaged > 0)
                    LibManager.release(tokens[i], to, amounts[i], collatInfo.managerData.config);
                else IERC20(tokens[i]).safeTransfer(to, amounts[i]); //@audit reentrancy
            }
            if (subCollateralsTracker[indexCollateral] - 1 <= i) ++indexCollateral;
        }
        emit Redeemed(amount, tokens, amounts, forfeitTokens, msg.sender, to);
    }

The researcher's annotations mark the burn and the transfer. The key observation is that the payout loop transfers each collateral in turn, and during those transfers, whether a direct safeTransfer or a call into LibManager.release(), a recipient contract can be invoked if the token implements a hook such as ERC777's. At that moment the redemption is only partly complete: the agToken has been burned, but later collaterals in the loop have not yet been sent out.

Exploitation

The report describes the attack with a two-collateral example.

Step 1: Set the scene

Suppose the Transmuter holds 1000 units of colA and 1000 units of colB. Alice holds 20 units of agToken. colA is an ERC777 token, so transferring it to Alice triggers a hook on her contract.

Step 2: First redemption

Alice calls redeem() with 10 units of agToken. Based on the current balances she should receive 10 units of colA and 10 units of colB.

Step 3: Reenter from the hook

Because colA is ERC777, the transfer of colA to Alice invokes her hook. Inside that hook she calls redeem(10) again. The report links this to the colA transfer line in Redeemer.sol.

Step 4: Second redemption sees stale balances

During the second redemption, the contract's collateral balances are colA = 990 and colB = 1000, because colB has not been transferred in the first redemption yet. The quote for the second redemption is therefore computed against a basket that still contains the full colB balance, even though Alice's first redemption has already been priced against it.

Step 5: Collect the excess

After both redemptions complete, Alice has received more collateral than a single, non-reentrant redemption of 20 agToken would have paid. The report attributes the excess to the calculation performed in the second redemption, linking to the relevant line in Redeemer.sol.

The researcher adds that a similar reentrancy attack might be possible during the swap as well, though the report does not work through a swap scenario.

Root cause

The redemption quote is computed at the start of _redeem(), and the function then pays out collaterals one at a time. Because the agToken is burned before the transfers and the transfers can hand control to the recipient, a second redemption can be started while the first is still mid-payout. That second call prices its payout against balances that still include collaterals the first call has already committed to sending. The result is that Alice receives more collateral than a single redemption would pay.

The existing defence was an operational assumption rather than a code control: as the Angle team put it, they had this in mind but thought it was acceptable because they do not plan to accept collaterals with callbacks. The judge noted that LibManager.release() is called during redemption and might itself involve a callback even though governance does not accept collaterals with hooks, and treated the assumption as practical enough to keep the severity at High, since users can steal collaterals directly. There is no reentrancy guard on redeem() or swap() in the code shown.

Impact

A redeemer who can trigger a transfer hook can extract more collateral from the Transmuter than their agToken entitles them to. The attack requires a collateral token in the basket that calls back into the recipient on transfer. The report hedges the swap path as a possibility ("might be possible") rather than a demonstrated case.

Fix

The recommended mitigation in the report is to add the nonReentrant modifier to the major functions such as redeem() and swap(). Angle implemented this: the mitigation PR adds a reentrancy guard to several functions. The mitigation was confirmed, with details in the follow-up mitigation reports from auditor0517, Lambda and Jeiwan.

Variants to test

  1. Other payout loops that read live balances. Look for functions that compute a share from current token balances and then transfer tokens in a loop. A positive result is a second call, made from a transfer hook, that is priced against balances the first call has already spent.
  2. Managed collateral release paths. Check whether LibManager.release() or equivalent manager calls can invoke external code even when the token itself has no hook. A positive result is any callback into the redeemer before the loop finishes.
  3. Swap functions sharing the same accounting. Apply the same two-collateral reasoning to swap(). A positive result is a swap executed from within a redemption or swap hook that receives a better rate than a single call would.
  4. Burn-before-transfer ordering. Search for functions that burn or debit the caller before paying out multiple assets. A positive result is a reentrant call that passes the balance checks because the debit has already happened but the credits have not.

Hunting notes

This class of bug hides in redemption, withdrawal and swap functions that mix live balance reads with multi-asset payouts. During review, the signal is a loop of external transfers after a burn or debit, with no reentrancy guard on the entry point. The presence of ERC777 or other hook-capable tokens in a supported asset list, or a manager layer that can call out during release, raises the likelihood. The researcher showed impact with a concrete numeric example: two collaterals, a 20 agToken balance, two 10-unit redemptions, and the intermediate balances of 990 and 1000 that make the double count visible. The judge kept the finding at High because the assumption was practical enough and users can steal collaterals directly.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 15 min read.

What happened, in plain words

Angle Protocol is a system that issues a stablecoin called agToken. People who hold agToken can hand it back to the protocol and receive a mix of other tokens (called collateral) in return. The part of the protocol that handles this exchange is called the Transmuter, and the specific piece of code that does the paying out is a function named _redeem() inside a file called Redeemer.sol.

The researcher, auditor0517, read that function and noticed a problem with the order in which it does things. When someone redeems, the contract works out how much collateral they are owed, destroys (burns) their agToken, and then sends the collateral out one token at a time. Some kinds of tokens can run a small piece of code on the receiving side every time they are transferred. If one of the collateral tokens is that kind, the person receiving it gets a chance to run their own code in the middle of the payout, before the remaining collateral has left the contract. From inside that pause, they can call redeem() again. The second call is priced while some collateral from the first redemption has not been sent yet. The attacker walks away with more collateral than they should have.

The report was filed in a Code4rena audit contest for Angle Protocol and rated High severity. The same issue was found independently by another researcher, Lambda. The Angle team agreed the issue was real but thought it was unlikely to matter because they did not plan to support collateral tokens that run code on transfer. The judge treated the assumption as practical enough and kept the severity at High, since users can steal collaterals directly. Angle later added a reentrancy guard to several functions, and the fix was confirmed.

Background concepts, from zero

Before walking through the report, here are the ideas you need.

Stablecoin. A cryptocurrency designed to keep a steady value, usually tied to a real-world currency. Angle's stablecoin here is called agToken.

Collateral. Assets held by the protocol as backing. If you redeem agToken, you get some of this collateral back. In this report the collateral is a basket of several different tokens, which the report calls colA, colB and so on.

Smart contract. A program that lives on a blockchain. It runs automatically when someone sends it a transaction. The Transmuter is a smart contract, and so is the Redeemer code inside it.

Function. A named block of code inside a smart contract that does one job. redeem() is the function a user calls to exchange agToken for collateral. _redeem() is an internal helper that redeem() uses to do the actual work. The leading underscore is a naming convention meaning "internal, not called directly by users".

Facet. A module of a smart contract. The Transmuter is split into facets, and Redeemer is the facet that handles redemptions.

Burn. Permanently destroy a token. When you redeem agToken, the contract burns your agToken so it no longer exists, which is how the supply shrinks.

Transfer. Move a token from one address to another. In this report, the contract transfers collateral tokens to the redeemer.

ERC20 and ERC777. Two standards for tokens on Ethereum-like blockchains. ERC20 is the basic one: a transfer just moves the balance. ERC777 is an extension that, on every transfer, can call a function on the receiving address if that address is a contract. That call is called a hook. It is meant to let the receiver react to the transfer, but it also hands control of execution to the receiver for a moment.

Hook. A piece of code that runs automatically at a certain point, here on the receiving side of a token transfer. If the receiver is a malicious contract, the hook is a place where the attacker gets to run their own logic in the middle of the protocol's operation.

Reentrancy. A class of bug where a contract calls out to another contract, and that other contract calls back into the first one before the first call has finished. The first call is still halfway through, so its internal state is inconsistent. The classic analogy is a bank clerk who checks your balance, then goes to fetch the cash, and while they are away you ask a second clerk for a withdrawal; the second clerk also sees the old balance and pays you again. Here the "clerk" is the Transmuter, the "balance check" is the collateral quote, and the "fetching the cash" is the collateral transfer.

Reentrancy guard. A simple defence: a flag that is set when a function starts and cleared when it ends. If the function is entered again while the flag is set, the second entry is rejected. In Solidity this is usually a modifier called nonReentrant.

Modifier. A small wrapper you attach to a function that runs extra code before or after it. nonReentrant is a modifier that enforces the guard described above.

Swap. A second way to exchange tokens in the same contract. The researcher suspected the same bug could apply there, but did not work through an example.

Severity. How serious a finding is judged to be. High means it can lead to direct loss of funds.

The setup

There is nothing to install or configure. This is a code review finding, not a live attack against a running system. The example in the report implies the following conditions:

  1. The Transmuter holds collateral balances that can be redeemed against. In other words, there is something to steal.
  2. At least one collateral in the basket is a token that can run a hook on the recipient during transfer, such as an ERC777 token. Without a hook, the attacker never gets control mid-payout.
  3. The attacker holds agToken and can therefore call redeem() legitimately. They need a real balance to start the process.

The report does not name specific deployed addresses, a chain, or a contract version beyond the linked commit of Redeemer.sol.

Finding it

The researcher read _redeem() and noticed the order of operations. The agToken is burned before the collateral transfers happen. But the amount of collateral each redeemer receives is calculated from the contract's current collateral balances at the start of the call. The transfers to the recipient happen inside the same function, and for tokens with transfer hooks the recipient gets control of execution mid-redemption, after the burn but before all collaterals have left the contract. That ordering is what makes reentrancy possible.

Here is the function as quoted in the report:

Solidity
    function _redeem(
        uint256 amount,
        address to,
        uint256 deadline,
        uint256[] memory minAmountOuts,
        address[] memory forfeitTokens
    ) internal returns (address[] memory tokens, uint256[] memory amounts) {
        TransmuterStorage storage ts = s.transmuterStorage();
        if (ts.isRedemptionLive == 0) revert Paused();
        if (block.timestamp > deadline) revert TooLate();
        uint256[] memory subCollateralsTracker;
        (tokens, amounts, subCollateralsTracker) = _quoteRedemptionCurve(amount);
        // Updating the normalizer enables to simultaneously and proportionally reduce the amount
        // of stablecoins issued from each collateral without having to loop through each of them
        _updateNormalizer(amount, false);

        IAgToken(ts.agToken).burnSelf(amount, msg.sender); //@audit-info burn agToken

        address[] memory collateralListMem = ts.collateralList;
        uint256 indexCollateral;
        for (uint256 i; i < amounts.length; ++i) {
            if (amounts[i] < minAmountOuts[i]) revert TooSmallAmountOut();
            // If a token is in the `forfeitTokens` list, then it is not sent as part of the redemption process
            if (amounts[i] > 0 && LibHelpers.checkList(tokens[i], forfeitTokens) < 0) {
                Collateral storage collatInfo = ts.collaterals[collateralListMem[indexCollateral]];
                if (collatInfo.onlyWhitelisted > 0 && !LibWhitelist.checkWhitelist(collatInfo.whitelistData, to))
                    revert NotWhitelisted();
                if (collatInfo.isManaged > 0)
                    LibManager.release(tokens[i], to, amounts[i], collatInfo.managerData.config);
                else IERC20(tokens[i]).safeTransfer(to, amounts[i]); //@audit reentrancy
            }
            if (subCollateralsTracker[indexCollateral] - 1 <= i) ++indexCollateral;
        }
        emit Redeemed(amount, tokens, amounts, forfeitTokens, msg.sender, to);
    }

Line by line, in plain words:

  • function _redeem( opens the internal function. It takes five inputs: amount (how much agToken to redeem), to (who receives the collateral), deadline (a timestamp after which the call is rejected), minAmountOuts (the minimum acceptable amount of each collateral, so the user is not surprised by a bad rate), and forfeitTokens (a list of collateral tokens the user does not want to receive).
  • TransmuterStorage storage ts = s.transmuterStorage(); loads the contract's stored settings and balances into a local variable called ts.
  • if (ts.isRedemptionLive == 0) revert Paused(); stops the call if redemptions are switched off. revert means "abort and undo everything".
  • if (block.timestamp > deadline) revert TooLate(); stops the call if the deadline has passed.
  • uint256[] memory subCollateralsTracker; declares a temporary array used later to keep track of which collateral each entry in the payout list belongs to.
  • (tokens, amounts, subCollateralsTracker) = _quoteRedemptionCurve(amount); is the pricing step. It asks the curve logic how much of each collateral the given agToken amount is worth, based on the contract's current balances. This is the "balance check" in the bank analogy.
  • The comment and _updateNormalizer(amount, false); adjust an internal accounting figure so that the amount of stablecoin attributed to each collateral shrinks proportionally, without looping over every collateral.
  • IAgToken(ts.agToken).burnSelf(amount, msg.sender); destroys the caller's agToken. The comment //@audit-info burn agToken is the researcher's note marking this line. After this point the user's agToken is gone, but they have not yet received collateral.
  • address[] memory collateralListMem = ts.collateralList; copies the list of collateral token addresses.
  • uint256 indexCollateral; sets up a counter for walking that list.
  • for (uint256 i; i < amounts.length; ++i) { starts a loop over each collateral payout.
  • if (amounts[i] < minAmountOuts[i]) revert TooSmallAmountOut(); enforces the user's minimum for this collateral.
  • The comment explains that tokens in forfeitTokens are skipped.
  • if (amounts[i] > 0 && LibHelpers.checkList(tokens[i], forfeitTokens) < 0) { runs the payout only if the amount is positive and the token is not in the forfeit list.
  • Collateral storage collatInfo = ts.collaterals[collateralListMem[indexCollateral]]; loads the settings for this collateral.
  • if (collatInfo.onlyWhitelisted > 0 && !LibWhitelist.checkWhitelist(collatInfo.whitelistData, to)) revert NotWhitelisted(); rejects the payout if the collateral is restricted and the recipient is not on the whitelist.
  • if (collatInfo.isManaged > 0) chooses between two payout paths: a managed release, or a direct transfer.
  • LibManager.release(tokens[i], to, amounts[i], collatInfo.managerData.config); is the managed path. It hands the payout to a manager layer, which may itself call out to other code.
  • else IERC20(tokens[i]).safeTransfer(to, amounts[i]); is the direct path. The comment //@audit reentrancy is the researcher's note marking this line as the place where a hook can fire. safeTransfer moves the token to the recipient; if the token is ERC777, the recipient's hook runs here.
  • if (subCollateralsTracker[indexCollateral] - 1 <= i) ++indexCollateral; advances the collateral counter when the loop has finished all sub-entries for the current collateral.
  • emit Redeemed(...) records an event on the blockchain for logs and monitoring.

The researcher's annotations mark the burn and the transfer. The key observation is that the payout loop transfers each collateral in turn, and during those transfers, whether a direct safeTransfer or a call into LibManager.release(), a recipient contract can be invoked if the token implements a hook such as ERC777's. At that moment the redemption is only partly complete: the agToken has been burned, but later collaterals in the loop have not yet been sent out.

Exploitation

The report describes the attack with a two-collateral example.

Step 1: Set the scene

Suppose the Transmuter holds 1000 units of colA and 1000 units of colB. Alice holds 20 units of agToken. colA is an ERC777 token, so transferring it to Alice triggers a hook on her contract. Alice here is the attacker: her "contract" is a smart contract she controls, which is what lets her run code inside the hook.

Step 2: First redemption

Alice calls redeem() with 10 units of agToken. Based on the current balances she should receive 10 units of colA and 10 units of colB. The contract burns her 10 agToken, then starts paying out. It sends the 10 units of colA first.

Step 3: Reenter from the hook

Because colA is ERC777, the transfer of colA to Alice invokes her hook. Inside that hook she calls redeem(10) again. The report links this to the colA transfer line in Redeemer.sol. At this instant, the first redemption has burned Alice's agToken and sent colA, but has not yet sent colB.

Step 4: Second redemption sees stale balances

During the second redemption, the contract's collateral balances are colA = 990 and colB = 1000, because colB has not been transferred in the first redemption yet. The quote for the second redemption is therefore computed against a basket that still contains the full colB balance, even though Alice's first redemption has already been priced against it. The second call is priced as if colB were still entirely available, so it hands Alice a share of colB that the first call has already promised her.

Step 5: Collect the excess

After both redemptions complete, Alice has received more collateral than a single, non-reentrant redemption of 20 agToken would have paid. The report attributes the excess to the calculation performed in the second redemption, linking to the relevant line in Redeemer.sol.

The researcher adds that a similar reentrancy attack might be possible during the swap as well, though the report does not work through a swap scenario.

Root cause

The redemption quote is computed at the start of _redeem(), and the function then pays out collaterals one at a time. Because the agToken is burned before the transfers and the transfers can hand control to the recipient, a second redemption can be started while the first is still mid-payout. That second call prices its payout against balances that still include collaterals the first call has already committed to sending. The result is that Alice receives more collateral than a single redemption would pay.

The existing defence was an operational assumption rather than a code control: as the Angle team put it, they had this in mind but thought it was acceptable because they do not plan to accept collaterals with callbacks. The judge noted that LibManager.release() is called during redemption and might itself involve a callback even though governance does not accept collaterals with hooks, and treated the assumption as practical enough to keep the severity at High, since users can steal collaterals directly. There is no reentrancy guard on redeem() or swap() in the code shown.

Impact

A redeemer who can trigger a transfer hook can extract more collateral from the Transmuter than their agToken entitles them to. The attack requires a collateral token in the basket that calls back into the recipient on transfer. The report hedges the swap path as a possibility ("might be possible") rather than a demonstrated case.

Fix

The recommended mitigation in the report is to add the nonReentrant modifier to the major functions such as redeem() and swap(). Angle implemented this: the mitigation PR adds a reentrancy guard to several functions. The mitigation was confirmed, with details in the follow-up mitigation reports from auditor0517, Lambda and Jeiwan.

Variants to test

  1. Other payout loops that read live balances. Look for functions that compute a share from current token balances and then transfer tokens in a loop. A positive result is a second call, made from a transfer hook, that is priced against balances the first call has already spent.
  2. Managed collateral release paths. Check whether LibManager.release() or equivalent manager calls can invoke external code even when the token itself has no hook. A positive result is any callback into the redeemer before the loop finishes.
  3. Swap functions sharing the same accounting. Apply the same two-collateral reasoning to swap(). A positive result is a swap executed from within a redemption or swap hook that receives a better rate than a single call would.
  4. Burn-before-transfer ordering. Search for functions that burn or debit the caller before paying out multiple assets. A positive result is a reentrant call that passes the balance checks because the debit has already happened but the credits have not.

Hunting notes

This class of bug hides in redemption, withdrawal and swap functions that mix live balance reads with multi-asset payouts. During review, the signal is a loop of external transfers after a burn or debit, with no reentrancy guard on the entry point. The presence of ERC777 or other hook-capable tokens in a supported asset list, or a manager layer that can call out during release, raises the likelihood. The researcher showed impact with a concrete numeric example: two collaterals, a 20 agToken balance, two 10-unit redemptions, and the intermediate balances of 990 and 1000 that make the double count visible. The judge kept the finding at High because the assumption was practical enough and users can steal collaterals directly.

Glossary

  • agToken: Angle Protocol's stablecoin, the token users redeem for collateral.
  • Angle Protocol: The project whose Transmuter contract is the subject of this report.
  • Burn: Permanently destroy a token so it no longer exists.
  • Callback: Code that runs automatically on the receiving side of an action, such as a token transfer.
  • Collateral: Assets held by the protocol as backing for the stablecoin.
  • Code4rena: A platform that runs audit contests where researchers review code for bugs.
  • Deadline: A timestamp after which a call is rejected.
  • ERC20: The basic token standard; transfers just move balances.
  • ERC777: A token standard that can run a hook on the recipient during every transfer.
  • Facet: A module of a smart contract; Redeemer is the facet that handles redemptions.
  • Forfeit tokens: A list of collateral tokens the user chooses not to receive.
  • Hook: Code that runs automatically at a certain point, here on the receiving side of a token transfer.
  • Internal function: A function that can only be called from inside the same contract, not directly by users.
  • LibManager.release(): The managed payout path used when a collateral is flagged as managed; it may call out to other code.
  • MinAmountOuts: The minimum acceptable amount of each collateral, protecting the user from a bad rate.
  • Modifier: A wrapper attached to a function that runs extra code before or after it.
  • nonReentrant: A modifier that blocks a function from being entered again while it is still running.
  • Quote: The calculation of how much of each collateral a given agToken amount is worth.
  • Reentrancy: A bug where a contract calls out, and the callee calls back into the first contract before the first call has finished, so the first call's state is inconsistent.
  • Reentrancy guard: A flag that is set while a function runs and cleared when it ends, used to reject re-entry.
  • redeem(): The user-facing function that exchanges agToken for collateral.
  • _redeem(): The internal helper that does the actual redemption work.
  • Redeemer.sol: The source file containing the redemption logic.
  • Revert: Abort a call and undo all its effects.
  • Severity: How serious a finding is judged to be; High means direct loss of funds is possible.
  • safeTransfer: A token transfer helper that moves tokens to a recipient.
  • Smart contract: A program that lives on a blockchain and runs automatically when called.
  • Stablecoin: A cryptocurrency designed to keep a steady value.
  • Swap: A second exchange path in the same contract, suspected of the same weakness.
  • Transmuter: The Angle Protocol contract that handles redemptions and swaps.
  • Transfer: Moving a token from one address to another.
  • Whitelist: A list of addresses allowed to receive a restricted collateral.

More by auditor0517

View all

11 more disclosed reports, best first.

More from Angle Protocol - Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.