Author: Lisa

Edited by: Sherry

Background

On-chain messages, as a special means of communication in the blockchain world, have been frequently used in various security incidents in recent years. For example, recently, SlowMist assisted KiloEx in engaging in multiple rounds of communication with attackers through on-chain messages, ultimately successfully facilitating the return of all stolen funds amounting to $8.44 million. In an anonymous environment, on-chain messages can serve as an effective tool for establishing preliminary dialogue, laying the foundation for subsequent fund recovery.

In our previous article (On-chain Messaging in the Theft Emergency Guide), we detailed the messaging method on Ethereum. The Bitcoin network also supports on-chain messaging, but the implementation methods are slightly different. The core tool for on-chain messaging in Bitcoin is the OP_RETURN instruction. It allows users to embed 80 bytes of custom data in the transaction, which will not be used by nodes for transaction validation and will not affect the status of UTXOs, purely for recording information, and will be fully recorded on the blockchain.

How to Use OP_RETURN for On-chain Messaging

Step 1: Encode the Message Content

First, convert the text message you want to send into hexadecimal (HEX) format. The OP_RETURN instruction on the Bitcoin chain only accepts HEX format data.

For example, if you want to leave a message:

This is a test.

The converted HEX is:

54686973206973206120746573742e

You can use online format conversion tools or complete it through Python scripts:

The message content must be less than 160 hexadecimal characters, or 80 bytes. If it exceeds this length, it is recommended to simplify the message or send multiple messages.

Step 2: Construct a Transaction with OP_RETURN

Next, you need to use a Bitcoin wallet or tool that supports custom transactions to create a transaction containing OP_RETURN output.

Taking Bitcoin Core as an example, use createrawtransaction to manually add OP_RETURN output:

bitcoin-cli createrawtransaction '[{"txid":"your_input_txid","vout":0}]' '[{"data":"54686973206973206120746573742e"}]'

The transaction constructed in this way will not actually transfer funds, but will only write this message on the chain.

Taking the imToken wallet as an example, enter the BTC wallet transfer interface and open 'Advanced Mode'. In the 'OP_RETURN' input box, enter the hexadecimal information. Click 'Next' to complete the transaction information confirmation, enter the transaction password to successfully send the transaction containing OP_RETURN information. Please ensure 'Input Amount = Output Amount + Miner Fee'.

Step 3: Broadcast Transaction

Broadcast the signed transaction through the Bitcoin network. Since OP_RETURN transactions do not actually transfer funds, a miner fee must be included for processing, waiting for the miner to package it into a block. Once the transaction is confirmed, the message will be permanently stored in the Bitcoin blockchain.

Step 4: View the Message Content

After completing the transaction, you will receive a TXID, which can be viewed through a block explorer. The explorer usually automatically decodes the OP_RETURN hexadecimal data back to ASCII, for example:

(https://mempool.space/tx/f4ac7abcb689df30ec5e8d829733622f389ca91367c47b319bc582e653cd8cab)

OP_RETURN Applications

In security incidents, some attackers leave messages on-chain using OP_RETURN, actively expressing their intention to return funds to the project party, or the project party and white hat teams also use this method to reach out to attackers, trying to establish contact. Besides being used in negotiation scenarios, OP_RETURN is also used for 'marking' operations. For instance, Chainalysis revealed that on the eve of the outbreak of the Russia-Ukraine war in 2022, an unidentified Bitcoin user used OP_RETURN on-chain messages to mark nearly 1,000 addresses suspected of being associated with the Russian security services. These messages were written in Russian, directly indicating that these addresses might be involved in cyber attacks or espionage activities:

  • "GRU to SVR. Used for hacking!"

  • "GRU to GRU. Used for hacking!"

  • "GRU to FSB. Used for hacking!"

  • "Help Ukraine with money from the GRU Khakir"

(https://mempool.space/address/1CMugHhsSf8Bzrp142BpvUynWBR1RiqMCk)

This user did not simply leave a message when posting these warnings, but also burned a large amount of Bitcoin. Due to the nature of OP_RETURN outputs, any Bitcoin sent to such transactions will be burned and cannot be used. It is estimated that this user burned Bitcoin worth over $300,000 in this series of operations.

Summary

On-chain messages, especially the OP_RETURN in the Bitcoin network, provide an anonymous, public, and tamper-proof means of communication, widely used during the early stages of fund recovery for contact and information transmission. However, it is important to note that on-chain messages can also be used by attackers to guide victims to malicious links or execute risky operations (such as entering private keys for decryption), so it is essential to remain vigilant and avoid viewing and processing suspicious information on untrusted devices. In the event of a security incident, it is recommended to contact a professional security team for assistance in analysis, improving the success rate of fund recovery. At the same time, users and project parties should continuously enhance their security awareness to avoid becoming targets of attacks.