Skip to content
Smart contracts Write-up Advanced

Wormhole

The Wormhole core bridge contract on Ethereum had an uninitialized proxy implementation, allowing an attacker to become the Guardian and force an upgrade to a malicious contract that self-destructs, potentially locking up user funds.

medium.com

Published on medium.com

Wormhole

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

Context

Wormhole is a cross-chain bridge, and the target of this disclosure was its core bridge contract on Ethereum. The contract is deployed behind an upgradeable proxy, so the address users interact with holds no logic of its own: it forwards every call to an implementation contract whose address is kept in the proxy's storage. Upgrading the bridge means changing that stored address, and the logic that performs the upgrade lives in the implementation contract, in the UUPS style.

What makes Wormhole's version different from a stock UUPS proxy is the authorisation model. An upgrade is not guarded by a single owner but by Guardians, who must produce a multi-sig message stating that the upgrade to a new implementation address is authorised. The implementation contract at [redacted] was, at the time of the report, uninitialised: a previous bugfix had reverted the original initialisation.

On 24 February a whitehat using the pseudonym satya0x responsibly disclosed a critical bug in this contract: an upgradeable proxy implementation self-destruct bug that could have led to a potential lockup of user funds. Wormhole verified and fixed the issue the same day it was reported, and no user funds were lost. Wormhole paid a record bug bounty of $10 million for the find.

From the original on medium.com

Setup

No accounts, tooling versions or request captures are described for the disclosure itself. What the report does give is the technical background needed to follow the bug, and it is worth setting out because the Wormhole issue is a generalisation of an earlier, wider OpenZeppelin problem.

The explanation of proxy patterns in the report uses the specifics and terminology of version 4.4.0 of OpenZeppelin's contracts. The Wormhole code was implemented differently but worked in practice very similarly. The upgrade behaviour described below applies to versions of UUPS prior to 4.4.2; more recent versions of the UUPS pattern in the OpenZeppelin library use a different safety mechanism.

Finding it

Proxies and DELEGATECALL

Ethereum has three major types of contract call: regular CALL, STATICCALL and DELEGATECALL. When contract A makes a CALL to contract B by calling foo(), execution relies on contract B's storage and msg.sender is set to contract A. Contract A called foo(), so msg.sender is contract A's address and msg.value is the ETH sent with that call. State changes made during the call can only affect contract B.

From the original on medium.com

With DELEGATECALL the same foo() is called on contract B but in the context of contract A. The logic of contract B is used, but state changes made by foo() affect the storage of contract A, and msg.sender points to the EOA that made the call in the first place.

From the original on medium.com

This is what makes upgradeable contracts possible. The proxy contract (A) redirects all calls it receives to an implementation contract whose address is stored in A's storage. From a user's perspective the proxy runs the implementation's code as its own, modifying the storage and balance of the proxy.

From the original on medium.com

An upgrade is then just a change to the stored implementation address. All incoming calls go to the new address and nothing changes for the user.

Initialisation

A contract's constructor runs automatically at deployment, and most developers put initialisation logic there. With a proxy this no longer works: the constructor would change only the implementation contract's storage (B), not the proxy's storage (A), which is the one that matters. The constructor is therefore turned into a regular function, conventionally called initialize or init, added to the implementation contract. Called from the proxy, it changes the proxy's storage. It also needs special logic to ensure it can only be called once, like a constructor.

Transparent proxies and UUPS

A proxy admin calling a proxy function such as transferOwnership() that shares a name with a function in the implementation raises the question of which one runs. The Transparent Proxy Pattern (TPP) resolves it by making all calls by a user execute the implementation's logic and all calls by the proxy admin execute the proxy's logic. One address is assigned as admin to deploy and manage the proxy, and when a call is not made from the admin the implementation is called instead.

From the original on medium.com

TPP needs extra logic in the proxy to manage the upgradability functions and to identify whether the caller is the admin, which reads storage and costs gas. UUPS moves the upgrade logic into the implementation contract instead. Calling upgradeToAndCall() on the proxy delegates to the same function on the implementation; executing in the context of the proxy, it changes the stored implementation address in the proxy, because the implementation has access to all of the proxy's storage. Proxy calls become cheaper, the caller is only checked when an upgrade is requested, and the name-collision case is handled by code Solidity generates automatically. All authorisation logic for upgradability sits in the implementation contract.

The OpenZeppelin UUPS uninitialised proxy vulnerability

The Wormhole bug was found by generalising the pattern of the OpenZeppelin UUPS vulnerability, which is closely related but affected many more deployed contracts. In a UUPS proxy the implementation provides initialize(), and developers often also use upgradeable versions of the standard OpenZeppelin contracts, which implement their own initialize() functions. The example in the report is taken from OpenZeppelin's security advisory post.

From the original on medium.com

initialize() calls __Ownable_init, which sets the owner of the implementation contract to the first person to call it. That is the key point: the owner of a UUPS implementation contract controls the upgrade functions and can call upgradeToAndCall() directly on the implementation contract instead of going through the proxy.

upgradeToAndCall() changes the implementation address and, in the same transaction, executes any migration or initialisation function using DELEGATECALL with the data passed along. If the new implementation's initialisation function executes the SELFDESTRUCT opcode, the DELEGATECALL caller is destroyed. Normally that would be the proxy, which is not a concern because only the proxy's admin can call upgradeToAndCall(). The question the researcher asked is what happens if the implementation contract can be made to run upgradeToAndCall() in its own context. The proxy would then forward all calls to an empty address, and since the upgrade logic lives in the implementation by design, upgrading would no longer be possible and nobody could switch the mechanism to fix it.

The Wormhole case

Wormhole's implementation contract at [redacted] was uninitialised after the earlier bugfix reverted the original initialisation. An attacker could therefore pass their own Guardian set and proceed with an upgrade as a Guardian they controlled. Once in control of the Guardian address, the attacker can use submitContractUpgrade() to force an upgrade attempt, causing a DELEGATECALL to an attacker-submitted address. If that address is a contract that executes a SELFDESTRUCT opcode, the implementation contract is destroyed.

From the original on medium.com

submitContractUpgrade() takes bytes _vm, a multi-sig message prepared by the Guardian instructing the system to upgrade to the contract encoded in the message. After all safety checks, which the attacker passes because they are a valid Guardian, the function calls upgradeImplementation(), which makes the delegatecall to the initialize() function. The malicious implementation contract needs a SELFDESTRUCT instruction in its initialize() function to destroy the current implementation contract.

Exploitation

The report gives a step-by-step guide for the Wormhole exploit, mirroring the UUPS issue. It is a hypothetical attack description.

Step 1: take ownership of the implementation

The attacker calls initialize() on the implementation contract to set an attacker-controllable Guardian set. Because the implementation was left uninitialised, the call succeeds.

Step 2: deploy the destructive contract

The attacker deploys a malicious contract with a selfdestruct() function.

Step 3: submit the upgrade

The attacker calls submitContractUpgrade() on the implementation contract and passes a signature signed by the malicious Guardian, encoding the address of the malicious implementation contract for an upgrade.

Step 4: the delegatecall

During submitContractUpgrade() execution, DELEGATECALL is called from the regular implementation contract to the malicious implementation contract.

Step 5: self-destruct

SELFDESTRUCT is called, destroying the regular implementation contract.

Step 6: the proxy is useless

The proxy contract now forwards all calls to an empty address. Upgrading is no longer possible, and the upgrade mechanism cannot be switched because the upgrade logic is hosted on the implementation contract by design of the UUPS pattern.

The Immunefi triaging team prepared a runnable proof of concept of the bug for educational purposes, available at https://github.com/immunefi-team/wormhole-uninitialized.

Root cause

The mistake is an uninitialised implementation contract behind a UUPS-style proxy. Because initialize() had never been called on the implementation itself, the first caller could claim it, and in Wormhole's design that meant installing a Guardian set the attacker controlled. The upgrade path trusts the Guardian multi-sig, so a valid-looking Guardian message passed every safety check and reached upgradeImplementation(), which delegatecalls into the address named in the message. A malicious implementation whose initialize() runs SELFDESTRUCT therefore destroys the caller, and the caller here is the implementation contract itself, not the proxy.

The existing defence, that only an authorised party can trigger an upgrade, did not help because the authorisation state was itself uninitialised and claimable. The proxy pattern's own design then prevents recovery: with the logic gone, there is nothing left to call to point the proxy at a new implementation.

Impact

An attacker able to claim the uninitialised implementation could destroy it and render the proxy contract useless, forwarding all calls to an empty address. Upgrading would no longer be possible and nobody could switch the upgrade mechanism to fix it. The report describes this as a bug that could have led to a potential lockup of user funds. No user funds were lost, and the issue was verified and fixed on the day it was reported.

Fix

The Wormhole team fixed the issue in the transaction at https://etherscan.io/tx/[redacted]. The transaction called initialize() on the implementation contract and set the Guardians, The transaction called initialize() on the implementation contract and set the Guardians.

Variants to test

  1. Look for UUPS or proxy-based contracts whose implementation address has never had initialize() called on it. A positive result is a successful initialize() call from an address that is not the project, followed by control of the owner or admin role on the implementation.
  2. Check whether the implementation's owner can call upgradeToAndCall() directly on the implementation rather than through the proxy. A positive result is an upgrade path that executes in the implementation's own context.
  3. Trace what upgradeToAndCall() delegatecalls into and whether the target's initialisation function can contain SELFDESTRUCT. A positive result is destruction of the implementation contract and a proxy left pointing at an empty address.
  4. On custom upgrade schemes such as Wormhole's Guardian multi-sig, test whether the authorisation state (the Guardian set) is claimable on the implementation. A positive result is a self-supplied Guardian set that passes the upgrade checks.
  5. Check the OpenZeppelin version in use against the UUPS changes before and after 4.4.2. A positive result is an older pattern without the newer safety mechanism, combined with an uninitialised implementation.

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

What happened, in plain words

Wormhole is a bridge: a piece of software that moves digital assets between different blockchains. The part that was attacked is its core bridge contract on Ethereum. A contract here is a small program that lives at a fixed address on the blockchain and runs automatically when someone sends it a message.

On 24 February, a security researcher using the pseudonym satya0x found a serious flaw in that contract and reported it privately to the Wormhole team instead of exploiting it. This is called a responsible disclosure: you tell the people who can fix the problem before you tell anyone else. The flaw was an upgradeable proxy implementation self-destruct bug, which could have led to a potential lockup of user funds. Wormhole verified and fixed the issue the same day it was reported, and no user funds were lost. Wormhole paid a record bug bounty of $10 million for the find. A bug bounty is a reward a company offers to anyone who reports a security problem to them.

From the original on medium.com

The rest of this article explains, from zero, what a proxy is, why this particular kind of proxy can be dangerous, and how the Wormhole bug worked. No prior security knowledge is needed, only the willingness to follow a few everyday comparisons.

Setup

The report does not describe any accounts, tooling versions or captured requests for the disclosure itself. What it does give is the technical background needed to follow the bug, and that background matters because the Wormhole issue is a generalisation of an earlier, wider problem in a widely used library called OpenZeppelin.

The explanation of proxy patterns in the report uses the specifics and terminology of version 4.4.0 of OpenZeppelin's contracts. The Wormhole code was implemented differently but worked in practice very similarly. The upgrade behaviour described below applies to versions of UUPS prior to 4.4.2; more recent versions of the UUPS pattern in the OpenZeppelin library use a different safety mechanism.

Finding it

Proxies and DELEGATECALL

Ethereum has three major types of contract call: regular CALL, STATICCALL and DELEGATECALL. A call is simply one program asking another program to run a function. Think of a function as a named action, like foo(), that a program can perform.

When contract A makes a CALL to contract B by calling foo(), execution relies on contract B's storage and msg.sender is set to contract A. Storage is the contract's own memory, the place where it keeps its data. msg.sender is a built-in value that tells a function who is asking. Contract A called foo(), so msg.sender is contract A's address and msg.value is the ETH sent with that call. ETH is the currency of Ethereum. State changes made during the call can only affect contract B.

An everyday comparison: you phone a restaurant and ask them to note your order in their book. The order goes into their book, not yours, and the restaurant knows the call came from your phone number.

From the original on medium.com

With DELEGATECALL the same foo() is called on contract B but in the context of contract A. The logic of contract B is used, but state changes made by foo() affect the storage of contract A, and msg.sender points to the EOA that made the call in the first place. An EOA, externally owned account, is a normal wallet controlled by a person rather than a contract.

The same comparison: you borrow the restaurant's recipe book but write the notes into your own notebook, and the recipe still thinks the original caller is on the line.

From the original on medium.com

This is what makes upgradeable contracts possible. The proxy contract (A) redirects all calls it receives to an implementation contract whose address is stored in A's storage. From a user's perspective the proxy runs the implementation's code as its own, modifying the storage and balance of the proxy.

Think of a shop front that never changes its address but hires a new manager behind the counter. Customers keep walking into the same door; the person serving them can be swapped.

From the original on medium.com

An upgrade is then just a change to the stored implementation address. All incoming calls go to the new address and nothing changes for the user.

Initialisation

A contract's constructor runs automatically at deployment, and most developers put initialisation logic there. Initialisation means setting the starting values: who owns the contract, which settings are active, and so on. With a proxy this no longer works: the constructor would change only the implementation contract's storage (B), not the proxy's storage (A), which is the one that matters. The constructor is therefore turned into a regular function, conventionally called initialize or init, added to the implementation contract. Called from the proxy, it changes the proxy's storage. It also needs special logic to ensure it can only be called once, like a constructor.

In everyday terms: the new manager's personal notebook is not the shop's ledger. So the setup steps are written as a normal task that the shop itself performs, and a lock is added so the setup cannot be run twice.

Transparent proxies and UUPS

A proxy admin calling a proxy function such as transferOwnership() that shares a name with a function in the implementation raises the question of which one runs. The Transparent Proxy Pattern (TPP) resolves it by making all calls by a user execute the implementation's logic and all calls by the proxy admin execute the proxy's logic. One address is assigned as admin to deploy and manage the proxy, and when a call is not made from the admin the implementation is called instead.

From the original on medium.com

TPP needs extra logic in the proxy to manage the upgradability functions and to identify whether the caller is the admin, which reads storage and costs gas. Gas is the fee paid for computation on Ethereum. UUPS moves the upgrade logic into the implementation contract instead. Calling upgradeToAndCall() on the proxy delegates to the same function on the implementation; executing in the context of the proxy, it changes the stored implementation address in the proxy, because the implementation has access to all of the proxy's storage. Proxy calls become cheaper, the caller is only checked when an upgrade is requested, and the name-collision case is handled by code Solidity generates automatically. Solidity is the programming language used to write Ethereum contracts. All authorisation logic for upgradability sits in the implementation contract.

A comparison: instead of a receptionist in the lobby checking every visitor, the manager upstairs handles the rare request to change the building's locks, and only then checks who is asking.

The OpenZeppelin UUPS uninitialised proxy vulnerability

The Wormhole bug was found by generalising the pattern of the OpenZeppelin UUPS vulnerability, which is closely related but affected many more deployed contracts. In a UUPS proxy the implementation provides initialize(), and developers often also use upgradeable versions of the standard OpenZeppelin contracts, which implement their own initialize() functions. The example in the report is taken from OpenZeppelin's security advisory post.

From the original on medium.com

initialize() calls __Ownable_init, which sets the owner of the implementation contract to the first person to call it. That is the key point: the owner of a UUPS implementation contract controls the upgrade functions and can call upgradeToAndCall() directly on the implementation contract instead of going through the proxy.

upgradeToAndCall() changes the implementation address and, in the same transaction, executes any migration or initialisation function using DELEGATECALL with the data passed along. A transaction is a single recorded action on the blockchain. If the new implementation's initialisation function executes the SELFDESTRUCT opcode, the DELEGATECALL caller is destroyed. An opcode is a low-level instruction the machine executes; SELFDESTRUCT tells the blockchain to delete a contract. Normally that would be the proxy, which is not a concern because only the proxy's admin can call upgradeToAndCall(). The question the researcher asked is what happens if the implementation contract can be made to run upgradeToAndCall() in its own context. The proxy would then forward all calls to an empty address, and since the upgrade logic lives in the implementation by design, upgrading would no longer be possible and nobody could switch the mechanism to fix it.

Comparison: the shop's manager is allowed to hire a replacement manager. If someone can trick the manager into hiring a replacement who immediately burns down the manager's office, the shop front still stands but there is nobody left to run it, and the hiring process itself lived in that office.

The Wormhole case

Wormhole's implementation contract at [redacted] was uninitialised after the earlier bugfix reverted the original initialisation. An attacker could therefore pass their own Guardian set and proceed with an upgrade as a Guardian they controlled. Guardians are the parties whose multi-sig message authorises an upgrade; a multi-sig is a rule that several signatures are needed before an action is accepted. Once in control of the Guardian address, the attacker can use submitContractUpgrade() to force an upgrade attempt, causing a DELEGATECALL to an attacker-submitted address. If that address is a contract that executes a SELFDESTRUCT opcode, the implementation contract is destroyed.

From the original on medium.com

submitContractUpgrade() takes bytes _vm, a multi-sig message prepared by the Guardian instructing the system to upgrade to the contract encoded in the message. After all safety checks, which the attacker passes because they are a valid Guardian, the function calls upgradeImplementation(), which makes the delegatecall to the initialize() function. The malicious implementation contract needs a SELFDESTRUCT instruction in its initialize() function to destroy the current implementation contract.

Exploitation

The report gives a step-by-step guide for the Wormhole exploit, mirroring the UUPS issue. It is a hypothetical attack description.

Step 1: take ownership of the implementation

The attacker calls initialize() on the implementation contract to set an attacker-controllable Guardian set. Because the implementation was left uninitialised, the call succeeds. The reason for this step is that the setup function had never been run on the implementation itself, so the first caller could claim it.

Step 2: deploy the destructive contract

The attacker deploys a malicious contract with a selfdestruct() function.

Step 3: submit the upgrade

The attacker calls submitContractUpgrade() on the implementation contract and passes a signature signed by the malicious Guardian, encoding the address of the malicious implementation contract for an upgrade. The attacker passes the safety checks because they are a valid Guardian.

Step 4: the delegatecall

During submitContractUpgrade() execution, DELEGATECALL is called from the regular implementation contract to the malicious implementation contract. The call runs in the implementation's own context, mirroring the UUPS issue.

Step 5: self-destruct

SELFDESTRUCT is called, destroying the regular implementation contract.

Step 6: the proxy is useless

The proxy contract now forwards all calls to an empty address. Upgrading is no longer possible, and the upgrade mechanism cannot be switched because the upgrade logic is hosted on the implementation contract by design of the UUPS pattern.

The Immunefi triaging team prepared a runnable proof of concept of the bug for educational purposes, available at https://github.com/immunefi-team/wormhole-uninitialized.

Root cause

The mistake is an uninitialised implementation contract behind a UUPS-style proxy. Because initialize() had never been called on the implementation itself, the first caller could claim it, and in Wormhole's design that meant installing a Guardian set the attacker controlled. The upgrade path trusts the Guardian multi-sig, so a valid-looking Guardian message passed every safety check and reached upgradeImplementation(), which delegatecalls into the address named in the message. A malicious implementation whose initialize() runs SELFDESTRUCT therefore destroys the caller, and the caller here is the implementation contract itself, not the proxy.

The existing defence, that only an authorised party can trigger an upgrade, did not help because the authorisation state was itself uninitialised and claimable. The proxy pattern's own design then prevents recovery: with the logic gone, there is nothing left to call to point the proxy at a new implementation.

Impact

An attacker able to claim the uninitialised implementation could destroy it and render the proxy contract useless, forwarding all calls to an empty address. Upgrading would no longer be possible and nobody could switch the upgrade mechanism to fix it. The report describes this as a bug that could have led to a potential lockup of user funds. No user funds were lost, and the issue was verified and fixed on the day it was reported.

Fix

The Wormhole team fixed the issue in the transaction at https://etherscan.io/tx/[redacted]. The transaction called initialize() on the implementation contract and set the Guardians, The transaction called initialize() on the implementation contract and set the Guardians.

Variants to test

  1. Look for UUPS or proxy-based contracts whose implementation address has never had initialize() called on it. A positive result is a successful initialize() call from an address that is not the project, followed by control of the owner or admin role on the implementation.
  2. Check whether the implementation's owner can call upgradeToAndCall() directly on the implementation rather than through the proxy. A positive result is an upgrade path that executes in the implementation's own context.
  3. Trace what upgradeToAndCall() delegatecalls into and whether the target's initialisation function can contain SELFDESTRUCT. A positive result is destruction of the implementation contract and a proxy left pointing at an empty address.
  4. On custom upgrade schemes such as Wormhole's Guardian multi-sig, test whether the authorisation state (the Guardian set) is claimable on the implementation. A positive result is a self-supplied Guardian set that passes the upgrade checks.
  5. Check the OpenZeppelin version in use against the UUPS changes before and after 4.4.2. A positive result is an older pattern without the newer safety mechanism, combined with an uninitialised implementation.

Glossary

  • Bug bounty: a reward a company offers to anyone who reports a security problem to them.
  • Bridge: software that moves digital assets between different blockchains.
  • Contract: a small program that lives at a fixed address on a blockchain and runs automatically when called.
  • Proxy: a contract that keeps a fixed address and forwards calls to another contract whose address it stores.
  • Implementation contract: the contract that holds the actual logic a proxy forwards to.
  • Storage: a contract's own memory where it keeps its data.
  • State change: a modification to the data a contract keeps.
  • CALL: a contract call where the called contract's own storage is used.
  • STATICCALL: one of the three major types of contract call on Ethereum, alongside CALL and DELEGATECALL.
  • DELEGATECALL: a contract call that runs another contract's code in the caller's context, so storage changes hit the caller.
  • msg.sender: a built-in value telling a function who is asking.
  • msg.value: a built-in value holding the ETH sent with a call.
  • ETH: the currency of Ethereum.
  • EOA (externally owned account): a normal wallet controlled by a person rather than a contract.
  • Constructor: code that runs automatically when a contract is deployed.
  • Initialisation: setting a contract's starting values, such as its owner and settings.
  • initialize / init: the regular function that replaces a constructor when a proxy is used.
  • Gas: the fee paid for computation on Ethereum.
  • Solidity: the programming language used to write Ethereum contracts.
  • Transparent Proxy Pattern (TPP): a proxy design where user calls run the implementation's logic and admin calls run the proxy's logic.
  • UUPS: a proxy design where the upgrade logic lives in the implementation contract rather than the proxy.
  • upgradeToAndCall(): the function that changes the implementation address and runs an initialisation function in the same transaction.
  • Transaction: a single recorded action on the blockchain.
  • Opcode: a low-level instruction the machine executes.
  • SELFDESTRUCT: an opcode that tells the blockchain to delete a contract.
  • Guardian: in Wormhole, a party whose multi-sig message authorises an upgrade.
  • Multi-sig: a rule that several signatures are needed before an action is accepted.
  • submitContractUpgrade(): the Wormhole function that takes a Guardian message and triggers an upgrade attempt.
  • upgradeImplementation(): the internal function that performs the delegatecall to the new implementation's initialisation function.
  • Proof of concept: a runnable demonstration that a bug can actually be triggered.
  • Responsible disclosure: reporting a security problem privately to the people who can fix it before telling anyone else.
  • Whitehat: a security researcher who reports problems instead of exploiting them.
  • OpenZeppelin: a widely used library of standard smart contracts.
  • Revert: undoing a change, here used for a bugfix that undid the original initialisation.

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.