Freeze The Bridge Via Large ERC20 Names/Symbols/Denoms
The Ethereum oracle in the Gravity bridge fetches logs with a fixed 10 MB response limit. An attacker can deploy an ERC20 with a very large name, symbol, or denom, causing the log response to exceed the limit and the oracle to fail permanently, freezing the bridge.
Submitted by nascent
Ethereum Oracles watch for events on the Gravity.sol contract on the Ethereum blockchain. This is performed in the check_for_events function, and run in the eth_oracle_main_loop.
In this function, there is the following code snippet:
let erc20_deployed = web3
.check_for_events(
starting_block.clone(),
Some(latest_block.clone()),
vec![gravity_contract_address],
vec![ERC20_DEPLOYED_EVENT_SIG],
)
.await;
This snippet leverages the web30 library to check for events from the starting_block to the latest_block. Inside the web30 library this nets out to calling:
pub async fn eth_get_logs(&self, new_filter: NewFilter) -> Result<Vec<Log>, Web3Error> {
self.jsonrpc_client
.request_method(
"eth_getLogs",
vec![new_filter],
self.timeout,
Some(10_000_000),
)
.await
}
The 10_000_000 specifies the maximum size of the return in bytes and returns an error if the return is larger:
let res: Response<R> = match res.json().limit(limit).await {
Ok(val) => val,
Err(e) => return Err(Web3Error::BadResponse(format!("Web3 Error {}", e))),
};
This can be triggered at will and keep the loop in a perpetual state of returning the GravityError::EthereumRestError(Web3Error::BadResponse( "Failed to get logs!".to_string())) error. To force the node into this state, you just have to deploy ERC20s generated by the public function in Gravity.sol:
function deployERC20(
string memory _cosmosDenom,
string memory _name,
string memory _symbol,
uint8 _decimals
) public {
// Deploy an ERC20 with entire supply granted to Gravity.sol
CosmosERC20 erc20 = new CosmosERC20(address(this), _name, _symbol, _decimals);
// Fire an event to let the Cosmos module know
state_lastEventNonce = state_lastEventNonce.add(1);
emit ERC20DeployedEvent(
_cosmosDenom,
address(erc20),
_name,
_symbol,
_decimals,
state_lastEventNonce
);
}
And specify a large string as the denom, name, or symbol.
If an attacker uses the denom as the attack vector, they save significant gas costing just 256 per additional 32 bytes. For other cases, to avoid gas overhead, you can have the string be mostly 0s resulting in just 584 gas per additional 32 bytes. This leaves it feasible to surpass the 10mb response data in the 6 block buffer. This would throw every ethereum oracle into a state of perpetual errors and all would fall out of sync with the ethereum blockchain. This would result in the batches, logic calls, deposits, ERC20 creations, and valset updates to never receive attestations from other validators because their ethereum oracles would be down; the bridge would be frozen and remain frozen until the bug is fixed due to get_last_checked_block.
This will freeze the bridge by disallowing attestations to take place.
This requires a patch to reenable the bridge.
Recommendation
Handle the error more concretely and check if you got a byte limit error. If you did, chunk the search size into 2 and try again. Repeat as necessary, and combine the results.
Additionally, you could require that validators sign ERC20 creation requests.
Excellent bug report.
I just ran into the buffer limit issue this morning with an Ethereum block. I agree handling this error correctly is essential to long term reliability.
Nice :)
Context
Gravity Bridge connects an Ethereum chain to a Cosmos chain. On the Ethereum side, a Solidity contract called Gravity.sol emits events for everything the Cosmos side needs to know about: token deployments, deposits, logic calls, validator set updates and batch transfers. On the Cosmos side, each validator runs an orchestrator process whose Ethereum oracle watches those events and turns them into attestations that the rest of the validator set can act on.
The oracle's watch loop is eth_oracle_main_loop, and the actual event querying happens in check_for_events in ethereum_event_watcher.rs. The feature normally works like this: on each pass, the oracle asks the Ethereum node for all logs emitted by the Gravity contract between the last block it checked and the latest block, then processes them. If that query fails, the oracle cannot attest to anything that happened in the covered range.
Setup
No special accounts, roles or tooling are needed beyond what any user of the bridge already has. The attack relies on a public function on Gravity.sol that anyone can call, and on the oracle's own event-fetching code. The relevant code lives in the cosmos-gravity-bridge repository at commit [redacted], in the orchestrator crate and the Solidity contracts.
Finding it
The researcher looked at how the oracle fetches events. In check_for_events, the code calls check_for_events on the web3 object for the range from starting_block to latest_block, filtered to the Gravity contract address and the ERC20_DEPLOYED_EVENT_SIG event signature:
let erc20_deployed = web3
.check_for_events(
starting_block.clone(),
Some(latest_block.clone()),
vec![gravity_contract_address],
vec![ERC20_DEPLOYED_EVENT_SIG],
)
.await;
That call goes through the web30 library, which ends up in eth_get_logs:
pub async fn eth_get_logs(&self, new_filter: NewFilter) -> Result<Vec<Log>, Web3Error> {
self.jsonrpc_client
.request_method(
"eth_getLogs",
vec![new_filter],
self.timeout,
Some(10_000_000),
)
.await
}
The 10_000_000 argument is the maximum size of the response in bytes. If the response is larger, the library returns an error rather than the logs:
let res: Response<R> = match res.json().limit(limit).await {
Ok(val) => val,
Err(e) => return Err(Web3Error::BadResponse(format!("Web3 Error {}", e))),
};
So the size of the JSON-RPC response, not the number of events, decides whether the oracle can read the chain at all.
Exploitation
Step 1: call the public deploy function with oversized strings
Gravity.sol exposes deployERC20 as a public function. It takes a Cosmos denom, a name, a symbol and a decimals value, deploys a CosmosERC20 with the entire supply granted to Gravity.sol, increments state_lastEventNonce, and emits ERC20DeployedEvent containing all of those strings:
function deployERC20(
string memory _cosmosDenom,
string memory _name,
string memory _symbol,
uint8 _decimals
) public {
// Deploy an ERC20 with entire supply granted to Gravity.sol
CosmosERC20 erc20 = new CosmosERC20(address(this), _name, _symbol, _decimals);
// Fire an event to let the Cosmos module know
state_lastEventNonce = state_lastEventNonce.add(1);
emit ERC20DeployedEvent(
_cosmosDenom,
address(erc20),
_name,
_symbol,
_decimals,
state_lastEventNonce
);
}
The attacker supplies a very large string as the denom, the name or the symbol. Because the event is emitted with those strings inside it, the log entry itself becomes large, and the JSON-RPC response that returns it grows with it.
Step 2: keep the response above the limit inside the oracle's window
The oracle queries a block range, so the oversized event has to sit inside the range the oracle is currently scanning. The researcher notes that the 6 block buffer leaves enough room to push the response past 10 MB. The cost of doing so is low: using the denom as the vector costs just 256 gas per additional 32 bytes, and for the other fields a string that is mostly zero bytes costs just 584 gas per additional 32 bytes. That makes it feasible to exceed the 10 MB response size within the buffer.
Step 3: the oracle errors and stays errored
Once the response exceeds the limit, eth_get_logs returns the Web3Error::BadResponse error, and the oracle surfaces it as GravityError::EthereumRestError(Web3Error::BadResponse("Failed to get logs!".to_string())). The researcher states this can be triggered at will and keeps the loop in a perpetual state of returning that error. Every Ethereum oracle that scans the affected range fails the same way and falls out of sync with the Ethereum chain.
Root cause
The oracle treats a response-size failure as a generic bad response and does not distinguish it from other errors. There is no chunking of the block range and no retry with a smaller window, so a single oversized log makes the whole query fail. The event data that determines the response size is fully attacker-controlled through a public function, and the oracle has no way to skip or bound it. Nothing in the oracle handles the byte-limit error specially.
Impact
With every Ethereum oracle stuck in the error state, no attestations are produced for batches, logic calls, deposits, ERC20 creations or valset updates. The bridge is frozen, and it stays frozen until the bug is fixed, because of get_last_checked_block: the oracle cannot move its last-checked block past the offending range. The researcher states that this requires a patch to re-enable the bridge.
Fix
The recommendation is to handle the error more concretely: detect the byte-limit error, split the search range in two, retry, and repeat as necessary, combining the results. As an additional measure, validators could be required to sign ERC20 creation requests.
Althea's jkilpatr confirmed the report and noted having run into the buffer limit issue that morning with an Ethereum block, agreeing that handling the error correctly is essential to long term reliability. The judge, albertchon, commented "Nice :)".
Variants to test
- Other event fields. Any event whose payload includes a user-supplied string can inflate a log response. Try long memo fields, arbitrary call data and similar strings, and look for a response that grows with the input.
- Other range-based queries. Look for any oracle or indexer that fetches logs over a block range with a fixed response cap. A positive result is a query that fails once a single oversized log falls inside the range.
- Gas cost of the vector. Compare the cost of padding the denom versus padding the name or symbol with mostly zero bytes, and check whether the cheaper vector is enough to cross the cap within the buffer.
- Recovery behaviour. After triggering the error, check whether the component advances its last-checked block. If it does not, the failure is persistent rather than transient.
Hunting notes
This class of bug hides in the boundary between an on-chain contract that emits attacker-controlled data and an off-chain consumer that fetches it with a size or count limit. During recon, look for public functions that write arbitrary strings into events, and for oracle or relayer code that calls eth_getLogs (or an equivalent) over a block range with a fixed response cap. The signal is a fetch path where a single log can dominate the response size and where the error path does not chunk or retry. The researcher tied the error to the attestation flow: without logs, no attestations, and without attestations the bridge cannot progress.
What happened, in plain words
Gravity Bridge is a piece of software that lets two separate blockchains talk to each other: an Ethereum chain and a Cosmos chain. Think of it as a translator sitting between two people who speak different languages. Each side keeps its own record of what has happened, and the bridge carries messages from one record to the other.
On the Ethereum side there is a smart contract (a program that lives on the blockchain) called Gravity.sol. Whenever something important happens, this contract announces it publicly by writing a note into its log. These notes are called events. On the Cosmos side, every validator (a computer that helps run the Cosmos chain) runs a helper program called an orchestrator. Inside the orchestrator there is a component called the Ethereum oracle. Its job is simple to describe: read the notes that Gravity.sol has written, and tell the rest of the Cosmos network what they say. Those reports are called attestations.
The bug is that the oracle's event query has a cap on the size of the response. Anyone can make one note enormous by calling a public function on Gravity.sol and passing in a very long piece of text. When the note becomes too big, the oracle's request fails, and it keeps failing on every retry because it always asks for the same range of blocks. With every oracle stuck, no attestations are produced, and the bridge stops working. It stays stopped until the code is patched.
Background you need first
A few ideas come up again and again in this report, so here they are from zero.
Blockchain and blocks. A blockchain is a list of records that many computers keep copies of. New records are added in groups called blocks, and each block has a number. Block 100 comes after block 99. Because blocks are numbered, you can ask a node (a computer that holds a copy of the chain) for everything that happened between block 100 and block 200.
Smart contract. A program stored on the blockchain that anyone can call. Gravity.sol is one, written in a language called Solidity.
Event and log. When a smart contract does something worth announcing, it can emit an event. The blockchain stores that announcement in a log. Other software can later ask a node: "give me all the logs from this contract between these two blocks". That is exactly what the oracle does.
JSON-RPC and eth_getLogs. A node exposes a way for other programs to talk to it, called JSON-RPC. It is a bit like a restaurant menu: you name a dish (a method) and hand over the ingredients (parameters), and you get a result back. eth_getLogs is the dish the oracle orders: "all logs matching this filter".
API. An API is the agreed way one program asks another program to do something. JSON-RPC is the API here.
Gas. Running code on Ethereum costs a fee measured in gas. Longer text costs more gas, but as this report shows, the amounts involved can still be small.
Attestation. A signed statement from a validator saying "I saw this happen on Ethereum". The Cosmos side acts on events only once enough validators have attested to them.
Denom, name, symbol, decimals. When a token is created, it needs a few labels. The denom is its identifier on the Cosmos side, the name is its human-readable name, the symbol is the short ticker, and decimals says how divisible it is.
Byte limit. A cap on how much data a program will accept in one response. If the answer is bigger than the cap, the program refuses it rather than reading it.
The setup
The researcher did not need any special account, role or tool. The attack uses a function on Gravity.sol that is open to anyone, plus the oracle's own code for fetching events. The code discussed lives in the cosmos-gravity-bridge repository at commit [redacted], in the orchestrator component and the Solidity contracts.
Finding it
The researcher started by reading how the oracle fetches events. The watch loop is called eth_oracle_main_loop, and the actual querying happens in a function called check_for_events in the file ethereum_event_watcher.rs. On each pass, the oracle asks the Ethereum node for all logs from the Gravity contract between the last block it checked and the newest block, then processes them.
In that function, the code calls check_for_events on a web3 object, asking for the range from starting_block to latest_block, filtered to the Gravity contract address and to one particular event signature, ERC20_DEPLOYED_EVENT_SIG:
let erc20_deployed = web3
.check_for_events(
starting_block.clone(),
Some(latest_block.clone()),
vec![gravity_contract_address],
vec![ERC20_DEPLOYED_EVENT_SIG],
)
.await;
Line by line: let erc20_deployed = stores the result in a variable named erc20_deployed. web3 is the object that talks to the Ethereum node. .check_for_events( starts the request. starting_block.clone() is the first block to look at, and .clone() makes a copy so the original value is not used up. Some(latest_block.clone()) is the last block to look at, wrapped in Some because the value is optional. vec![gravity_contract_address] is a list containing the one contract address to watch. vec![ERC20_DEPLOYED_EVENT_SIG] is a list containing the one event type to watch. .await means "wait here until the answer comes back".
That call goes through a library called web30, which ends up in a function called eth_get_logs:
pub async fn eth_get_logs(&self, new_filter: NewFilter) -> Result<Vec<Log>, Web3Error> {
self.jsonrpc_client
.request_method(
"eth_getLogs",
vec![new_filter],
self.timeout,
Some(10_000_000),
)
.await
}
Line by line: pub async fn eth_get_logs declares a function that can be called from elsewhere and that waits on network work. It takes &self (the object it belongs to) and new_filter: NewFilter (the filter describing which logs to fetch). It returns either a list of logs or an error. Inside, self.jsonrpc_client.request_method( sends a request to the node. "eth_getLogs" is the method name. vec![new_filter] passes the filter as the argument list. self.timeout is how long to wait. Some(10_000_000) is the important one: the maximum size of the response in bytes. .await waits for the reply.
So the 10_000_000 is a cap of ten million bytes, roughly ten megabytes. If the response is larger, the library returns an error instead of the logs:
let res: Response<R> = match res.json().limit(limit).await {
Ok(val) => val,
Err(e) => return Err(Web3Error::BadResponse(format!("Web3 Error {}", e))),
};
Line by line: let res: Response<R> = prepares a variable to hold the parsed response. match res.json().limit(limit).await { tries to read the response as JSON while enforcing the size limit, and waits for the result. Ok(val) => val, means: if it worked, keep the value. Err(e) => return Err(Web3Error::BadResponse(format!("Web3 Error {}", e))), means: if it failed, stop and return a "bad response" error carrying the underlying message.
The consequence is that the size of the response, not the number of events, decides whether the oracle can read the chain at all.
Exploitation
Step 1: call the public deploy function with oversized strings
Gravity.sol exposes a function called deployERC20 that anyone can call. It takes a Cosmos denom, a name, a symbol and a decimals value, creates a new token contract with the entire supply granted to Gravity.sol, increments a counter called state_lastEventNonce, and emits an ERC20DeployedEvent containing all of those strings:
function deployERC20(
string memory _cosmosDenom,
string memory _name,
string memory _symbol,
uint8 _decimals
) public {
// Deploy an ERC20 with entire supply granted to Gravity.sol
CosmosERC20 erc20 = new CosmosERC20(address(this), _name, _symbol, _decimals);
// Fire an event to let the Cosmos module know
state_lastEventNonce = state_lastEventNonce.add(1);
emit ERC20DeployedEvent(
_cosmosDenom,
address(erc20),
_name,
_symbol,
_decimals,
state_lastEventNonce
);
}
Line by line: function deployERC20( starts the function. string memory _cosmosDenom, takes the denom as text held in temporary memory. string memory _name, takes the name. string memory _symbol, takes the symbol. uint8 _decimals takes the decimals as a small number. ) public { makes the function callable by anyone. CosmosERC20 erc20 = new CosmosERC20(address(this), _name, _symbol, _decimals); creates the new token, owned by the Gravity contract itself. state_lastEventNonce = state_lastEventNonce.add(1); bumps the event counter by one. emit ERC20DeployedEvent( writes the announcement into the log, passing the denom, the new token's address, the name, the symbol, the decimals and the counter. The closing braces end the call and the function.
The attacker supplies a very large string as the denom, the name or the symbol. Because the event is emitted with those strings inside it, the log entry itself becomes large, and the response that returns it grows with it.
Step 2: keep the response above the limit inside the oracle's window
The oracle asks for a range of blocks, so the oversized event has to sit inside the range the oracle is currently scanning. The researcher notes that a 6 block buffer leaves enough room to push the response past 10 MB. The cost is low: using the denom as the vector costs just 256 gas per additional 32 bytes, and for the other fields a string that is mostly zero bytes costs just 584 gas per additional 32 bytes. That makes it feasible to exceed the 10 MB response size within the buffer.
Step 3: the oracle errors and stays errored
Once the response exceeds the limit, eth_get_logs returns the Web3Error::BadResponse error, and the oracle surfaces it as GravityError::EthereumRestError(Web3Error::BadResponse("Failed to get logs!".to_string())). The researcher states this can be triggered at will and keeps the loop in a perpetual state of returning that error. Every Ethereum oracle that scans the affected range fails the same way and falls out of sync with the Ethereum chain.
Root cause
The oracle treats a response-size failure as a generic bad response and does not distinguish it from other errors. There is no splitting of the block range and no retry with a smaller window, so a single oversized log makes the whole query fail. The event data that determines the response size is attacker-controlled through a public function. Nothing limits the length of the denom, name or symbol strings, and nothing in the oracle handles the byte-limit error specially.
Impact
With every Ethereum oracle stuck in the error state, no attestations are produced for batches, logic calls, deposits, ERC20 creations or valset updates. The bridge is frozen, and it stays frozen until the bug is fixed, because of get_last_checked_block: the oracle cannot move its last-checked block past the offending range. The researcher states that this requires a patch to re-enable the bridge.
Fix
The recommendation is to handle the error more concretely: detect the byte-limit error, split the search range in two, retry, and repeat as necessary, combining the results. As an additional measure, validators could be required to sign ERC20 creation requests.
Althea's jkilpatr confirmed the report and noted having run into the buffer limit issue that morning with an Ethereum block, agreeing that handling the error correctly is essential to long term reliability. The judge, albertchon, commented "Nice :)".
Variants to test
- Other event fields. Any event whose payload includes a user-supplied string can inflate a log response. Try long memo fields, arbitrary call data and similar strings, and look for a response that grows with the input.
- Other range-based queries. Look for any oracle or indexer that fetches logs over a block range with a fixed response cap. A positive result is a query that fails once a single oversized log falls inside the range.
- Gas cost of the vector. Compare the cost of padding the denom versus padding the name or symbol with mostly zero bytes, and check whether the cheaper vector is enough to cross the cap within the buffer.
- Recovery behaviour. After triggering the error, check whether the component advances its last-checked block. If it does not, the failure is persistent rather than transient.
Hunting notes
This class of bug hides in the boundary between an on-chain contract that emits attacker-controlled data and an off-chain consumer that fetches it with a size or count limit. During recon, look for public functions that write arbitrary strings into events, and for oracle or relayer code that calls eth_getLogs (or an equivalent) over a block range with a fixed response cap. The signal is a fetch path where a single log can dominate the response size and where the error path does not split the range or retry. The researcher tied the error to the attestation flow: without logs, no attestations, and without attestations the bridge cannot progress.
Glossary
- API: the agreed way one program asks another program to do something.
- Attestation: a signed statement from a validator that it observed a particular event on the other chain.
- Block: a numbered group of records added to a blockchain.
- Blockchain: a list of records kept in copies by many computers.
- Byte: a unit of data size; roughly one character of text.
- Cosmos: the blockchain network on one side of the bridge.
- Decimals: how divisible a token is.
- Denom: a token's identifier on the Cosmos side.
- ERC20: the standard format for tokens on Ethereum.
- Error: a signal that an operation did not succeed.
- Ethereum: the blockchain network on the other side of the bridge.
- Event: an announcement a smart contract writes into its log.
- Event signature: the identifier that says which type of event to look for.
- Gas: the fee unit for running code on Ethereum.
- JSON-RPC: the request format Ethereum nodes use to talk to other programs.
- Log: the stored record of an event on the blockchain.
- Node: a computer that holds a copy of a blockchain and answers queries about it.
- Oracle: the component that reads one chain and reports what it saw to the other.
- Orchestrator: the helper program each validator runs to operate the bridge.
- Response: the data a program sends back after a request.
- Smart contract: a program stored on a blockchain that anyone can call.
- Solidity: the language smart contracts on Ethereum are written in.
- Symbol: a token's short ticker.
- Validator: a computer that helps run a blockchain and signs statements about it.
- Valset: the set of validators recognised by the bridge at a given time.