Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

Background

ERC-7573 proposes an interface for secure token transfers across two different blockchains.

This article explains and expands on the proposal below.

I also cover other Ethereum Improvement Proposals.

Overview

The standard proposes an interface for a transaction scheme that performs secure delivery versus payment (DvP) across two chains. In DvP, delivery of the asset depends on payment. This design uses a stateless decryption oracle attached to one chain and avoids an intermediary that coordinates the trade across both chains.

Decryption oracle

A decryption oracle lets a contract arrange for encrypted data to be decrypted at the appropriate point in the transaction without relying on a separate trade coordinator.

The oracle holds the private key needed to decrypt the ciphertext. The contract requests decryption at the appropriate time and receives the result. The oracle's private key stays with the oracle.

Communication between the contract and the oracle must protect the reliability and security of the result. A stateless oracle can process multiple requests and supply the corresponding plaintext for each without maintaining the trade's state. Correct decryption is still a dependency of the exchange.

The scheme puts a contract on each blockchain. The asset chain contract implements ILockingContract, and the payment chain contract implements IDecryptionContract.

  • ILockingContract

    • This contract on the asset chain locks tokens until an appropriate key is presented.
    • The parties supply two encrypted values, corresponding to the keys for claiming or reclaiming the asset.
  • IDecryptionContract

    • This contract on the payment chain uses the oracle to decrypt one of the two keys depending on whether the token transfer, such as a payment, succeeds or fails.
    • The stateless decryption oracle connects to the chain that runs IDecryptionContract and performs the decryption.

How the exchange works

  • Lock the asset
    • ILockingContract on the asset chain locks the asset until a valid key is presented.
  • Determine the payment result
    • IDecryptionContract on the payment chain requests decryption of one key on success and the other on failure.
  • Present the released key
    • A party presents the key released for the payment outcome to ILockingContract. The key determines who can unlock the asset.

This scheme links the exchange across the two blockchains without requiring a third party to coordinate both sides of the trade.

Motivation

Hash-Link Contracts (HLCs) have drawn attention in finance and distributed ledger technology (DLT). They can help solve delivery versus payment when the asset chain and the payment system are separate.

Limitations of existing approaches

Many proposed solutions face two issues.

  • API-based interaction
    • An API lets the asset chain and payment system communicate, but adds overhead.
  • Complex timelocks
    • Some protocols rely on timelocks for transaction safety. These mechanisms can be difficult to design and operate.

Proposed protocol

The proposed protocol aims to achieve secure DvP with less overhead. Using a stateless oracle reduces the complexity of the decryption component.

  • Stateless oracle
    • The oracle can handle multiple requests and decrypt the corresponding key for each.
    • This enables the parties to pass the key released on the payment chain to the asset chain.

The protocol avoids complex timelocks and API-heavy coordination between the chains.

  1. A smart contract on the asset chain locks the asset.
  2. A smart contract on the payment chain requests decryption of a key based on whether payment succeeds or fails.
  3. A party presents the decrypted key to the asset-chain contract to unlock the asset.

Specification

Version note: The interfaces below follow the historical draft covered by the Japanese article. The current draft uses a uint256 transaction ID and bytes encrypted keys, identifies sender and recipient explicitly, and separates confirmation from transferAndDecrypt(uint256 id).

Methods

Contract on the locking chain, such as the asset chain

The following methods belong to the contract responsible for locking the asset.

Methods and behavior

Starting a transfer with inceptTransfer
js
function inceptTransfer(bytes32 id, int amount, address from, string memory keyEncryptedSeller) external;

The asset buyer starts the token transfer.

  • Parameters
    • id
      • Transaction identifier.
    • amount
      • Amount of tokens to transfer.
    • from
      • Address sending the asset.
    • keyEncryptedSeller
      • Encrypted key used to let the sender reclaim the tokens.
  • Event
    • Emits TransferIncepted.
Confirming a transfer with confirmTransfer
js
function confirmTransfer(bytes32 id, int amount, address to, string memory keyEncryptedBuyer) external;

The asset sender confirms the token transfer.

  • Parameters
    • id
      • Transfer identifier.
    • amount
      • Amount of tokens to transfer.
    • to
      • Asset buyer's address.
    • keyEncryptedBuyer
      • Encrypted key used to let the buyer claim the tokens.
  • Event
    • Emits TransferConfirmed.

The transfer details at confirmation, including id, amount, from, and to, must match the earlier inceptTransfer call. If the details match and the sender holds enough tokens, the tokens move from from to the contract, which locks them and emits TransferConfirmed.

Moving the tokens with transferWithKey
js
function transferWithKey(bytes32 id, string memory key) external;

Either the buyer or seller calls this function for the associated transfer.

  • Parameters
    • id
      • Transfer identifier.
    • key
      • Plaintext obtained by decrypting the encrypted key.

If the buyer (to) calls with a key corresponding to keyEncryptedBuyer, the contract transfers the locked tokens to the buyer and emits TokenClaimed. If the seller (from) calls with a key corresponding to keyEncryptedSeller, the contract returns the locked tokens to the seller and emits TokenReclaimed.

ILockingContract interface

js
interface ILockingContract {
    event TransferIncepted(bytes32 id, int amount, address from, address to, string keyEncryptedSeller);
    event TransferConfirmed(bytes32 id, int amount, address from, address to, string keyEncryptedBuyer);
    event TokenClaimed(bytes32 id, string key);
    event TokenReclaimed(bytes32 id, string key);

    function inceptTransfer(bytes32 id, int amount, address from, string memory keyEncryptedSeller) external;
    function confirmTransfer(bytes32 id, int amount, address to, string memory keyEncryptedBuyer) external;
    function transferWithKey(bytes32 id, string memory key) external;
}

Contract on the conditional decryption chain, such as the payment chain

The following methods belong to the contract responsible for conditional decryption.

Methods and behavior

Starting a transfer with inceptTransfer
js
function inceptTransfer(bytes32 id, int amount, address from, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external;

The payment recipient starts the transfer.

  • Parameters
    • id
      • Transaction identifier.
    • amount
      • Payment amount.
    • from
      • Payer's address. The recipient is msg.sender.
    • keyEncryptedSuccess
      • Ciphertext for the key to decrypt on successful payment.
    • keyEncryptedFailure
      • Ciphertext for the key to decrypt if payment fails.
  • Event
    • The Japanese prose calls this event PaymentTransferIncepted. The interface below names it TransferIncepted.
Paying and decrypting with transferAndDecrypt
js
function transferAndDecrypt(bytes32 id, int amount, address to, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external;

The payer calls this function to complete the payment transfer.

  • Parameters
    • id
      • Transaction identifier.
    • amount
      • Payment amount.
    • to
      • Payment recipient's address. The payer is implicitly msg.sender.
    • keyEncryptedSuccess
      • Ciphertext for the key to decrypt on successful payment.
    • keyEncryptedFailure
      • Ciphertext for the key to decrypt if payment fails.
  • Events
    • Emits TransferKeyRequested and TransferKeyReleased.
    • The payment outcome determines which key is decrypted.

This method does not perform a payment transfer or request decryption if the values id, amount, from, to, keyEncryptedSuccess, and keyEncryptedFailure differ from the earlier inceptTransfer call.

Canceling the transaction with cancelAndDecrypt
js
function cancelAndDecrypt(bytes32 id, address from, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external;

The payment recipient calls this function to cancel the payment transfer.

  • Parameters
    • id
      • Transaction identifier.
    • from
      • Payer's address.
    • keyEncryptedSuccess
      • Ciphertext for the key associated with successful payment.
    • keyEncryptedFailure
      • Ciphertext for the key associated with failed payment.

This method only cancels a payment transfer when the supplied values match the corresponding arguments of the earlier inceptTransfer call.

IDecryptionContract interface

js
interface IDecryptionContract {
    event TransferIncepted(bytes32 id, int amount, address from, address to, string keyEncryptedSuccess, string keyEncryptedFailure);
    event TransferKeyRequested(bytes32 id, string encryptedKey);
    event TransferKeyReleased(bytes32 id, bool success, string key);

    function inceptTransfer(bytes32 id, int amount, address from, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external;
    function transferAndDecrypt(bytes32 id, int amount, address to, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external;
    function cancelAndDecrypt(bytes32 id, address from, string memory keyEncryptedSuccess, string memory keyEncryptedFailure) external;
}

Encryption and decryption

The two smart contracts coordinate using plaintext keys (key) and encrypted keys (encryptedKey).

The scheme can use any encryption method the oracle supports, as long as both parties use the same method. Encryption uses the decryption oracle's public key, which both the buyer and seller know. Both parties also check that the keyEncryptedBuyer and keyEncryptedSeller strings have valid formats.

Payment sequence diagram

The sequence diagram shows how the two contracts interact.

Sequence diagram for cross-chain delivery versus payment Source: https://eips.ethereum.org/EIPS/eip-7573#sequence-diagram-of-delivery-versus-payment

The diagram illustrates secure delivery versus payment between the asset chain and the payment chain. The abbreviated calls below follow the original walkthrough. See the interface declarations above for exact signatures.

Participants

  • Seller of Asset
    • The party selling the asset.
  • Buyer of Asset
    • The party buying the asset.
  • Asset Contract
    • The locking contract (ILockingContract) on the asset chain.
  • Payment Contract
    • The conditional decryption contract (IDecryptionContract) on the payment chain.
  • Payment Operator
    • The decryption oracle.
  1. Prepare the encrypted keys

    • The seller and buyer encrypt their respective keys with the decryption oracle's public key.
    • encrypt B represents encryption of the buyer's key.
    • encrypt S represents encryption of the seller's key.
  2. Start the transaction

    • Buyer calls inceptTransfer(id, amount, from, E(S)) to start the asset transfer.
    • The locking contract emits TransferIncepted and stores E(S).
    • The Payment Contract receives inceptTransfer(id, amount, from, E(B), E(S)) to start the corresponding payment transfer. It emits TransferIncepted and stores E(B) and E(S).
  3. Confirm the transaction

    • Seller calls confirmTransfer(id, to, E(B)) to confirm the asset transfer.
    • The locking contract emits TransferConfirmed and locks the tokens.
  4. Cancel payment, if needed

    • Payment Contract receives cancelAndDecrypt(id, amount, to, E(B), E(S)) in the abbreviated walkthrough.
    • If payment has been initiated but completion has not been requested with a valid transferAndDecrypt call, the recipient can cancel it.
    • The contract emits TransferKeyRequested, and the decryption oracle decrypts E(K).
    • The contract emits TransferKeyReleased, making the seller's key S available.
  5. Complete payment

    • Payment Contract receives transferAndDecrypt(id, amount, to, E(B), E(S)).
    • The payer completes the payment operation.
    • The contract emits TransferKeyRequested, and the decryption oracle decrypts E(K).
    • If payment succeeds, decryption of E(B) yields K = B, the buyer's key.
    • If payment fails, decryption of E(S) yields K = S, the seller's key.
    • The contract emits TransferKeyReleased.
  6. Transfer the asset

    • Buyer calls transferWithKey(id, B) to claim the locked tokens using B.
    • The locking contract emits TokenClaimed and transfers the asset to the buyer.
    • Seller calls transferWithKey(id, S) to reclaim the locked tokens using S.
    • The locking contract emits TokenReclaimed and returns the asset to the seller.

Additional notes

The protocol aims to keep coordination simple and efficient.

Protocol details

  • Transaction identifier

    • Each transaction has a unique identifier, id.
    • The parties should ideally generate that identifier as part of a separate interaction.
  • Plaintext and encrypted keys

    • The key and encryptedKey arguments are strings.
    • This lets the parties use different encryption schemes across different trades.
  • Encryption and decryption scheme

    • The scheme should be inferable from the contents of encryptedKey.

Citation

Christian Fries (@cfries), Peter Kohl-Landgraf (@pekola), "ERC-7573: Conditional-upon-Transfer-Decryption for DvP [DRAFT]," Ethereum Improvement Proposals, no. 7573, December 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7573.

Conclusion

ERC-7573 proposes an interface for exchanging tokens across two different blockchains. The decryption oracle releases a key based on the payment outcome, so the asset-chain contract can let either the buyer claim the asset or the seller reclaim it.

Questions are welcome by direct message.

Twitter @cardene777

Find more of my writing here.

https://chaldene.net/