Bitcoin-RGB Asset Exchange

A Deep Dive into Atomic Swap Mechanics

The exchange process involves two parties — Bob and Alice — who wish to exchange Bitcoin (BTC) for an RGB asset (an asset built on the RGB protocol). The entire process is designed to ensure that both parties fulfill their obligations or the transaction is canceled, preventing any party from losing their assets unfairly.

1. Bob Creates the BTC HTLC

Action: Bob creates an HTLC (Hashed Time-Locked Contract) output that includes both BTC and a deposit. The HTLC locks up Bob’s BTC, with a specified time lock (T2, a longer time lock) to prevent Alice from accessing the funds before a certain time.

Key Concept: The deposit ensures a penalty mechanism for Alice if she does not fulfill her obligations, creating an additional layer of security. The time lock (T2) protects Bob’s funds in case Alice doesn’t meet the requirements.

2. Alice Creates the RGB HTLC

Action: Alice creates an RGB HTLC output, committing to transferring her RGB assets to Bob. This HTLC uses the same hash value as Bob’s BTC HTLC and has a different time lock (T1, a shorter time lock).

Key Concept: The shorter time lock (T1) ensures that Alice can recover her RGB assets if Bob fails to fulfill the contract within the given time frame, thus giving Alice a safeguard.

3. Alice Validates the BTC HTLC

Action: Alice validates Bob’s BTC HTLC, checking the locked BTC amount (including the deposit), the time lock conditions, and the HTLC script.

Key Concept: Alice needs to ensure that Bob’s HTLC is set up correctly and that she will be able to unlock the BTC if the conditions are met (i.e., the preimage of the hash is revealed).

4. Bob Validates the RGB HTLC

Action: Bob validates Alice’s RGB HTLC, reviewing the locked RGB asset amount, the time lock (T1), and the HTLC script.

Key Concept: Bob ensures that Alice’s HTLC is set up properly and that he can unlock the RGB assets if the conditions are met, using the preimage of the hash.

5. Alice Creates the RGB State Transition and Sends Data

Action: Alice constructs a PSBT (Partially Signed Bitcoin Transaction) for the RGB state transition and sends both the PSBT and the Consignment data to Bob. The Consignment contains information about the change in the RGB asset balance, allowing Bob to verify the transfer of ownership.

Key Concept: The Consignment serves as proof of the state change and is crucial for verifying that the RGB asset ownership is properly transferred to Bob.

6. Bob Verifies the RGB State Transition and Confirms the Transaction

Action: Bob verifies Alice’s PSBT and Consignment, confirming that the RGB asset transfer is legitimate and that the deposit mechanism is in place. If everything checks out, Bob provides the preimage to Alice, signaling his agreement to proceed with the transaction.

Key Concept: The preimage is the key to unlocking both the BTC and RGB assets. Bob’s provision of the preimage represents his final confirmation that the transaction should proceed.

7. Completion of the Transaction (Two Possible Paths)

Normal Path:

  • Action: Once Alice receives the preimage from Bob, she broadcasts her RGB state transition and the BTC PSBT to complete the transaction.

Abnormal Path:

  • Action: If Bob attempts to broadcast the RGB state transition before Alice has received the preimage, Alice needs to monitor the blockchain to detect this. If Bob tries to reveal the preimage prematurely, Alice can use the preimage to recover her BTC assets.

Key Concept: The different time locks give Alice the upper hand in the transaction. She can either ensure the transaction completes on time or monitor the blockchain to respond if Bob attempts to break the contract prematurely.

The Philosophy Behind the Bitcoin-RGB Asset Exchange

The Bitcoin-RGB asset exchange system exemplifies the principle of trustless, decentralized financial exchanges, using a combination of hashed time-locked contracts (HTLCs) and the RGB protocol to enforce fairness and security without the need for intermediaries.

Atomicity:

The transaction is atomic, meaning that either both parties exchange assets at the same time, or neither party does. If either side fails to meet the contract’s conditions, the entire transaction fails, and the funds are returned to the respective parties. This prevents any potential for one party to steal assets.

Security via Time Locks and Penalties:

The use of time locks (T1 and T2) ensures that both parties have a fixed period to fulfill their commitments. The penalty deposit adds an additional layer of deterrence against dishonesty or failure to fulfill the terms.

Asset Transfer via the RGB Protocol:

RGB allows for the creation and transfer of off-chain assets on top of Bitcoin, combining the benefits of Bitcoin’s security with the flexibility of smart contract functionality. It provides an efficient way to manage assets and enforce conditions, which are critical in a decentralized exchange.

User Control:

Unlike traditional exchanges, where assets are held by the platform, in this atomic swap system, both Bob and Alice maintain control of their assets at all times. The process is self-executing, ensuring that no third party has access to the funds unless the conditions are met.

Trustlessness and Transparency:

The entire process is transparent and trustless. Both parties can validate the conditions of the contract and the assets involved at every step, making the system highly secure.

The Bitcoin-RGB Asset Exchange system offers a powerful method for trustless asset exchange. By combining Bitcoin’s HTLCs with the RGB protocol, it ensures secure, atomic transactions between parties. The use of time locks, deposits, and state transitions enables a system that minimizes the need for trust while maintaining full control over the assets involved. This approach not only provides a high level of security and fairness but also opens the door to the development of advanced financial systems based on the principles of decentralization.