Cross-Chain Atomic Swaps
Diviko enables trustless atomic swaps between Canton and Ethereum. No bridge operators, no custodians, no trust assumptions beyond the two chains themselves. If both parties follow the protocol, the swap completes. If either party walks away, both are refunded.
The mechanism is a hash time-locked contract (HTLC) deployed on both sides — a Daml template on Canton and a Solidity contract on Ethereum. Both use SHA-256, so a single preimage/hash pair works across both chains.
How it works
Suppose Alice holds Canton Coin and wants ETH, and Bob holds ETH and wants Canton Coin.
- Alice generates a secret preimage and computes
hashLock = sha256(preimage) - Alice locks her Canton tokens on-chain using the hashLock
- Bob sees Alice's lock, then locks his ETH on Ethereum using the same hashLock
- Alice claims Bob's ETH by revealing the preimage on Ethereum
- Bob reads the preimage from the Ethereum
Claimedevent and claims Alice's Canton tokens
The critical detail is timelock ordering: Bob's Ethereum lock must expire before Alice's Canton lock. This guarantees Bob always has time to learn the preimage from Ethereum and claim on Canton before Alice can refund.
| Step | Chain | Actor | Action |
|---|---|---|---|
| 1 | off-chain | Alice | Generate preimage, compute hashLock |
| 2 | Canton | Alice | Create HTLCProposal, Bob accepts |
| 3 | Ethereum | Bob | Call createETH locking ETH with the same hashLock |
| 4 | Ethereum | Alice | Call claim to collect ETH, revealing the preimage |
| 5 | Canton | Bob | Exercise Claim with the revealed preimage |
Hash compatibility
The Canton side uses DA.Text.sha256 in Daml. The Ethereum side uses the EVM's native sha256 precompile. Both produce identical digests for the same UTF-8 input — verified in our cross-chain test suite with hardcoded hashes.
Refund safety
If Alice never claims on Ethereum, Bob refunds his ETH after the deadline. Alice then refunds her Canton tokens after the Canton deadline. Neither party can lose funds — the worst outcome is that the swap doesn't happen.
The Solidity contract also supports ERC-20 tokens via createERC20, so the same mechanism extends to any token pair between Canton and Ethereum.