## BTC to ETH secure cross chain swap
### Purpose
Allow anyone to seamlessely swap their Bitcoin for Ethereum in a trustless and secure way.
In this short description: Alice will be the buyer/sender, Bob the market maker and Carol; Bob's assistant.
### test it out
Click [here](https://james-sangalli.github.io/btcrelay/examples/mainnetSwap.html)
### Introduction
BtcRelay is a service invented by Joseph Chow with the intention to allow Bitcoin SPV verification to be done inside an ethereum smart contract.
The potential of such a service is massive as it can allow for cross chain services to happen, like the one mentioned below.
Note: with this technology it is also possible to relay on other ethereum networks as well as clones of Bitcoin that use SPV.
### Implementation
Let's say that Bob has a large stash of Ether and would like to create a service whereby he can sell his ether safely for a profit in exchange for bitcoin without worrying about fraud or potential for accidental loss.
With the smart contract here: https://github.com/James-Sangalli/Solidity-Contract-Examples/blob/master/Finance/bitcoin-to-ethereum-swap/BTC2ETH.sol Bob can create the contract, set a fresh Bitcoin address controlled by himself to receive coins and set himself as the admin of the contract, allowing him to set the rate of Bitcoin to Ethereum.
Note: Since Bitcoin and Ethereum use the same private key algorithm, it is possible for Alice to recieve ether on the same key that holds her bitcoins (by getting the public key from the bitcoin transaction and hashing it into an ethereum address).
### Steps for Bob to become the market maker:
- Bob creates the smart contract and sends 1000 eth to store as liquidity in the contract
- Bob sets his bitcoin address that receives the funds to be swapped using the smart contract (this should be a fresh address as old transactions that are irrelevant could be claimed otherwise)
- Bob sets the daily rate for ether to bitcoin inside the smart contract
- Optional: Bob sets the fee for the transaction that he would like e.g. 2%
- Optional: Bob adds a small fee back to the relayer of the block that the transaction is in
### Steps for Alice to get her Ether for Bitcoin
- Alice checks that Bob’s contract has enough ether for her trade
- She checks what Bitcoin address to send the Bitcoin to
- She checks to see if she is happy with the rate (in this example it is 10:1)
- She sends 1 bitcoin to Bob’s bitcoin address, expecting back 10 ether minus fees after 6 confirmations on the Bitcoin network
### Steps for Carol to complete the transaction (note, Carol is probably Bob’s assistant or Bob himself)
- Carol runs a Bitcoin node and notices a new transaction in the address set by Bob
- Carol gets the transaction info and submits it to the smart contract to validate. In this case it is the raw transaction, transaction hash, merkle sybling and the block hash.
### Steps for the smart contract
- BtcRelay validates that the transaction has occured in the Bitcoin blockchain
- If it has happened then the smart contract derives the corresponding ethereum address by taking the public key from the transaction and hashing it into an ethereum address.
- The smart contract sends the ether to Alice and adds the transaction hash to an array to ensure that the transaction is not resubmitted
### Note on BtcRelay relayers
One of the biggest issues with BTCRelay is providing incentives for ethereum nodes to relay Bitcoin headers, this can be mitigated by Bob if he decides to allocate a portion of the transaction as a fee back to the relayer.
### Security Considerations
- If Bob is close with miners, he can conspire to delay Alice's transaction and take all the liquidity away from the contract
- Bob risks his ether in the smart contract (contract must be airtight)
- Relayers might go silent and stop relaying (can be mitigated by anyone willing to run nodes and relay)
没有合适的资源?快使用搜索试试~ 我知道了~
实例学习:以Solidity编写的充满智能合约的仓库
共37个文件
sol:27个
css:2个
js:2个
需积分: 10 5 下载量 115 浏览量
2021-02-05
05:13:41
上传
评论
收藏 144KB ZIP 举报
温馨提示
通过实例学习团结! 用Solidity编写的充满智能合约的仓库。 此回购旨在用于教育。 任何人都可以随意使用它,并提出建议和/或请求。 金融 该目录包含与金融应用程序相关的所有智能合约,例如原子掉期交易,跨链掉期和其他工具 积分 可以允许服务无缝集成的智能合约示例。 诸如可管理声誉的dapp之类的东西可以在其他智能合约中引用。 验证 可以验证外部工作的智能合约示例,例如机器学习模型,并通过提供的证明对其进行奖励。 其他方便的资源 AlphaWallet-具有本机ERC和以太坊支持的移动钱包 Android: : iOS: :
资源详情
资源评论
资源推荐
收起资源包目录
learn-solidity-with-examples-master.zip (37个子文件)
learn-solidity-with-examples-master
SafeMath.sol 2KB
Finance
misc
GasSpeculator.sol 1KB
bank.sol 2KB
shares.sol 649B
ConvertLib.sol 219B
ContractWallet.sol 3KB
bankPlus.sol 2KB
socialSecurity.sol 1KB
Government.sol 1KB
accounting.sol 1KB
stock.sol 728B
GasTokenSubsidisedTransactions.sol 2KB
InvestorDAO.sol 5KB
sangalliCoin
sangalliCoin.sol 2KB
market.sol 2KB
sangalli.js 4KB
deploy.sol 121B
swaps
bitcoin-to-ethereum-swap
css
bootstrap.min.css 141KB
style.css 1KB
images
qr.png 417B
package.json 274B
btcrelayInterface.sol 2KB
BTC2ETH.sol 4KB
ERC20.sol 786B
bundle.js 488KB
README.md 4KB
BtcParser.sol 13KB
erc20Swap.sol 1KB
ETH2BTC.sol 5KB
BuyTokensWithBTC.sol 3KB
LICENSE 1KB
Verification
VerifyModelByOutput.sol 5KB
MachineLearningVerification.sol 3KB
Intergration
Reputation.sol 1KB
IntergrationExample.sol 3KB
.gitignore 633B
README.md 973B
共 37 条
- 1
步衫
- 粉丝: 29
- 资源: 4641
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0