ERC-7573 Cross-chain delivery-versus-payment (DvP) protocol (Conditional-upon-Transfer-Decryption for DvP)
Draft · Vaults & DeFi · created 2023-12-05
A standard that lets an asset on one chain and payment on another chain be settled simultaneously (DvP) without an intermediary, even though the two transfers are on different chains. Depending on whether settlement succeeds, an oracle decrypts one of two cryptographic keys to unlock the asset.
Why it is needed
When buying or selling assets on a blockchain, the asset may move on one chain while the payment moves on a different chain or a separate payment system. This creates the risk that the asset is transferred without payment arriving, or payment is made without the asset being received. In finance, the principle that prevents this is called Delivery-versus-Payment (DvP). Previously proposed solutions required either a separate API integration bridging the two chains, or reliance on complex and problematic time locks (locks that release only after a certain time has passed). This standard aims to achieve secure DvP with less overhead and no intermediary by placing one contract on each chain and using a stateless decryption oracle that releases either a success key or a failure key depending on the settlement outcome.
What to implement
function transferWithKey(uint256 id, bytes memory key) external;: If the hash of the presented key matches the buyer's key hash, the locked token is sent to the buyer; if it matches the seller's key hash, it is sent to the seller.event TokenLocked(uint256 indexed id);: A signal indicating the token was actually locked. It must be emitted exactly once per transfer leg.event TokenClaimed(uint256 id, bytes key);: Indicates that the token locked with the buyer's key has been transferred to the buyer.event TokenReclaimed(uint256 id, bytes key);: Indicates that the token locked with the seller's key has been returned to the seller.function transferAndDecrypt(uint256 id) external;: Called by an authorized finalizer to execute a confirmed payment, emitting a TransferKeyRequested event containing the cryptographic key matching the outcome.function releaseKey(uint256 id, bytes memory key) external;: Called by the decryption oracle. If the call is eligible, it emits a TransferKeyReleased event containing the decrypted key.event TransferKeyRequested(address sender, uint256 id, bytes encryptedKey);: Indicates that the cryptographic key to be sent to the oracle for decryption has been selected.event TransferKeyReleased(address sender, uint256 id, bool success, bytes key);: Indicates that the decrypted key has been released. This key can be used to call transferWithKey on the locking contract.function onInceptionCompleted(uint256 id) external returns (bytes4 acknowledgement);: The completion callback invoked by the decryption contract when asynchronous key generation finishes. It must return its own function selector.
In depth
Division of labor between two contracts and a stateless oracle
This standard consists of two smart contracts, one per chain. The ILockingContract on the asset chain locks tokens until the hash of a presented key, or some other lock representation, matches one of two values agreed upon in advance. The IDecryptionContract on the payment chain releases one of two keys, depending on whether settlement succeeds or fails, through a decryption oracle. The oracle is stateless and no intermediary is required. The concept is not limited to asset-versus-payment exchange; it is a general structure for making a token transfer on one chain conditional on the success of a token transfer on another chain.
Lifecycle of the locking contract and the TokenLocked rule
inceptTransfer initiates a transfer by registering the hash of the seller's key and the ciphertext. confirmTransfer locks the given amount by moving it from `from` to the contract, provided that (id, amount, from, to, transaction) exactly matches the inception and the balance is sufficient. TokenLocked(id) must be emitted exactly once, after the lock actually succeeds, and must not be emitted on failure, pending status, cancellation, or idempotent retries. transferWithKey sends the tokens to the stored buyer (`to`) and emits TokenClaimed if the key hash matches keyHashedBuyer, or returns them to the seller (`from`) and emits TokenReclaimed if it matches keyHashedSeller. Since the participants and destination are already stored, the correct key itself can serve as the authorization, and the caller need not be a transacting party. cancelTransfer is a pre-confirmation cancellation, and a cancelled id cannot be reused.
Success and failure keys in the decryption contract
inceptTransfer on the payment chain registers two cryptographic keys, keyEncryptedSuccess and keyEncryptedFailure. The two must point to distinct keys; if they are the same, the success and failure outcomes cannot be distinguished, so it must be rejected. transferAndDecrypt(id) can only be used by a caller who satisfies the finalizer policy, and in the confirmed state it emits a TransferKeyRequested containing the cryptographic key matching the outcome. cancelAndDecrypt must repeat the entire inception content exactly, and emits the failure key only if the success key has not already been emitted via TransferKeyRequested. releaseKey is called by the oracle and, if eligible, publishes the decrypted key via TransferKeyReleased. The order of the success and failure keys is normative; if an unordered pair is received, selection must be made by semantic identifier, not by array position.
Lifetime uniqueness of id and the msg.sender rule
id is the lifetime-unique identifier of a single transfer leg. Re-inception of the same id must be rejected even after completion or cancellation. Paired locking and decryption contracts can link both sides of a DvP using the same numeric id, and a group identifier that bundles multiple legs must be encoded within each leg's immutable transaction data. `from` and `to` are passed explicitly; msg.sender is merely the caller and must not alone be used to determine participants. Confirmation and cancellation must compare every repeated argument, including dynamic byte strings, against the stored inception values. Oracle jobs use a separate, oracle-assigned requestId, which must not be confused with this id.
Asynchronous key generation extension and completion callback
IDecryptionContractWithKeyGeneration adds an inceptTransfer that can be called before keys exist. callback may be address(0); if nonzero, it must implement IDecryptionContractInceptionCallback. The generated success and failure key material must be stored atomically with the pending inception and cannot be replaced afterward, and TransferIncepted is emitted only after both keys have been stored. Before calling the callback, the full context and key material must be readable via getInceptionContext and getInceptionKeyMaterial, and the receiving side must authenticate the decryption contract, cross-check all fields, and return the function selector. If the callback fails, the completion attempt is reverted and the inception remains pending for retry. On the locking side, ILockingContractWithKeyGeneration approves a specific decryption contract as the immutable source of keys and finalizes the lock via completeLock or a direct callback.
Oracle proxy standard and strict vs. best-effort fulfillment
Communication with external oracles is standardized through IKeyDecryptionOracle (the proxy) and IKeyDecryptionOracleCallback (the receiver). A consumer calls request* to obtain a requestId; the off-chain oracle observes the event and calls fulfill*, and the proxy then invokes the on* callback. Both key generation and verification are batch operations: there must be exactly one result per requested keyId, and duplicate, missing, unrequested, or partial-batch entries must be rejected. The verification result is authoritative as a single `verified` value; per-key partial success is not represented. Two fulfillment modes are permitted. In strict mode, a callback failure reverts fulfill* so the oracle operator can retry; in best-effort mode, it does not revert, and failure is instead signaled via an event such as CallbackFailed, with recovery left to a watcher on the consumer side. It is also recommended to document a fallback for recovering fulfillment data from the calldata of the fulfill* call.
Key document format for stateless decryption
It might seem that state is needed for the oracle to release keys only to eligible contracts, but introducing a document format into the key itself enables fully stateless decryption. The undecrypted key document contains the address of the payment contract implementing IDecryptionContract, and after decrypting the document, the oracle delivers the key to releaseKey on the callback contract address found inside it. The original text proposes an XML schema for a releaseKey element with contract and transaction attributes. The encryptedKey field may be ciphertext or a reference to a key in an authenticated external system, and the authority to release the key must not depend solely on the confidentiality of the reference. To avoid on-chain encryption in the locking contract, a simpler hash can be used instead, with the oracle providing a way to obtain the hash H(K) from the cryptographic key E(K) without exposing the key itself.
Multilateral DvP and proposal status
Locking is a feature, not an inconvenience. For n parties to atomically bundle two-party transactions, at least 2(n-1) transfers are needed, m-1 of which require locking, with the success or failure of the final one determining whether the remaining locks are released or returned. Each payment leg uses its own unique id, and a common group identifier is encoded in the transaction field. Before the first confirmation is received, an implementation must freeze the expected set of legs and the finalizer policy; legs must not be added afterward, and the full set of currently registered legs must not be treated as the complete group. Once the frozen set is fully confirmed, a single call to transferAndDecrypt(id) on the designated coordinating leg requests all success keys on success or all failure keys on failure. This proposal is currently in Draft status, and its content may still change.
Things to watch out for
- Mitigating a single point of trust with threshold decryption: The oracle need not be a single trusted party. Using threshold decryption, where multiple oracles perform partial decryption and a quorum must be reached to reconstruct the key, reduces the risk of a single point of failure and single-party trust.
- Restricting callback callers and validating pending requests: Callback implementations must restrict who can call them (e.g., checking that msg.sender is the oracle proxy); otherwise, any address could call the on* function directly. They must also validate that a pending (oracleProxy, requestId) of the expected operation type exists, and consume or mark it before applying its effects.
- Blocking duplicate and reentrant fulfillment: Before invoking a callback, the oracle proxy must put the corresponding request into a state where concurrent or reentrant fulfillment is impossible. A best-effort proxy may return the request to pending status after a callback failure to allow a retry.
- Atomicity of batch verification and authentication of the failure path: Batch verification must exactly match the full set of requested keys by keyId, authenticate all cryptographic references against the same single-use settlement context and external batch context, and complete atomically. Verifying only the success key does not authenticate the failure path. The ability to verify a failure key reference must be kept separate from the authority to decrypt and release that key.
- Verification duties of asynchronous callback receivers: For nonzero asynchronous inception callbacks, the completed inception must be stored before the external call, invoked with limited gas, and its selector return value verified. The receiver must authenticate the expected decryption contract, cross-check id and all getter fields, and confirm key availability; the locking-side receiver must additionally require that the getter's callback matches its own address. Otherwise, a single inception could be reused across multiple asset contracts.