BitShares Forum

Main => General Discussion => Topic started by: xeroc on October 18, 2014, 12:33:15 pm

Title: Atomic Cross Chain Trading
Post by: xeroc on October 18, 2014, 12:33:15 pm
For those that did not attend the latest dev hangout, BM briefly explained how cross-chain trading would work.
However, he also stated that ACCT is very low in priority as they see more value from developing escrow ... (imho they are right)

Anyway, I'd like to also let you know how ACCT works.

Let's assume we have Alice wanting to trade 1 bitUSD on BTSX chain for 1 bitUSD
on the DNS chain. Bob wants to do the same .. but the other way round.

Alice goes first (could also be Bob) .. and generates a random passphrase. Let's say

Passphrase: AlIcETraDesWithBoB1USD

Alice generates the hash of the passphrase and gets something like

hash(Passphrase): afb39ca02949c0ae4a6a44e8eef5242fd81bd93072d82ebff145743c1910c098

Alice uses a new kind of transaction (not so new.. it's already in the blockchain and called withdraw_password_type) ..
that transaction goes towards bob and has the following rules

- the transaction is going TO bob
- it has a expiration of .. say 24h .. after that only alice can claim the transaction again
- bob can claim (within 24h) .. ONLY if he knows the password

Alice broadcasts this transaction in the BTSX chain and thus "transfers" the
funds to bob .. who will only be able to claim the shares if alice tells the password!

In the meantime, Bob creates a new transaction in the DNS chain. That
transaction goes to the account name of alice, and uses the exact same hash of
the passphrase (bob see that passphrase from alice's transaction in the btsx
chain) .. and he set's a expiration of less then 24h ..

So, if alice wants to have her shares in the DNS chain, she needs to reveal the
password in order to claim the withdraw_password_type-transaction in DNS.
By doing so, Bob sees the passphrase and can take his shares in the BTSX chain,
beacuse it uses the same passphrase.

Tada .. everything worked out .. everybody happy :)

Remarks:

- It is crucial to have the the second transaction (bob does not know the
passphrase) .. expire WAY earlier than the first transaction to ensure that
alice cannot reclaim an EXPIRED ACCT transaction

- It is crucial (as usual) that the passphrase is chosen securely, and randomly!!

Anything I forgot to describe? Anything unclear?
Title: Re: Atomic Cross Chain Trading
Post by: emski on October 18, 2014, 12:42:18 pm
This would work for BTSX and DNS.
What about BTSX and BTC ?
What if Bob just wants to mess with Alice by blocking the funds for 24hours ?
Title: Re: Atomic Cross Chain Trading
Post by: xeroc on October 18, 2014, 12:47:30 pm
This would work for BTSX and DNS.
What about BTSX and BTC ?
If you can build a script that
a) expires after x hours and
b) can be claimed a multisig (one key from the owner, the other key from the passprhase)
then you should be able to build this for btc to .. yes
not with with a) though

Quote
What if Bob just wants to mess with Alice blocks the funds for 24hours ?
If you'r passphrase is random and long enough it shouldn't be an issue .. will it?
and surely .. you can just a shorter time intervall .. ie 10 minutes ..
however .. the second party should always use a SHORTER time

// edit: .. lol shorter than 10 minutes is no good with BTC ..
actually .. all this might not work well with btc .. due to the "uncertain time" of the next block
Title: Re: Atomic Cross Chain Trading
Post by: xeroc on October 18, 2014, 12:56:29 pm
you could do a double spend in bitcoin ..

a) one transaction with nlocktime going back to your own address
b) one transaction with something like op_check_hash ... for the trade

however .. you would need to have both in the blockchain ...
which the miners should not be allowed to do ..

//edit:
https://en.bitcoin.it/wiki/Atomic_cross-chain_trading
Title: Re: Atomic Cross Chain Trading
Post by: emski on October 18, 2014, 01:05:04 pm
I was just going to write about the double spend option in BTC. Miners will not include both transactions. Only the first one.

Have you seen this thread:
https://bitsharestalk.org/index.php?topic=9075.0 (https://bitsharestalk.org/index.php?topic=9075.0) ?
Title: Re: Atomic Cross Chain Trading
Post by: xeroc on October 18, 2014, 01:13:22 pm
I was just going to write about the double spend option in BTC. Miners will not include both transactions. Only the first one.
Thought so ..
If I find some time I will read through:
https://en.bitcoin.it/wiki/Atomic_cross-chain_trading
But it contains exchanging of signed and unsigned transactions .. (ugly, not user friendly)

Quote
Have you seen this thread:
https://bitsharestalk.org/index.php?topic=9075.0 (https://bitsharestalk.org/index.php?topic=9075.0) ?
Thx, I will read through it ..
However, from what I can see .. the delegates are involved and you are trading BTSX<->BTC on two chains ..
maybe we should start out with something easier and go for bitBTC <-> BTC first ... not having an exchange ratio
Title: Re: Atomic Cross Chain Trading
Post by: emski on October 18, 2014, 01:16:03 pm
I was just going to write about the double spend option in BTC. Miners will not include both transactions. Only the first one.
Thought so ..
If I find some time I will read through:
https://en.bitcoin.it/wiki/Atomic_cross-chain_trading
But it contains exchanging of signed and unsigned transactions .. (ugly, not user friendly)

Quote
Have you seen this thread:
https://bitsharestalk.org/index.php?topic=9075.0 (https://bitsharestalk.org/index.php?topic=9075.0) ?
Thx, I will read through it ..
However, from what I can see .. the delegates are involved and you are trading BTSX<->BTC on two chains ..
maybe we should start out with something easier and go for bitBTC <-> BTC first ... not having an exchange ratio

bitBTC <-> BTC or BTSX <-> BTC doesn't matter. That should be the same. And the ratio -> you still should have some kind of ratio even for BTC <-> bitBTC .

Update: Infact there is no incentive for anyone holding BTC to exchange that for bitBTC even at 1:1 unless he wants to trade against other assets on BTSX blockchain. And BTSX is better suited for that.
Title: Re: Atomic Cross Chain Trading
Post by: CoinHoarder on October 18, 2014, 02:54:10 pm
Why is this a low priority? You've now seen people's reactions that bitUSD will be implemented in Bitshares Vote.. BTSX is down 5% since that announcement was made and it could get much worse. One usually big time Bitshares supporter stated he dumped his BTSX because of it..

IMO it is important to keep bitUSD in BTSX but utilize it in Bitshares vote using atomic cross chain transactions. This way BTSX DAC shareholders don't feel robbed of their biggest feature. It is important that each DAC retain its value by not implementing DAC-specific features in each DAC, but still link them together for the same functionality.
Title: Re: Atomic Cross Chain Trading
Post by: bytemaster on October 18, 2014, 03:02:13 pm
You don't understand the issues involved.  Acct is not viable for anything but real time trades of bit usd between two chains
Title: Re: Atomic Cross Chain Trading
Post by: xeroc on October 18, 2014, 03:14:39 pm
So,it's technically impossible to spend BTSX-BitUSD on vote directly?
These are TWO different chains .. there is no such thing as a BTSX-bitUSD in the vote chain ..
Title: Re: Atomic Cross Chain Trading
Post by: jsidhu on October 18, 2014, 04:34:04 pm
Is this wat BM mentioned was going to be Turing complete so for example if you have an AUCTION Dac you can encode rules in the script to function as a auction with buy it now as a turing complete implementation using ACCT (auctions are represented in bitUSD)
Title: Re: Atomic Cross Chain Trading
Post by: theoretical on October 18, 2014, 09:11:19 pm
For those that did not attend the latest dev hangout, BM briefly explained how cross-chain trading would work.

Is this explanation somewhere online?

Anything I forgot to describe? Anything unclear?

The form of AXCT you describe requires both chains to implement the withdraw_password_type operation.  Thus it is only practical between two BitShares Toolkit chains.  A potential AXCT implementation would have more value if it supported coins such as BTC, LTC, DOGE, etc. (without requiring a hardfork in those non-BitShares Toolkit chains).

Another minor nitpick:  The described protocol is not truly atomic.  If Bob is offline between Alice revealing the password and the expiry of Alice's transaction, Alice may end up with both BTSX and DNS.  You can reduce (but not eliminate) this possibility by lengthening the time Bob would need to be offline for this to happen.

I have proposed a protocol which fixes the above deficiencies.  (emski independently developed an identical protocol.)  However my / our protocol imposes an additional requirement:  It requires a way for the network to "know" whether the delivery of the "foreign" currency occurred.  I.e. we (the BTSX network) need to know what happened on the foreign chain (the BTC network).

One way to satisfy this requirement is having delegates to monitor the foreign chain.  This is less than ideal:  (1) Supporting N altcoins would require the delegates to run N different clients; (2) You have the political problem of choosing which altcoins to support, (3) Fully auditing delegates' good behavior also requires N foreign clients, so you have the problem of either (4) Less thorough delegate auditing, or (5) Running N different clients on all nodes.

I've come up with a less centralized way to meet the requirement without too much burden; a way to make the network "know" what happened on the foreign chain.  However, I haven't written it up yet.  I think AXCT between BTSX and BTC would have some value.  It would make it easier to leverage existing BTC infrastructure.  For example, it would be fairly simple for a third party to use AXCT to build a translation app which allows using BitUSD to pay a specified number of Bitcoins to a specified Bitcoin address, e.g. paying a BitPay invoice [1] [2].

Also, if we have AXCT for DOGE <-> BTSX and BTSX <-> BTC, then essentially we can allow users to trade DOGE <-> BTC without trusting any fiduciary.  Making the "MtGox problem" a thing of the past.

In addition, I suspect a working, live implementation would get us a lot of attention; basically free marketing.

[1] With AXCT support for BitUSD -> BTC, this app would not require any fiduciary trust from the user.  Without AXCT, this app is still possible, but either the app must have API access to the user's account at bter or a similar fiduciary exchange, or the app maintainers must have fiduciary control of user funds.

[2] This app would provide value by (from the user's point of view) enabling every merchant who accepts BTC to also accept BitUSD, without any action on the part of the merchant.
Title: Re: Atomic Cross Chain Trading
Post by: Shentist on October 18, 2014, 09:51:08 pm
@drltc

i read you are a C++ coder?
do you think you can programm it?
i am interested to fund it if so.

maybe we could team up with emski to give it a shot?
Title: Re: Atomic Cross Chain Trading
Post by: jsidhu on October 18, 2014, 10:19:23 pm
For those that did not attend the latest dev hangout, BM briefly explained how cross-chain trading would work.

Is this explanation somewhere online?

Anything I forgot to describe? Anything unclear?

The form of AXCT you describe requires both chains to implement the withdraw_password_type operation.  Thus it is only practical between two BitShares Toolkit chains.  A potential AXCT implementation would have more value if it supported coins such as BTC, LTC, DOGE, etc. (without requiring a hardfork in those non-BitShares Toolkit chains).

Another minor nitpick:  The described protocol is not truly atomic.  If Bob is offline between Alice revealing the password and the expiry of Alice's transaction, Alice may end up with both BTSX and DNS.  You can reduce (but not eliminate) this possibility by lengthening the time Bob would need to be offline for this to happen.

I have proposed a protocol which fixes the above deficiencies.  (emski independently developed an identical protocol.)  However my / our protocol imposes an additional requirement:  It requires a way for the network to "know" whether the delivery of the "foreign" currency occurred.  I.e. we (the BTSX network) need to know what happened on the foreign chain (the BTC network).

One way to satisfy this requirement is having delegates to monitor the foreign chain.  This is less than ideal:  (1) Supporting N altcoins would require the delegates to run N different clients; (2) You have the political problem of choosing which altcoins to support, (3) Fully auditing delegates' good behavior also requires N foreign clients, so you have the problem of either (4) Less thorough delegate auditing, or (5) Running N different clients on all nodes.

I've come up with a less centralized way to meet the requirement without too much burden; a way to make the network "know" what happened on the foreign chain.  However, I haven't written it up yet.  I think AXCT between BTSX and BTC would have some value.  It would make it easier to leverage existing BTC infrastructure.  For example, it would be fairly simple for a third party to use AXCT to build a translation app which allows using BitUSD to pay a specified number of Bitcoins to a specified Bitcoin address, e.g. paying a BitPay invoice [1] [2].

Also, if we have AXCT for DOGE <-> BTSX and BTSX <-> BTC, then essentially we can allow users to trade DOGE <-> BTC without trusting any fiduciary.  Making the "MtGox problem" a thing of the past.

In addition, I suspect a working, live implementation would get us a lot of attention; basically free marketing.

[1] With AXCT support for BitUSD -> BTC, this app would not require any fiduciary trust from the user.  Without AXCT, this app is still possible, but either the app must have API access to the user's account at bter or a similar fiduciary exchange, or the app maintainers must have fiduciary control of user funds.

[2] This app would provide value by (from the user's point of view) enabling every merchant who accepts BTC to also accept BitUSD, without any action on the part of the merchant.

This sounds like an approach using oracles or n of m signers... I suggest to look at Automated Transactions or AT (http://ciyam.org/at)

atomic cross-chain transfers(network based) are possible across any block chain that implements the API.. also it is turing complete using a load/store style machine.
Title: Re: Atomic Cross Chain Trading
Post by: bernard on January 02, 2015, 02:49:05 am
Looks like the same design crispweed over on BTT came up with (and implemented) back in May: https://bitcointalk.org/index.php?topic=628547.0 (https://bitcointalk.org/index.php?topic=628547.0)

So is this "withdraw_password_type" tx already in BitShares and working? Theoretically we could do a BTSX to SwapBill trade as a test?
Title: Re: Atomic Cross Chain Trading
Post by: bluebit on January 02, 2015, 05:10:25 am
Anything I forgot to describe? Anything unclear?

I have a better idea:

Both Alice and Bob have their transactions ready to send, in whatever currency or asset. They send their transactions to a "node", node checks to makes sure both transactions are of equal value and if not node sends back the transactions to Alice and Bob. If both transactions are correct, both transactions are green lit and broadcast on the network.
Title: Re: Atomic Cross Chain Trading
Post by: crispweed on January 02, 2015, 08:57:25 am
Looks like the same design crispweed over on BTT came up with (and implemented) back in May: https://bitcointalk.org/index.php?topic=628547.0 (https://bitcointalk.org/index.php?topic=628547.0)

So is this "withdraw_password_type" tx already in BitShares and working? Theoretically we could do a BTSX to SwapBill trade as a test?

Hi there!

Yes, this is the same algorithm as is used for cross chain exchange in SwapBill.

You can find some more discussion about this on this blog post:
http://upcoder.com/11/atomic-cross-chain-exchange/

The key point, I think, is to try and standardise on a good secret hashing function.

SwapBill is currently *live* on the bitcoin and litecoin testnets, and yes, it would be very cool if you want to try out exchanges against this.

Just shout if you need some help setting this up..
Title: Re: Atomic Cross Chain Trading
Post by: bernard on January 02, 2015, 12:49:09 pm
I just fired up the gui client and could not find the "withdraw_password_type" in the console screen.

Where can I find it?
Title: Re: Atomic Cross Chain Trading
Post by: xeroc on January 03, 2015, 12:56:30 pm
Its implemented in the blockchain protocol ... no client api there yet .. sadly
Title: Re: Atomic Cross Chain Trading
Post by: vikram on January 06, 2015, 07:29:01 pm
Its implemented in the blockchain protocol ... no client api there yet .. sadly

This is not true--please see: https://bitsharestalk.org/index.php?topic=12813.msg170505#msg170505