The idea is to create an escrow order in a target chain and prove Bitcoin transaction to target address via zk light client.
- Create two smart contracts:
- Smart contract for exchange (SCE);
- Smart contract for storing data about the Bitcoin valid chain (SCS).
- Make a zk-proof of the block data.
SCE implements the exchange logic and sends requests to the SCS. The SCS must be constantly running to maintain the network and correct block data from the valid chain. A single block in Bitcoin becomes final approximately after six blocks have been built on top of it (~10 min for one block, i.e. 1 hour for 6 blocks). Accordingly, we propose to update one block every hour to keep the “local chain” (in SCS) up-to-date. The scheme checks the prev_hash, prev_height and PoW of the block.
SCS contains the hash, height and PoW of the block (or chain). We check the chain PoW to make sure that the valid chain contains the requested block. When smb makes a swap request, SCE makes a request to SCS to check if the “local chain” contains the required block (the latest valid block in the chain), which can be used as a trusted point to confirm the requested block.
Zk-proof of the block data. The scheme uses seven blocks from RPC (including the requested one) to prove the block and the data of the last valid block stored in SCS. The following data needs to be proven:
- Check hash of the block:
sha256(sha256(proposed_block_header)) = block.hash
; - Check prev_hash in all eight blocks:
block.prev_block_hash = prev_block.hash
; - Check prev_height in all eight blocks:
block.height = prev_block.height + 1
; - Check PoW in all eight blocks. This check confirms that the current block is valid:
sha256(sha256(proposed_block_header)) <= target_block_difficulty
; - Check PoW of the chain, i.e. the heaviest chain, and PoW of the requested block. It confirms that the requested block is included in the valid chain.