Skip to content
Access control Write-up Intermediate

Alchemix

The setWhitelist function in the AlchemistEth contract lacked access control, allowing any user to whitelist addresses to call harvest and flush. An attacker could front-run the intended keepers to block these calls, causing a denial of service.

medium.com

Published on medium.com

Alchemix

Immunefi, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

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. 4 min read.

Context

Alchemix is a protocol that provides instant loans which pay themselves off over time through future yield. A user deposits DAI, and the protocol mints the user alUSD, a synthetic token that tokenises future yield. The yield itself comes from collateral deposited in yearn.finance vaults, and that yield repays the advance over time. As part of the process, alUSD can be transmuted 1-to-1 back into DAI or traded on a decentralised exchange.

The bug described here sits in the AlchemistEth.sol contract, in the function setWhitelist(). That function is meant to control who is allowed to drive two privileged operations: harvest(), which harvests the yield of a vault, and flush(), which deposits all buffered tokens to the active vault. In normal operation only the intended keeper addresses should be able to call those two functions.

From the original on medium.com

Setup

The finding came from whitehat Ashiq Amien, a security researcher at the auditing firm iosiro, on June 16. No special accounts, tooling or versions are described beyond the contract and function names above. The relevant precondition is simply that setWhitelist() was reachable by any user, which is what made the issue an access control problem rather than something requiring privileged access.

Finding it

The problem was present in the AlchemistEth.sol contract in the function setWhitelist(). Any user could have called setWhitelist() to give an attacker the ability to call the harvest function or the flush function. That is, the whitelist that was supposed to gate the keepers could be rewritten by anyone, giving an attacker the ability to call the harvest and flush functions.

Exploitation

Step 1: call setWhitelist() as any user

Because the function had no access restriction, any user could call setWhitelist(). The report does not include the exact call, arguments or transaction.

Step 2: use the whitelisted position to call harvest() and flush()

Through this, an attacker gained the ability to call the harvest function, harvesting the yield of any vault, and to call the flush function, depositing all buffered tokens to the active vault. The report characterises these two actions as relatively harmless on their own.

Step 3: front-run the keepers to cause a denial of service

The more serious use of the same primitive was to front-run the intended keeper addresses to block harvest() and flush() from being called, effectively causing a denial of service. The report does not give the front-running transaction or its parameters.

Root cause

The mistake was an access control gap: setWhitelist() could be called by any user, so the whitelist that was supposed to restrict harvest() and flush() to the intended keepers could be modified by anyone. The root cause as presented is the missing restriction on the setter.

Impact

The vulnerability was given a severity rating of "high". Funds at risk were very low, though if the bug had remained undetected and unpatched, it is possible that it would have become a much bigger issue down the line for future Alchemix strategies.

The reason the damage stayed small is the yearn.finance layer: Alchemix wraps a yearn vault, and yearn vaults have robust safeguards in place regarding forced withdrawals causing unexpected losses. Estimated losses from this attack are approximately $300, despite the fact that about 1,450 ETH is deposited into that Alchemix contract, which is then custodied in yearn.

Alchemix rewarded Ashiq a bounty of $7,500, paid to iosiro at request. Ashiq had previously picked up a bounty of $42,069 from 88mph.

Fix

The Alchemix team added an onlyGov modifier and changed the function name to setKeepers(), so that only governance can whitelist addresses to call harvest() and flush(). Alchemix has patched the vulnerability.

Variants to test

  1. Look for setter functions that configure keeper, operator or whitelist roles and check whether they carry an owner or governance modifier. A positive result is a setter that any externally owned account can call successfully and that changes the address allowed to invoke a privileged function.
  2. Check whether the privileged functions themselves (harvest(), flush() and equivalents) rely only on the whitelist for authorisation. If so, compromising the setter is equivalent to compromising the functions; a positive result is a whitelist entry added by a non-governance address that then passes the check in the privileged function.
  3. Test front-running of keeper transactions: if an attacker can occupy the whitelist slot or otherwise make the keeper's call revert, the keeper's harvest() and flush() can be blocked. A positive result is a repeated pattern where the keeper's transaction fails while the attacker's succeeds.
  4. Review the underlying yield source for safeguards against forced withdrawals, since those safeguards are what bounded the loss here. A positive result is a wrapper whose loss on forced withdrawal is capped by the underlying vault rather than by the wrapper itself.
  5. Check for renamed or refactored versions of the same function across forks and deployments, since a rename to setKeepers() with onlyGov in one contract does not guarantee the same protection elsewhere.

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. 10 min read.

What happened, in plain words

Alchemix is a piece of software that runs on a blockchain (a shared, public record of transactions that many computers keep copies of). It offers a kind of loan that pays itself back over time. You put in a digital currency called DAI, and Alchemix gives you back a different digital token called alUSD. That alUSD represents the money you will earn later from interest, called yield. The interest comes from money parked in another service, yearn.finance, which puts deposits to work and pays a return. Over time that return pays off the loan for you.

A security researcher named Ashiq Amien, who works at an auditing firm called iosiro, found a flaw in this system on June 16. The flaw was an access control issue. Access control simply means deciding who is allowed to do what, like a door that should only open for staff but was left open to everyone. The flaw was rated "high" severity. Alchemix paid a bounty (a reward for finding and reporting a bug) of $7,500, sent to iosiro at the researcher's request. The money actually at risk was very low, but if the bug had gone unnoticed and unfixed, it could have grown into a much bigger problem for future Alchemix strategies. Alchemix has since fixed it.

From the original on medium.com

The product and the feature

To follow the rest, you need a few ideas from the world of blockchain software.

  • A smart contract is a program that lives on the blockchain. It runs automatically and anyone can send it instructions. Think of it as a vending machine: it has fixed rules, and anyone with coins can press the buttons.
  • A token is a digital unit tracked by such a contract. DAI and alUSD are tokens.
  • A function is a named action inside a program, like a button on the vending machine. You call a function to make it do something.
  • A whitelist is a list of people or addresses that are allowed to do something. Here it is a list of addresses allowed to press two particular buttons.
  • An address is a public identifier for an account on the blockchain, a long string of characters. It is not secret, but it identifies who is acting.
  • A keeper is an automated helper that regularly calls certain functions to keep the system running, for example to collect the interest or move funds around.

Alchemix provides instant loans that pay themselves off over time through future yield. A user deposits DAI, and the protocol mints the user alUSD, a synthetic token that tokenises future yield. The yield itself comes from collateral deposited in yearn.finance vaults, and that yield repays the advance over time. As part of the process, alUSD can be transmuted 1-to-1 back into DAI or traded on a decentralised exchange.

The bug described here sits in the AlchemistEth.sol contract, in the function setWhitelist(). That function is meant to control who is allowed to drive two privileged operations: harvest(), which harvests the yield of a vault, and flush(), which deposits all buffered tokens to the active vault. In normal operation only the intended keeper addresses should be able to call those two functions.

In everyday terms: setWhitelist() is the button that edits the guest list, and harvest() and flush() are the two doors that only people on the guest list may open. The problem was that the button for editing the guest list had no lock on it.

Setup

The finding came from whitehat Ashiq Amien, a security researcher at the auditing firm iosiro, on June 16. A whitehat is someone who finds security holes and reports them to the owner instead of abusing them. No special accounts, tooling or versions are described beyond the contract and function names above. The relevant precondition is simply that setWhitelist() was reachable by any user, which is what made the issue an access control problem rather than something requiring privileged access.

In other words, you did not need to be an insider, an administrator or the owner of the system. Any ordinary participant could reach the function, and that is exactly what made it dangerous.

Finding it

The problem was present in the AlchemistEth.sol contract in the function setWhitelist(). Any user could have called setWhitelist() to give an attacker the ability to call the harvest function or the flush function. That is, the whitelist that was supposed to gate the keepers could be rewritten by anyone, giving an attacker the ability to call the harvest and flush functions.

Think of a club with a bouncer who checks names against a list. The list is kept in a notebook on the front desk. If anyone walking past can write their own name in the notebook, the bouncer's check becomes meaningless. The researcher's observation was that the notebook was open to everyone.

Exploitation

Exploitation means actually using a flaw to make the system do something it should not. The write-up describes it in three steps.

Step 1: call setWhitelist() as any user

Because the function had no access restriction, any user could call setWhitelist(). The report does not include the exact call, arguments or transaction.

Why this step matters: the editing button was unlocked, so any user could call it. No password, no special role, no permission from the owners.

Step 2: use the whitelisted position to call harvest() and flush()

Through this, an attacker gained the ability to call the harvest function, harvesting the yield of any vault, and to call the flush function, depositing all buffered tokens to the active vault. The report characterises these two actions as relatively harmless on their own.

Why this step matters: once on the list, the attacker could press the two protected buttons. Harvesting collects the interest earned by a vault. Flushing moves all the waiting tokens into the active vault. On their own, the write-up says these actions are relatively harmless, so this step is not where the real damage lies.

Step 3: front-run the keepers to cause a denial of service

The more serious use of the same primitive was to front-run the intended keeper addresses to block harvest() and flush() from being called, effectively causing a denial of service. The report does not give the front-running transaction or its parameters.

Two terms need unpacking here. Front-running means getting your own transaction processed just before someone else's, so that yours takes effect first and changes the situation the other one expected. On a blockchain, transactions wait in a queue before being processed, and someone who can see the queue can try to jump ahead. A denial of service means stopping a service from working for the people who need it, without necessarily stealing anything.

Why this step matters: the keepers are the automated helpers whose job is to call harvest() and flush() on schedule. If the attacker can jump ahead of them and make their calls fail, the routine maintenance stops. The system does not lose its money directly, but it stops being looked after, which is the serious part of the finding.

Root cause

The mistake was an access control gap: setWhitelist() could be called by any user, so the whitelist that was supposed to restrict harvest() and flush() to the intended keepers could be modified by anyone. The root cause as presented is the missing restriction on the setter.

A setter is simply a function whose job is to set, or change, a value. Here the value is the list of allowed addresses. The root cause is that this setter had no check on who was calling it.

Impact

The vulnerability was given a severity rating of "high". Funds at risk were very low, though if the bug had remained undetected and unpatched, it is possible that it would have become a much bigger issue down the line for future Alchemix strategies.

The reason the damage stayed small is the yearn.finance layer: Alchemix wraps a yearn vault, and yearn vaults have robust safeguards in place regarding forced withdrawals causing unexpected losses. Estimated losses from this attack are approximately $300, despite the fact that about 1,450 ETH is deposited into that Alchemix contract, which is then custodied in yearn.

To put that in plain terms: about 1,450 ETH sat in the Alchemix contract, held on its behalf by yearn. ETH is the native currency of the Ethereum blockchain. Even so, the estimated loss was only around $300, because yearn has protections that limit what a forced withdrawal can cost. The other effect was the denial of service described above.

Alchemix rewarded Ashiq a bounty of $7,500, paid to iosiro at request. Ashiq had previously picked up a bounty of $42,069 from 88mph.

Fix

The Alchemix team added an onlyGov modifier and changed the function name to setKeepers(), so that only governance can whitelist addresses to call harvest() and flush(). Alchemix has patched the vulnerability.

A modifier is a small piece of code attached to a function that runs a check before the function is allowed to proceed. onlyGov means the check is "is the caller the governance account?" Governance here means the official controlling account of the project. If the answer is no, the function refuses to run. Renaming the function to setKeepers() also makes its purpose clearer: it sets the keepers, not a general list.

Variants to test

These are the same checks a beginner can learn to look for in similar systems.

  1. Look for setter functions that configure keeper, operator or whitelist roles and check whether they carry an owner or governance modifier. A positive result is a setter that any externally owned account can call successfully and that changes the address allowed to invoke a privileged function. An externally owned account is an ordinary account controlled by a person or a key, as opposed to a contract.
  2. Check whether the privileged functions themselves (harvest(), flush() and equivalents) rely only on the whitelist for authorisation. If so, compromising the setter is equivalent to compromising the functions; a positive result is a whitelist entry added by a non-governance address that then passes the check in the privileged function.
  3. Test front-running of keeper transactions: if an attacker can occupy the whitelist slot or otherwise make the keeper's call revert, the keeper's harvest() and flush() can be blocked. A positive result is a repeated pattern where the keeper's transaction fails while the attacker's succeeds. To revert means to cancel a transaction and undo its effects.
  4. Review the underlying yield source for safeguards against forced withdrawals, since those safeguards are what bounded the loss here. A positive result is a wrapper whose loss on forced withdrawal is capped by the underlying vault rather than by the wrapper itself.
  5. Check for renamed or refactored versions of the same function across forks and deployments, since a rename to setKeepers() with onlyGov in one contract does not guarantee the same protection elsewhere. A fork is a copy of a project's code that someone else continues to develop separately.

Glossary

  • Access control: the rules that decide who is allowed to perform which action.
  • Address: a public identifier for an account on a blockchain.
  • alUSD: a synthetic token issued by Alchemix that represents future yield.
  • Bounty: a reward paid for finding and reporting a security bug.
  • Collateral: an asset deposited as security against a loan.
  • Contract (smart contract): a program that runs on a blockchain and follows fixed rules.
  • DAI: a digital currency token used in the Alchemix example.
  • Decentralised exchange: a trading service that runs without a central operator.
  • Denial of service: stopping a service from working for the people who need it.
  • ETH: the native currency of the Ethereum blockchain.
  • Externally owned account: an ordinary blockchain account controlled by a person or key, not a contract.
  • Fork: a copy of a project's code developed separately.
  • Front-running: getting your transaction processed just before someone else's to change the outcome.
  • Function: a named action inside a program that can be called.
  • Governance: the official controlling account or process of a project.
  • Harvest: collecting the yield earned by a vault.
  • Keeper: an automated helper that regularly calls maintenance functions.
  • Mint: to create new tokens according to a contract's rules.
  • Modifier: a check attached to a function that runs before the function is allowed to proceed.
  • Protocol: a set of rules and contracts that together provide a service.
  • Revert: to cancel a transaction and undo its effects.
  • Setter: a function whose job is to set or change a value.
  • Severity: a rating of how serious a vulnerability is.
  • Synthetic token: a token that stands in for something else, here future yield.
  • Token: a digital unit tracked by a contract on a blockchain.
  • Vault: a place where deposited funds are held and put to work to earn yield.
  • Whitehat: a researcher who finds security holes and reports them rather than abusing them.
  • Whitelist: a list of addresses allowed to do something.
  • Yield: the return earned on deposited funds over time.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.