[web3] xDai Stake Arbitrary Call Method Bug Postmortem. This is a postmortem of a vulnerability… | by Immunefi | Sep, 2021 | Medium
The xDai Arbitrary Message Bridge contracts allowed calls to any method of any contract, so an attacker could craft a message that executed a token transfer on behalf of the bridge contract. This could steal tokens that users had mistakenly sent to the bridge contract, though the bridge was not intended to hold funds.
medium.com
Published on medium.com
Xdai
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.
Context
xDai is an Ethereum sidechain, and a bridge connects the Ethereum Mainnet with the xDai chain. That bridge lets users pass arbitrary messages from one chain to the other, which is why it is called an Arbitrary Message Bridge (AMB). One part of the bridge is the set of contracts deployed on both chains. EOAs or other contracts can use them to execute contracts on the other side of the bridge.
Because the AMB contracts allow calls of any method of any contract, a malicious attacker could compose a message that would execute a token transfer on behalf of the AMB contracts. The AMB contracts are not intended to own any tokens, but users could still mistakenly send tokens to them. Once an attacker discovers such tokens, they could be stolen.
The OmniBridge contracts, which are intended to keep funds sent through the AMB, are not affected by this vulnerability.
Setup
On 1 August, whitehat 0xadee028d submitted an arbitrary method call vulnerability in xDai to Immunefi. The vulnerability was assessed to have a severity level of medium, but was out of scope of xDai's bug bounty program. No special accounts, tools or versions are described in the report.
Finding it
The AMB contracts allow calls of any method of any contract. Since the AMB contracts are not intended to own any tokens, but users could mistakenly send tokens to them, a message composed through the bridge could execute a token transfer on behalf of the AMB contracts, moving any tokens that had been sent there.

Exploitation
Step 1: Compose a message through the AMB
An attacker could compose a message through the Arbitrary Message Bridge that calls a token transfer method on behalf of the AMB contracts. The report does not include the exact message, payload or request used.
Step 2: Target tokens sent to the AMB contracts
The impact depends on tokens having been sent to the AMB contracts. At the time of the report, a user had accidentally sent $4.50 in renBTC to the contract 10 months prior, which amounted to the total funds at risk. If users had sent more funds to that contract, more would have been at risk, and the same holds for any funds sent to that contract in the future.
Root cause
The AMB contracts allow calls of any method of any contract, so a message can be composed that executes a token transfer on behalf of the AMB contracts. The contracts are not intended to own any tokens, but users could mistakenly send tokens to them, and any tokens that arrived there could be moved by such a message.
Impact
A potentially malicious hacker could gain access to funds in a contract that users were never supposed to send funds to in the first place. At the time of the report, the total funds at risk were $4.50 in renBTC, sent accidentally 10 months prior. The OmniBridge contracts, which are intended to keep funds sent through the AMB, are not affected.
Despite the vulnerability being out of scope, xDai generously decided to pay out a bounty of $5,000 USDC to the whitehat.
Fix
xDai plans to introduce a monitor on the AMB contract to watch for Transfer events, so that the team will be able to identify locked tokens before they could be accessed by someone else.
Variants to test
- A positive result is a message that moves tokens held by the bridge contract.
- A positive result is a non-zero token balance on the bridge contract that can be transferred out.
- A positive result is a bridge contract holding tokens with no monitoring in place.
What happened, in plain words
A security researcher found a flaw in a system called xDai, which is a blockchain network connected to Ethereum. The flaw could let someone use a bridge between the two networks to move tokens that had been sent to the bridge by mistake. At the time, the only tokens sitting there were worth $4.50, sent by a user ten months earlier. The flaw was rated medium severity, but it fell outside the rules of xDai's bug bounty programme, so it was not eligible for a reward. Even so, xDai paid the researcher $5,000 USDC as a thank you. This article walks through what the bridge does, why the flaw existed, what could have gone wrong, and how xDai planned to fix it, explaining each idea from scratch.
Background: what xDai and the bridge are
To follow this story you need a few basic ideas.
- A blockchain is a shared record of transactions that many computers keep copies of. Once something is written, it is very hard to change.
- Ethereum is one well-known blockchain. xDai is a separate blockchain that runs alongside Ethereum. The report calls xDai an Ethereum sidechain, meaning a chain that is linked to Ethereum but operates on its own.
- A token is a digital asset recorded on a blockchain. Examples named in the report are renBTC and USDC. Tokens can be sent from one address to another.
- A smart contract is a small program that lives on a blockchain. It has its own address and can hold tokens. People or other programs can call functions on it, and it runs the code those functions contain.
- An EOA (externally owned account) is an ordinary account controlled by a person with a private key, as opposed to a contract. The report says the bridge contracts can be used by EOAs or other contracts.
- A bridge connects two blockchains so value or information can move between them.
xDai uses a particular kind of bridge called an Arbitrary Message Bridge (AMB). "Arbitrary message" means the bridge will carry a message of any shape from one chain to the other. Think of it like a postal service that will deliver any letter you write, without checking what is inside. That flexibility is useful, but it also means the message can ask the receiving side to do almost anything.
The bridge is made of contracts deployed on both chains. A contract on one side can be used to trigger a contract on the other side. The report says these AMB contracts are not meant to own any tokens. They are plumbing, not a wallet.
There is also a separate set of contracts called OmniBridge, which are the ones actually intended to hold funds that travel through the AMB. The report is clear that OmniBridge is not affected by this vulnerability.
The flaw in one sentence
Because the AMB contracts let a message call any function of any contract, an attacker could write a message that tells a token contract to transfer tokens on behalf of the AMB contracts. If any tokens had been sent to the AMB contracts by mistake, that message could move them out.
A useful comparison: imagine a building's front desk that will sign for any delivery on behalf of any tenant, no questions asked. If a parcel is accidentally addressed to the front desk itself, anyone who knows the desk will sign for anything can walk in and collect it.
How the researcher found it
Two facts sit next to each other:
- The AMB contracts allow calls of any method of any contract.
- The AMB contracts are not intended to own tokens, but users could mistakenly send tokens to them.
Either fact alone is not a disaster. Together they are a problem: a message composed through the bridge could execute a token transfer on behalf of the AMB contracts, moving any tokens that had been sent there. The whitehat reported this to Immunefi, a bug bounty platform, on 1 August. The report does not describe any special accounts, tools or software versions used.

The image above is the header of the published review, titled "xDai Stake Arbitrary Call Method Bugfix Review".
What an attacker would actually do
Step 1: Compose a message through the AMB
An attacker could write a message that travels through the Arbitrary Message Bridge and asks a token contract to transfer tokens on behalf of the AMB contracts. Because the bridge does not restrict which function the message calls, the message can be shaped to do exactly that. The report does not include the exact message, payload or request used, so there is no code to show for this step.
Why this step matters: the bridge is the delivery mechanism. Without a way to make the AMB contracts act on the attacker's behalf, the tokens sitting in those contracts would be stuck.
Step 2: Target tokens sent to the AMB contracts
For the attack to be worth anything, tokens must already be sitting in the AMB contracts. At the time of the report, a user had accidentally sent $4.50 in renBTC to the contract ten months earlier. That was the entire amount at risk. If users had sent more funds to that contract, more would have been at risk, and the same holds for any funds sent to that contract in the future.
Why this step matters: the flaw is only exploitable against whatever balance happens to be there. The attacker cannot conjure tokens; they can only redirect tokens that were mistakenly sent to the bridge.
Why the flaw existed
The root cause is the combination described above. The AMB contracts allow calls of any method of any contract, so a message can be composed that executes a token transfer on behalf of the AMB contracts. The contracts are not intended to own any tokens, but users could mistakenly send tokens to them, and any tokens that arrived there could be moved by such a message.
What the impact was
A malicious hacker could gain access to funds in a contract that users were never supposed to send funds to in the first place. At the time of the report, the total funds at risk were $4.50 in renBTC, sent accidentally ten months prior. The OmniBridge contracts, which are intended to keep funds sent through the AMB, are not affected.
The vulnerability was assessed as medium severity, but it was out of scope of xDai's bug bounty programme. Despite that, xDai decided to pay a bounty of $5,000 USDC to the whitehat, 0xadee028d.
How xDai planned to fix it
xDai plans to introduce a monitor on the AMB contract to watch for Transfer events, so the team can identify locked tokens before someone else could access them. A Transfer event is a notification that a token contract emits whenever tokens move; watching for it is like putting an alarm on the front desk so staff know when a parcel arrives addressed to it.
Other places to look for the same pattern
- A positive result is a message that moves tokens held by the bridge contract.
- A positive result is a non-zero token balance on the bridge contract that can be transferred out.
- A positive result is a bridge contract holding tokens with no monitoring in place.
Glossary
- Blockchain: a shared, tamper-resistant record of transactions kept by many computers.
- Ethereum: a public blockchain that runs smart contracts.
- xDai: an Ethereum sidechain, a separate blockchain linked to Ethereum.
- Sidechain: a blockchain that runs alongside another chain and is connected to it.
- Token: a digital asset recorded on a blockchain, such as renBTC or USDC.
- renBTC: a token named in the report as the asset that had been sent to the contract by mistake.
- USDC: a token named in the report as the currency of the bounty payout.
- Smart contract: a program deployed on a blockchain with its own address, which can hold tokens and run code when called.
- EOA (externally owned account): an ordinary blockchain account controlled by a person with a private key.
- Bridge: a system that moves value or messages between two blockchains.
- Arbitrary Message Bridge (AMB): a bridge that carries a message of any shape from one chain to another, without restricting what the message asks for.
- OmniBridge: the set of contracts intended to hold funds sent through the AMB; the report says it is not affected.
- Method / function: a named action a smart contract can perform when called.
- Arbitrary method call: the ability for a message to invoke any method of any contract, which is the property at the heart of this report.
- Transfer event: a notification a token contract emits when tokens move, which xDai plans to monitor.
- Whitehat: a security researcher who reports flaws to help fix them rather than to exploit them.
- Bug bounty programme: a scheme that pays researchers for reporting vulnerabilities, usually with rules about which systems are in scope.
- Out of scope: outside the rules of a bug bounty programme, so not eligible for a reward.
- Severity: a rating of how serious a vulnerability is; here it was assessed as medium.
- Immunefi: the bug bounty platform to which the researcher submitted the report.
- Monitor: an automated watch on a contract, here one that would look for Transfer events.