Skip to content
Business logic Write-up Advanced

[web3] Cronos: Theft of Transactions Fees Bugfix Postmortem. This is a postmortem of a vulnerability… | by Immunefi | Sep, 2022 | Medium

A missing check allowed a Cosmos-signed transaction to skip the Ethereum gas fee deduction while still receiving a gas refund, letting an attacker steal transaction fees from the current block. The attacker could repeat this for every block.

medium.com

Published on medium.com

Cronos

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

Context

Cronos is a blockchain built on the Cosmos SDK that is compatible with the Ethereum Virtual Machine (EVM). Its purpose, in the words of Cronos' own description quoted in the report, is to connect the EVM chains and the Cosmos ecosystem so that crypto assets and dApps can interoperate across a multichain world.

The underlying technology is Ethermint, a Proof-of-Stake blockchain that is compatible with Ethereum and runs on the Cosmos SDK on top of the Tendermint Core consensus engine. Because Ethermint serves both EVM-based chains and Cosmos-specific chains, its client has to parse and handle transactions routed for both. It does this by mimicking Geth's transaction structure and treating an Ethereum transaction as a unique Cosmos SDK message type: an Ethereum transaction is a single SDK.Msg contained in an auth.StdTx, and all relevant Ethereum transaction information (signature, gas, payload and so on) lives in that message.

The message in question is MsgEthereumTx. It wraps an Ethereum transaction as an SDK message and is how the chain performs state transitions for Ethereum-style transactions.

Transactions are the only thing that can modify or update blockchain state. They are signed messages, originated from an externally owned account (EOA), that are propagated to every node by gossip. The Ethereum transaction structure the report lists is:

  • Nonce: an originating EOA-issued sequence number used to prevent message replay.
  • Gas price: how much Ether (in Wei) the originator is prepared to pay for each unit of gas.
  • Gas limit: the quantity of gas the originator is prepared to purchase for this transaction.
  • Recipient: the Ethereum address of the final destination, which may be another EOA or a contract address.
  • Value: the amount of Ether to transmit to the destination (in Wei).
  • Data: variable-length binary data payload.
  • v, r, s: the three components of the original EOA's ECDSA digital signature.

When transactions are consumed in Ethermint they pass through a sequence of handlers. One of them is the AnteHandler, which performs preliminary message execution business logic such as fee payment and signature verification. It applies only to transactions conducted through the Cosmos SDK; Ethereum-routed transactions are handled by the EVM, which performs the same business logic.

Setup

Ethermint exposes standard JSON-RPC endpoints for sending an Ethereum transaction. When a transaction is submitted through the compatibility JSON-RPC endpoint, it is reformatted as a MsgEthereumTx and an ExtensionOptionsEthereumTx is appended to it. When a node processes the transaction, that extension causes it to be processed by the appropriate antehandlers, including the EthGasConsume handler, which deducts gas price * gas limit from the originating account. After the transaction executes, the fee is refunded.

This path needs no Cosmos signature, and it ensures the gas limit in the Ethereum message is subtracted first, as it would be on Ethereum.

The researcher is credited as zb3. The report does not describe any particular account, tooling or version used to prepare the finding beyond the transaction construction described below.

Finding it

What zb3 noticed is that there is no check that a MsgEthereumTx actually carries an ExtensionOptionsEthereumTx. A MsgEthereumTx can therefore be packaged without that extension and submitted to the node directly. Doing so executes only the standard set of antehandlers, because the option that would route the transaction through the Ethereum-specific antehandlers is absent. Several antehandlers that are supposed to run before MsgEthereumTx is handled are skipped as a result.

One of the handlers that is skipped is EthGasConsumeDecorator(evmKeeper). Its primary purpose is to ensure that the Ethereum transaction message has sufficient funds to cover intrinsic gas and that the sender has the funds to cover the gas cost. Intrinsic gas is the quantity of gas consumed by a transaction before it is completed; it is distinct from the Cosmos fee because it is meant to be refunded.

Because the gas cost is never deducted, an arbitrary gas limit can be specified and the transaction can then be "refunded" gas that was never deducted in the first place. The transaction can be "refunded" gas that was never deducted in the first place.

Exploitation

Step 1: build a cosmos-signed MsgEthereumTx with a valid Ethereum signature

The attacker constructs a MsgEthereumTx carrying a valid Ethereum signature, signs it at the Cosmos level, and deliberately omits ExtensionOptionsEthereumTx. The report gives no concrete payload for this step; the construction is described in prose only.

Step 2: set a high GasLimit

Because the EthGasConsumeDecorator will not run, the gas limit is not checked against the sender's balance and is not deducted. The attacker sets it high, and the refund is calculated from that figure.

Step 3: submit the transaction to the node

The transaction is submitted without the extension option. Only the standard antehandlers run, the Ethereum-specific ones are skipped, and the transaction receives a gas refund even though the gas charge was never taken.

Step 4: repeat per block

Before the malicious transaction executes, the transaction fees in the current block might be seized, and the attack can be repeated for every block.

Root cause

There is no check that a MsgEthereumTx carries an ExtensionOptionsEthereumTx. A message submitted without it takes the Cosmos path, skipping the handlers that would have deducted the gas cost. Nothing verifies that the extension is present. A message submitted without it takes the Cosmos path, skipping the handlers that would have deducted the gas cost, while the refund logic still runs. The result is that gas can be "refunded" that was never deducted.

Impact

The report classifies the issue as a theft of yield: user rewards were affected, but funds were not drained. It was filed as a high severity report on that basis. An attacker could seize the transaction fees of the current block before the malicious transaction executed, and could repeat the attack for every block. The report does not quantify the amounts at risk.

zb3 submitted the bug to Immunefi on December 12th and received a bounty of $40K from the Cronos team, followed by a swift fix.

Fix

Cronos now checks whether the MsgEthereumTx is contained inside the transaction. The fix was applied to the current Cronos mainnet beta in the binary upgrade of v0.6.5 (see https://github.com/crypto-org-chain/cronos/security/advisories/GHSA-f854-hpxv-cw9r).

Variants to test

  1. Submit a MsgEthereumTx without ExtensionOptionsEthereumTx on any Ethermint-based chain and watch the sender balance. A positive result is a refund credited without a matching deduction.
  2. Vary the GasLimit upward on such a message. A positive result is a refund that scales with the limit despite the sender lacking the funds to cover it.
  3. Look for other message types whose antehandler routing depends on an optional extension being present. A positive result is a message that reaches execution while skipping fee or signature checks that its normal entry point would enforce.
  4. Compare the antehandler set executed for the JSON-RPC path against the path taken by a directly submitted message. A positive result is any handler present in one path and absent in the other without an explicit check enforcing 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. 14 min read.

What happened, in plain words

A blockchain is a shared record book that many computers keep copies of. On most blockchains you cannot change anything in that book for free: every change is a transaction, and every transaction carries a small payment called a fee. The fee is what pays the computers that do the work of recording your change.

Cronos is one such blockchain. It is built to speak two languages at once: the language of Ethereum (the best-known blockchain for running small programs called smart contracts) and the language of Cosmos (a family of blockchains that are designed to talk to each other). The piece of software that lets Cronos do this is called Ethermint.

A security researcher known as zb3 found a way to build a transaction that would never actually pay its fee, yet would still be handed a refund of that fee as if it had. Before the malicious transaction executed, the transaction fees in the current block might be seized. The attack could be repeated on every block.

zb3 reported it to Immunefi, a platform where researchers report bugs in exchange for money, on 12 December. The report was rated high severity because it was classed as a theft of yield: other users' rewards were affected, but nobody's stored funds were drained. The Cronos team paid a bounty of $40K and fixed the bug quickly.

From the original on medium.com

The rest of this article walks through the same ground as the technical write-up, but from zero. We will explain what a blockchain transaction is, what Ethermint does with one, where the missing check was, and how the fix closes it.

Background: what Cronos and Ethermint are

Cronos describes itself, in the words the report quotes from Cronos' own Medium post, as:

"Built on the Cosmos SDK while being Ethereum Virtual Machine (EVM) compatible, Cronos is uniquely positioned to connect the EVM chains and Cosmos ecosystem to enable seamless crypto assets and dApps interoperability in the multichain world."

That sentence is dense, so let us unpack it.

  • Cosmos SDK: a toolkit for building blockchains. Think of it as a box of ready-made parts (accounts, fees, voting on new blocks) that a team can assemble into its own chain instead of writing everything from scratch.
  • Ethereum Virtual Machine (EVM): the part of Ethereum that runs smart contracts, small programs stored on the chain. Being "EVM compatible" means programs written for Ethereum can run on Cronos without changes, the way a document written in a common file format opens in many different programs.
  • dApps: short for decentralised applications, programs that live on a blockchain rather than on one company's server.
  • Interoperability: the ability of different chains to pass assets and messages between each other, like two countries agreeing to accept each other's currency.

Ethermint is the technology underneath Cronos. The report describes it as a high-throughput, scalable Proof-of-Stake blockchain that is entirely compatible with Ethereum. Two more terms there:

  • Proof-of-Stake (PoS): a way of deciding who gets to add the next block. Instead of burning electricity (Proof-of-Work), participants lock up coins as a stake; misbehave and you lose the stake. It is a bit like a deposit you put down when renting a flat.
  • Tendermint Core: the consensus engine, the piece of software that gets all the computers on the network to agree on the same order of blocks. Consensus just means agreement.

Ethermint is unusual because it lets ordinary Ethereum software run as a Cosmos application-specific blockchain, a chain built for one purpose. Developers get Ethereum's features and Tendermint's Proof-of-Stake at the same time.

Because Ethermint serves both EVM-based chains and Cosmos-specific chains, its client, the software that talks to the network, has to parse and handle transactions routed for both. The report quotes the Ethermint documentation on how it does this:

"We attempt to achieve this (note by author: transaction routing) by mimicking Geth's Transaction structure and treat it as a unique Cosmos SDK message type. An Ethereum transaction is a single SDK.Msg contained in an auth.StdTx. All relevant Ethereum transaction information is contained in this message. This includes the signature, gas, payload, etc."

In plain words: Ethermint takes an Ethereum-style transaction and wraps it up as a Cosmos-style message, so that the Cosmos machinery can carry it. Geth is the standard Ethereum client; mimicking its transaction structure means the wrapped transaction looks familiar to Ethereum tooling. SDK.Msg is the Cosmos term for a message, and auth.StdTx is the Cosmos envelope that carries one or more messages plus signatures. You can picture auth.StdTx as an envelope and SDK.Msg as the letter inside it.

Background: what a transaction is

Transactions are one of Ethereum's key functions, because they are the only thing that can modify or update the state of the blockchain. State means the current contents of the shared record book: balances, contract storage, everything. Nothing else changes it.

A transaction is a signed message. It is sent by an externally owned account (EOA), which is just an account controlled by a person holding a private key, as opposed to a contract account controlled by code. The message is propagated to every node, every computer keeping a copy of the chain, using a gossip protocol: each node tells its neighbours, they tell theirs, and the message spreads like rumour through a crowd. The report calls this "flood routing".

Only transactions can cause a state change or make a contract execute in the EVM. Every interaction a user has with the blockchain begins with a transaction.

The report lists the fields of an Ethereum transaction:

  • Nonce: an originating EOA-issued sequence number used to prevent message replay. Each transaction from an account gets the next number in sequence, so an old transaction cannot be copied and submitted again, the way a cheque book with numbered cheques makes it hard to reuse a stale cheque.
  • Gas price: how much Ether (in Wei) the originator is prepared to pay for each unit of gas. Wei is the smallest unit of Ether, like pence to a pound.
  • Gas limit: the quantity of gas the originator is prepared to purchase for this transaction. Gas is a unit of computational effort; the limit is a cap on how much work the transaction may do, and therefore on how much it may cost.
  • Recipient: the Ethereum address of the final destination. It may be another EOA or a contract address.
  • Value: the amount of Ether to transmit to the destination (in Wei).
  • Data: variable-length binary data payload. This is where a call to a smart contract and its arguments go.
  • v, r, s: the three components of the original EOA's ECDSA digital signature. ECDSA is the signing scheme Ethereum uses; the three numbers together prove the transaction came from the holder of the private key, without revealing the key.

Background: how Ethermint processes a transaction

When transactions are consumed in Ethermint, they pass through a sequence of handlers. A handler is a piece of code that inspects the transaction and does one job before the transaction is allowed to run. Think of airport security: several checkpoints in a row, each checking something different.

One of these handlers is the AnteHandler. The report describes it as the handler in charge of preliminary message execution business logic such as fee payment and signature verification. "Ante" means before: it runs before the transaction's real work. It applies only to transactions conducted through the Cosmos SDK. Ethereum-routed transactions are handled by the EVM, which performs the same business logic.

So there are two lanes: the Cosmos lane, where the AnteHandler checks fees and signatures, and the Ethereum lane, where the EVM does the equivalent. The bug lives in how a transaction can end up in the wrong lane.

The setup: how a normal Ethereum transaction is submitted

Ethermint offers standard JSON-RPC endpoints for sending an Ethereum transaction. Two terms there:

  • Endpoint: a specific address on a server that accepts a particular kind of request. If a website is a building, an endpoint is a particular counter inside it.
  • JSON-RPC: a simple way for one program to ask another to do something, sending the request as JSON (a text format for structured data) and getting a JSON reply. It is the standard way Ethereum wallets talk to nodes.

When an Ethereum transaction is submitted through the compatibility JSON-RPC endpoint, it is reformatted as a MsgEthereumTx and an ExtensionOptionsEthereumTx is appended to it. MsgEthereumTx is the Cosmos message that wraps an Ethereum transaction; ExtensionOptionsEthereumTx is an optional extra attached to the message that says, in effect, "treat this as an Ethereum transaction and run the Ethereum checks".

When a node processes the transaction, that extension causes it to be processed by the appropriate antehandlers, including the EthGasConsume handler. EthGasConsume deducts gas price * gas limit from the originating account. After the transaction executes, the fee is refunded.

This path needs no Cosmos signature, and it ensures the gas limit in the Ethereum message is subtracted first, as it would be on Ethereum. The subtraction first, refund later pattern is deliberate: it guarantees the sender actually has the money before any work is done, and returns the unused part afterwards, like a hotel holding a deposit at check-in and settling the bill at check-out.

The researcher is credited as zb3. The report does not describe any particular account, tooling or version used to prepare the finding beyond the transaction construction described below.

Finding it: the missing check

What zb3 noticed is that there is no check that a MsgEthereumTx actually carries an ExtensionOptionsEthereumTx. There is no check that a MsgEthereumTx actually carries an ExtensionOptionsEthereumTx. Nothing verified it.

A MsgEthereumTx can therefore be packaged without that extension and submitted to the node directly. Doing so executes only the standard set of antehandlers, because the option that would route the transaction through the Ethereum-specific antehandlers is absent. Several antehandlers that are supposed to run before MsgEthereumTx is handled are skipped as a result.

One of the handlers that is skipped is EthGasConsumeDecorator(evmKeeper). Its primary purpose is to ensure that the Ethereum transaction message has sufficient funds to cover intrinsic gas and that the sender has the funds to cover the gas cost. Intrinsic gas is the quantity of gas consumed by a transaction before it is completed; it is distinct from the Cosmos fee because it is meant to be refunded.

Because the gas cost is never deducted, an arbitrary gas limit can be specified and the transaction can then be "refunded" gas that was never deducted in the first place. The transaction can be "refunded" gas that was never deducted in the first place. In the hotel comparison: you skip check-in, never pay the deposit, and still get the deposit back at check-out.

Exploitation: how the attack was carried out

Step 1: build a cosmos-signed MsgEthereumTx with a valid Ethereum signature

The attacker constructs a MsgEthereumTx carrying a valid Ethereum signature, signs it at the Cosmos level, and deliberately omits ExtensionOptionsEthereumTx. The report gives no concrete payload for this step; the construction is described in prose only.

Why this step: the Ethereum signature makes the message look like a legitimate Ethereum transaction, and the Cosmos signature makes the Cosmos lane accept it. Leaving out the extension is the whole trick, because the extension is what would trigger the fee deduction.

Step 2: set a high GasLimit

Because the EthGasConsumeDecorator will not run, the gas limit is not checked against the sender's balance and is not deducted. The attacker sets it high, and the refund is calculated from that figure.

Why this step: because the gas cost is not deducted, an arbitrary gas limit can be specified and the transaction can then be "refunded" gas that was never deducted.

Step 3: submit the transaction to the node

The transaction is submitted without the extension option. Only the standard antehandlers run, the Ethereum-specific ones are skipped, and the transaction receives a gas refund even though the gas charge was never taken.

Why this step: submitting directly, rather than through the JSON-RPC endpoint that would add the extension, is what keeps the message on the Cosmos lane and out of the Ethereum checks.

Step 4: repeat per block

Before the malicious transaction executes, the transaction fees in the current block might be seized, and the attack can be repeated for every block.

Why this step: a block is a batch of transactions recorded together.

Root cause

There is no check that a MsgEthereumTx carries an ExtensionOptionsEthereumTx. A message submitted without it takes the Cosmos path, skipping the handlers that would have deducted the gas cost. Nothing verifies that the extension is present. A message submitted without it takes the Cosmos path, skipping the handlers that would have deducted the gas cost, while the refund logic still runs. The result is that gas can be "refunded" that was never deducted.

In security terms this is a missing check on whether the extension is present, which changes which code path runs.

Impact

The report classifies the issue as a theft of yield: user rewards were affected, but funds were not drained. It was filed as a high severity report on that basis. An attacker could seize the transaction fees of the current block before the malicious transaction executed, and could repeat the attack for every block. The report does not quantify the amounts at risk.

zb3 submitted the bug to Immunefi on 12 December and received a bounty of $40K from the Cronos team, followed by a swift fix.

Fix

Cronos now checks whether the MsgEthereumTx is contained inside the transaction. The fix was applied to the current Cronos mainnet beta in the binary upgrade of v0.6.5 (see https://github.com/crypto-org-chain/cronos/security/advisories/GHSA-f854-hpxv-cw9r).

In plain words: Cronos now checks whether the MsgEthereumTx is contained inside the transaction.

Variants to test

If you want to look for similar bugs yourself, the technical write-up suggests four directions. Each one is a way of asking the same question: does an optional field change which checks run, and is that change verified?

  1. Submit a MsgEthereumTx without ExtensionOptionsEthereumTx on any Ethermint-based chain and watch the sender balance. A positive result is a refund credited without a matching deduction.
  2. Vary the GasLimit upward on such a message. A positive result is a refund that scales with the limit despite the sender lacking the funds to cover it.
  3. Look for other message types whose antehandler routing depends on an optional extension being present. A positive result is a message that reaches execution while skipping fee or signature checks that its normal entry point would enforce.
  4. Compare the antehandler set executed for the JSON-RPC path against the path taken by a directly submitted message. A positive result is any handler present in one path and absent in the other without an explicit check enforcing it.

Glossary

  • AnteHandler: the Cosmos SDK handler that runs preliminary checks (fee payment, signature verification) before a transaction's real work begins.
  • auth.StdTx: the Cosmos envelope that carries one or more messages and their signatures.
  • Block: a batch of transactions recorded together on a blockchain.
  • Blockchain: a shared record book kept in copies by many computers.
  • Bounty: a payment made to a researcher who reports a security bug.
  • Consensus: agreement among the computers on a network about the order of blocks.
  • Cosmos SDK: a toolkit for building blockchains from ready-made parts.
  • Cronos: a blockchain built on the Cosmos SDK that is compatible with the EVM.
  • dApp: a decentralised application, a program that lives on a blockchain.
  • ECDSA: the signing scheme Ethereum uses to prove a transaction came from the holder of a private key.
  • EOA (externally owned account): an account controlled by a person holding a private key, as opposed to a contract account.
  • Ethermint: the technology underneath Cronos, a Proof-of-Stake blockchain compatible with Ethereum and built on the Cosmos SDK and Tendermint Core.
  • EthGasConsume: the handler that deducts gas price * gas limit from the sender's account.
  • EthGasConsumeDecorator(evmKeeper): the decorator that checks the sender has funds for intrinsic gas and the gas cost.
  • EVM (Ethereum Virtual Machine): the part of Ethereum that runs smart contracts.
  • ExtensionOptionsEthereumTx: an optional extra attached to a MsgEthereumTx that routes it through the Ethereum-specific antehandlers.
  • Fee: the payment a transaction carries to pay for the work of recording it.
  • Gas: a unit of computational effort; the gas limit caps how much a transaction may use.
  • Gas limit: the maximum quantity of gas a transaction is allowed to purchase.
  • Gas price: how much Ether per unit of gas the sender is prepared to pay.
  • Geth: the standard Ethereum client, whose transaction structure Ethermint mimics.
  • Gossip (flood routing): a way of spreading a message by each node telling its neighbours.
  • Handler: a piece of code that inspects a transaction and does one job before it runs.
  • Intrinsic gas: the gas consumed by a transaction before it is completed, meant to be refunded.
  • JSON-RPC: a simple way for one program to ask another to do something, using JSON text.
  • MsgEthereumTx: the Cosmos message that wraps an Ethereum transaction.
  • Nonce: a sequence number on each transaction from an account, used to prevent replay.
  • Proof-of-Stake (PoS): a way of choosing who adds the next block based on locked-up coins rather than electricity.
  • Refund: returning unused or overpaid gas to the sender after a transaction executes.
  • SDK.Msg: the Cosmos term for a message carried inside an envelope.
  • Smart contract: a small program stored and run on a blockchain.
  • State: the current contents of the blockchain record book.
  • Tendermint Core: the consensus engine that gets the network to agree on block order.
  • Theft of yield: a bug class where user rewards are affected but stored funds are not drained.
  • Transaction: a signed message that changes blockchain state and carries a fee.
  • v, r, s: the three components of an ECDSA signature.
  • Wei: the smallest unit of Ether.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.