Author: Lisa Editor: Sherry
Background
On-chain messages, as a special communication method in the blockchain world, have been frequently used in various security incidents in recent years. For example, recently SlowMist assisted KiloEx in multiple rounds of communication with the attacker through on-chain messages, and finally successfully facilitated the return of all stolen funds of US$8.44 million. In an anonymous environment, on-chain messages can be used as an effective tool to establish initial dialogues and lay the foundation for subsequent fund recovery.
In our previously published article "On-chain messages in the first aid guide for theft", we introduced in detail the message method on Ethereum. The Bitcoin network also supports on-chain messages, but the implementation methods of the two are slightly different. The core tool for Bitcoin on-chain messages is the OP_RETURN instruction. It allows users to embed 80 bytes of custom data in transactions. This part of data will not be used by nodes for transaction verification, nor will it affect the status of UTXO. It is purely used to record information and will be fully recorded in the blockchain.
How to use OP_RETURN to leave a message on the chain
Step 1: Encode the message content
First, convert the text information to be sent 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 an online format conversion tool or a Python script to complete it:

The message content must be less than 160 hexadecimal characters, or 80 bytes. If the length exceeds, it is recommended to simplify the information or send it in 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 with an OP_RETURN output.
Take Bitcoin Core as an example, use createrawtransaction to manually add OP_RETURN output:

The transaction constructed in this way will not actually transfer money, but will only write this message on the chain.
Take the imToken wallet as an example, enter the BTC wallet transfer interface, and turn on "Advanced Mode". Enter the hexadecimal information in the "OP_RETURN" input box. Click "Next" to complete the transaction information confirmation. Enter the transaction password to successfully send the transaction with OP_RETURN information. Please make sure that "input amount = output amount + mining fee".

Step 3: Broadcast transaction
Broadcast the signed transaction through the Bitcoin network. Since OP_RETURN transactions do not actually transfer money, they must include mining fees to be processed and wait for miners to pack them into blocks. Once the transaction is confirmed, the message will be permanently saved in the Bitcoin blockchain.
Step 4: View the message content
After completing the transaction, you will get a TXID. You can view the transaction through the block browser. The browser will usually automatically decode the OP_RETURN hexadecimal data back to ASCII, for example:

" style="text-align:center">
(https://mempool.space/address/1CMugHhsSf8Bzrp142BpvUynWBR1RiqMCk)
When this user issued these warnings, he did not just leave a message, but also burned a large number of bitcoins. Due to the characteristics of OP_RETURN output, any bitcoin sent to such transactions will be burned and cannot be used. According to statistics, this user burned more than $300,000 worth of bitcoins in this series of operations.
Summary
On-chain messages, especially OP_RETURN in the Bitcoin network, provide an anonymous, public and tamper-proof communication method, which is widely used in the initial contact and information transmission of fund recovery. However, it should be noted that on-chain messages may also be used by attackers to guide victims to visit malicious links or perform risky operations (such as entering private key decryption, etc.), so be sure to remain vigilant and avoid viewing and processing suspicious information on untrusted devices. When encountering a security incident, it is recommended to contact a professional security team as soon as possible to assist in analysis and improve the success rate of fund recovery. At the same time, users and project parties should continue to strengthen their awareness of security protection to avoid becoming targets of attack.