decred / dcrdex

The Decred Decentralized Exchange (DEX), powered by atomic-swaps.
Other
184 stars 92 forks source link

Replace txid/vout with coin ID #75

Closed buck54321 closed 4 years ago

buck54321 commented 4 years ago

One of the only respectable technical critiques the DEX spec has gotten came in an article by the Komodo AtomicDEX team.

It's a rudimentary atomic swap implementation because it currently only supports assets of the Bitcoin protocol.

... the protocol only supports UTXO-based assets. Whereas most hybrid DEX protocols only support Ether and ERC tokens, limiting their capabilities, the Decred DEX falls on the opposite side of the fence but runs into the same problem— only supporting UTXO coins excludes support for the Ethereum ecosystem, as well as a number of other prominent blockchain protocols and platforms.

The valid part is that as specified, Decred DEX seems like it will only work with UTXO-based assets. But here's the thing. There is no fundamental barrier to supporting trades with ETH-based assets and probably others. With a general enough API, we can accomodate virtually any asset that supports some equivalent of hash time locked contracts. And while I'm not suggesting that we should put our efforts towards this work right now, getting the API correct now greatly eases our pains in the future.

What I'm proposing here is that we replace every txid-vout pair in the specification with a single parameter called coin ID, coin being a general term here meaning some discrete amount of unspent asset identifiable on the blockchain. It is represented as a byte array. The backends and wallets for each asset can encode and decode whatever identifying information is needed in the coin ID. For the assets we are implementing now, it will likely be just the concatenated transaction hash and big-endian 32-bit vout.

Coincidentally, this resolves some questions we had earlier on how best to serialize the transaction ID, since the backends are probably byte-reversing the transaction hash. The answer, I'm hoping, is that the DEX doesn't need to concern itself with such details if you just give it a byte array.

This change also simplifies a lot of things internally for the DEX. Two columns become one in some tables, two arguments become one in some functions, two fields become one in some types. Outside of the asset backends, the DEX itself never has to decode the coin ID.

chappjc commented 4 years ago

coin ID, coin being a general term here meaning some discrete amount of unspent asset identifiable on the blockchain. It is represented as a byte array.

We've discussed this in Matrix, and I agree this is a reasonable approach that will generalize the DEX's handling of unspent assets for backing a swap. We should go forward with this change (replacing UTXO with CoinID).

chappjc commented 4 years ago

Resolved by https://github.com/decred/dcrdex/pull/91