-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[R4R]BEP3: HTLC and Atomic Peg #30
Conversation
8e8305b
to
3f09938
Compare
@caffeinum Could you help to review this BEP? |
When will this feature come online |
#### Preparation Stage | ||
|
||
1. Owner should issue proper number of tokens on Binance Chain as the Pegged | ||
2. Owner should create one address on Binance Chain (as OB in the below diagram), and transfer in enough number of tokens for swap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is the diagram?
#### Client Swap Tokens from Ethereum to Binance Chain | ||
|
||
1. Client calls APS contract, with the hash of a secret, X tokens and a time span T parameters, to express his/her interest to swap X tokens. If the parameters are good (e.g. T>MinLockTime, enough tokens to swap), the call transaction is recorded on the blockchain. | ||
2. Deputy process monitors the events of the APS contract on Ethereum. If it detects the client’s call and verify good, it will sign and broadcast the HTLT transaction on Binance Chain. This will lock X (or more as bonus) number of pegged tokens on Binance Chain. Please note the time span used in this HTLT transaction should be smaller enough than T in Client’s APS call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to check if the contract has enough deposit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to check. The contract will ensure there has been enough deposit on the contract address.
Will it be possible to lock the operator's balance so they can only send using HTLC? |
|
||
### Claim Hash Timer Locked | ||
|
||
Claim Hash Timer Locked (CHTL) is to claim the locked asset by showing the Random Number value that matches the hash. Each HTLT locked asset is guaranteed to be release once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be CHLT? This is the only place it is called CHTL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHTL
is right.
|
||
## Atomic Peg Swap | ||
|
||
The primary purpose of HTLC in Binance Chain is to support Atomic Peg Swap (APS). APS is proposed here as the standard way for asset/token issuers to peg or migrate part of the asset/token onto Binance Chain, so that users of the tokens can enjoy the fast transactions and pleasant trading experience. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe Atomic Swap and Peg should be a totally separate concerns. Atomic Swap is an option, and cannot be enforced without intermediary and complicated mechanisms like DAI (which isn't safe, too).
It's easy to implement an Atomic Swap using HTLC first, so I think we should focus on that and move Peg discussion to separate BEP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#### Preparation Stage | ||
|
||
1. Owner should issue proper number of tokens on Binance Chain as the Pegged | ||
2. Owner should create one address on Binance Chain (as OB in the below diagram), and transfer in enough number of tokens for swap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "OB
" an ordinary address controlled by the owner's private key? If so, isn't the owner free to move tokens from this address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It is an ordinary address. But once HTLT transaction is sent, a certain number of coins will be transferred to a temporary address. There is no risk for swap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood the swap process works. My question is geared more towards ensuring the total supply of tokens is still fixed. It's unclear to me how the current proposal guarantees at any given time, circulatingSupply(BEP-2) + circulatingSupply(ERC-20) == originalCirculatingSupply(ERC-20)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking ERC20 token for instance, the total supply of token A is 10000. If 5000 the BEP2 token is minted, then 5000 ERC20 token should be burned. Currently, there are 5000 BEP2 token and 5000 ERC20 token. Then the swap service provider use 1000 BEP2 token and 1000 ERC20 token for atomic swap service. Then total supply is still 10000.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But there's no prevention against the token owner minting more BEP-2, besides community monitoring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. The community monitor is the main insurance for the unexpected minting on Binance Chain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HaoyangLiu I believe it cannot be called a peg then.
I will state again that I think it's needed to separate Atomic swap BEP and Peg BEP.
22389ff
to
feca1f0
Compare
Changes on Binance Chain implementation:
Changes on swap contract interface:
I have add the above changes. Please review it again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think pegging mechanism needs much improvement, while Atomic swap is OK.
It's great we're having progress here, but I am for the separation.
@caffeinum |
Without loss of generality, let's design a pegging scheme between ERC-20 and BEP-2. IMO a proper mechanism should be something as follows: Create pegged BEP-20 tokens (convert a part of the supply from ERC-20 to BEP-2):
Destroy pegged BEP-20 tokens (convert a part of they supply from BEP-2 to ERC-20):
Note that this requires an extension to the semantics of This mechanism guarantees that the total supply of the token remains constant. |
b9573e5
to
235f94b
Compare
https://github.com/swishlabsco/cosmos-ethereum-bridge is an example of a unidirectional pegging implementation. |
FYI The latest version of the ETH bridge code is https://github.com/musnit/peggy/tree/unidirectional-complete |
It is nice to have it trustless, but it is heavy-weight-lifting and I don't think it is realistically achievable to implement this feature for multiple chains. I agree it is not a perfect solution for Peg here. The progress is to make at least a better way than current situation of how peg is performed on Binance Chain. |
Understood. We can revisit once projects like ThorChain have made more progress with generic peg zone implementations. |
This BEP is about introducing Hash Timer Locked Contract functions and further mechanism to handle inter-blockchain token peg.
HTLC has been used for Atomic Swap and cross payment channel for a few years on Bitcoin and its variant blockchains, and also Ethereum. This BEP defines native transactions to support HTLC on Binance Chain, and also proposes the standard infrastructure and procedure to use HTLC for inter-chain atomic swap to easily create and use pegged token, which is called
Atomic Peg
.Related BEP: #3