A regular Cosmos SDK message can be disguised as an EVM transaction, causing ListenFinalizeBlock to error which prevents the block from being indexed
A Cosmos SDK message that is not an EVM message can be signed in Ethereum signing mode so the indexer treats it as an EVM transaction, then fails to unpack its response type. This makes the block finalisation listener return an error, so the whole block and its transactions are never indexed and cannot be queried over JSON-RPC.
The indexer’s ListenFinalizeBlock() is called whenever a block is finalized from within BaseApp::FinalizeBlock() and processes the block, including the transactions.
86: // extract logs and contract address from tx results
87: ethLogs, contractAddr, err := extractLogsAndContractAddr(txStatus, txResult.Data, ethTx.To() == nil)
88: if err != nil {
89: e.logger.Error("failed to extract logs and contract address", "err", err)
90: return err
91: }
extractLogsAndContractAddr() then tries to unpack the transaction data into either MsgCreateResponse in line 28 or MsgCallResponse in line 37 by calling unpackData().
If the message’s type URL is not matching the expected types from the MsgCreateResponse or MsgCallResponse, it returns an error in line 61.
47: // unpackData extracts msg response from the data
48: func unpackData(data []byte, resp proto.Message) error {
49: var txMsgData sdk.TxMsgData
50: if err := proto.Unmarshal(data, &txMsgData); err != nil {
51: return err
52: }
53:
54: if len(txMsgData.MsgResponses) == 0 {
55: return sdkerrors.ErrLogic.Wrap("failed to unpack data; got nil Msg response")
56: }
57:
58: msgResp := txMsgData.MsgResponses[0]
59: expectedTypeUrl := sdk.MsgTypeURL(resp)
60: if msgResp.TypeUrl != expectedTypeUrl {
61: return fmt.Errorf("unexpected type URL; got: %s, expected: %s", msgResp.TypeUrl, expectedTypeUrl)
62: }
63:
64: // Unpack the response
65: if err := proto.Unmarshal(msgResp.Value, resp); err != nil {
66: return err
67: }
68:
69: return nil
70: }
In this case, the error will be propagated up to the ListenFinalizeBlock function in line 87, which will then exit the loop and stops processing the block. Consequently, the block and its transactions is not indexed and thus not available when querying via the JSON-RPC. Additionally, pruning is also not run and the bloom filter is not created.
Now the question is how this can be exploited?
The goal is to disguise a Cosmos SDK message, that is not a MsgCall or MsgCreate, so that extractLogsAndContractAddr() and more specifically, unpackData() errors due to the mismatch of the type URL, as an EVM transaction.
This can be done by using any Cosmos SDK message and signing it as if it were a EVM message (MsgCreate, MsgCall), by using SignMode_SIGN_MODE_ETHEREUM.
As a result, ConvertCosmosTxToEthereumTx() will consider this transaction to be an EVM transaction, bypassing the check in txutils.go#L250-L253.
Subsequently, it will also bypass the switch/case in txutils.go#L286-L321, as the type URL does not match any of the expected types (e.g., /minievm.evm.v1.MsgCall). The results is a valid EVM transaction, with the notable difference that txData.To = nil and txData.Data = nil.
The transaction will be successfully executed, but when processing it in ListenFinalizeBlock, it will error out due to the mismatch of the type URL in unpackData(), as it was expecting types.MsgCreateResponse.
Proof of Concept
The test case Test_ListenFinalizeBlock_Audit_Errors demonstrates how an ETH transaction can be wrapped with a bank MultiSend message, so that ListenFinalizeBlock errors, preventing the block from being indexed.
Please note that CustomConvertEthereumTxToCosmosTx is a copy of the original function. It only differs by adding the MultiSend Cosmos message instead of MsgCreate or MsgCall. It makes the PoC simpler. But it would also be possible to build such an transaction without CustomConvertEthereumTxToCosmosTx, using just the Cosmos tx builder.
Also, the MultiSend message handler was changed to not error. Again, also for simplicity. Any other Cosmos SDK message (e.g. Send) would work as well.
I think it should be sufficient to fix this issue by adding a default case to the switch statement in ConvertCosmosTxToEthereumTx(), which returns nil, nil, nil so that such a transaction is not considered an EVM transaction.
If you change the message and keep the signature, then your tx cannot be entered to mempool because signature verification failed in ante level.
There’s a misunderstanding. The PoC does not change/replace the message. It simply uses MsgMultiSend instead of e.g. MsgCall. The signature remains valid. It’s the same logic that ConvertCosmosTxToEthereumTx uses.
I noticed that the git diff contained an error so that it was not possible to git apply it. I’ve fixed it below. Also, I’ve added fmt.Println statements to the signature verification to show that the signature is indeed valid.
Please run the PoC to convince yourself of this issue. If you need further help of if something is unclear, please let me know. Happy to help!
Still, I don’t think this is possible at all. The problem you are saying is the second tx will return error when we call ConvertCosmosTxToEthereumTx function here.
This tx cannot enter this indexer code due to ante handler is already filter this type of transactions; see here. We are using skip-mev’s block-sdk which is ensuring to create a block only with the txs those are valid in the ante handler.
I’m saying that extractLogsAndContractAddr errors. It will not be filtered in the ante handler. Please run the PoC to get a better feeling for the issue.
The original report as published on Code4rena, by berndartmueller. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the conversion from Cosmos to Ethereum transactions has no default case for unrecognised message types, so a non-EVM message signed in Ethereum mode is still treated as an EVM transaction and later fails the response type check in the indexer.
Impact
A single crafted transaction causes the block to be skipped by the indexer, so its transactions are unavailable over JSON-RPC and pruning and bloom filter creation do not run for that block.
What the attacker needed
Ability to submit a transaction; transaction signed in Ethereum mode
The fix
A default case should be added to the switch in the conversion function so that unrecognised message types are not treated as EVM transactions.
How it was found
Create a normal transaction from a victim account.
Build an Ethereum-style transaction whose Cosmos message is a bank MultiSend rather than MsgCall or MsgCreate.
Submit both transactions and confirm both execute successfully.
Query the indexer for both transaction hashes and observe neither is found.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A blockchain node runs a background job that reads each finished block and stores its transactions in a searchable database. The job assumed every transaction signed in the Ethereum style was an Ethereum transaction, but an attacker can sign an ordinary Cosmos transaction that way instead. The job then hits an unexpected value, gives up on the whole block, and nothing from that block can be looked up afterwards.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.