Submitted by berndartmueller
https://github.com/initia-labs/minievm/blob/744563dc6a642f054b4543db008df22664e4c125/x/evm/keeper/txutils.go#L321
The indexers ListenFinalizeBlock() is called whenever a block is finalized from within BaseApp::FinalizeBlock() and processes the block, including the transactions.
https://github.com/cosmos/cosmos-sdk/blob/eb1a8e88a4ddf77bc2fe235fc07c57016b7386f0/baseapp/abci.go#L856-L864
During looping the transactions, it extracts the logs and the contract address from the transaction result:
indexer/abci.go#L86-L91
extractLogsAndContractAddr() then tries to unpack the transaction data into either MsgCreateResponse in line 28 or MsgCallResponse in line 37 by calling unpackData().
If the messages type URL is not matching the expected types from the MsgCreateResponse or MsgCallResponse, it returns an error in line 61.
indexer/utils.go#L47-L70
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.
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.
beer-1 (Initia) disputed and commented:
berndartmueller (warden) commented:
LSDan (judge) commented:
beer-1 (Initia) commented:
berndartmueller (warden) commented:
Initia mitigated:
Status: Mitigation confirmed. Full details in reports from berndartmueller, Franfran and 0xAlix2.
