Previous threads:
https://bitcointalk.org/index.php?topic=1340621.msg13828271#msg13828271
https://bitcointalk.org/index.php?topic=1364951
describe the atomic cross chain protocol, which I now have pretty much working on top of iguanacore. Still need to verify the blockchain's will accept the tx, but from order propagation, order match, protocol negotiation are all working, even most of the one party disconnects case. However I still have to add more validations of the rawtx data to make sure it matches the expected values, but for testing the basics, enough is working now.
Before even the fee tx are made, both sides go through a "cut and choose" protocol. Basically it is like shuffling a deck of cards and having the other side choose one. In order to prevent cheating, all the cards that were not chosen are revealed to the other side. In this case, the "card" is actually a keypair used for creating the transactions, both as reveal secret and 2of2 multisig. The fee is set to 1/777'th of the transaction value and 1000 keypairs are used, so if the someone tries to cheat and get away with a free ride, then will end up paying 1000 fees of 1/777 = 1000/777 = 28.7% penalty. Another attempt at cheating would be to put up a deposit and not go through with the trade, but in this case the other party gets to claim the deposit, which is 10% more than the trade value.
alice starts the process by issuing an API call using curl:
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"BTCD\",\"amount\":1,\"dest\":\"BTC\",\"minprice\":0.0025}}"
It is a request to convert 1 BTCD into BTC, with a minimum price of 0.0025
I have one of the relay servers setup to respond to incoming requests and if it finds one it can satisfy, it sends back a quote based on the current prices available on central exchanges. It adds a 1% profit margin and makes sure it is above the minimum price.
[(BTCD 1.00000000) -> (BTC 0.00000000) r.1555902389 q.0] destamount 0.00311118 aveprice 0.00314261 minamount 0.00250000
this starts the back and forth process that leads to:
ALICE:
0100000025797e57010acd55e30647957397faccb371031a54583b1f0ef6a74da494308cdefcf7899f020000006a473044022078dc07bb1a5052b6c3be55f3b0dbf215bccf53c2fe96214f7f631bf812dbb954022033381fcb1ed57024a6b55d9dde5c949a1c779e5588ba5582eca2b40760dbbdc4012103377aea6f477582332f128acb197b9f463b5262571d23afaa113dfab48753e3cdffffffff02a0860100000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac7053883b000000001976a914c210f6711e98fe9971757ede2b2dcb0507f3f25e88ac00000000 <- sendrawtransaction alicefee.(4bc6dc649ce823463b833ad19489e56aac7768bc50c5a65fad628fb3bf62d0f1)
BOB:
01000000011501573db522fad7c2597a91c725c6d0988fe4a7c9f038847ac37ec1af8646e3010000006a473044022059a71e3cc249b6cce290b506991b79e1189e2184c7804ac5163d8bb9696d337b022030e9894f2bca492e0331cf3e2682fe16d8437f8c7d0a20d225223f77afdb6b12012103958f90717f04239331a532353cebaf973025ea6586cbe70d70673ed025c2eb51ffffffff0210270000000000001976a914daedddd8dbe7a2439841ced40ba9c3d375f9814688ac20f40e00000000001976a914a8f1248b3c22b3a53855e3a47759ca05fadf741888ac00000000 <- sendrawtransaction bobfee.(fce96811a213f7453a231f677969877ca26be63c44bd9d4c6c8ce01e0a353869)
04000000011501573db522fad7c2597a91c725c6d0988fe4a7c9f038847ac37ec1af8646e3010000006a473044022100ccade6ded0e435581e942538262521b4ad1d4d5cdb34e477fb6d4d40f2c8aa14021f5ff51e3b8fd7df79894359fc287bf95dff791d71881f0835f9fa1f1e911f56012103958f90717f04239331a532353cebaf973025ea6586cbe70d70673ed025c2eb51ffffffff02d538050000000000676304808b7e57b1752102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac67a914fc2fb2cc391fd04fdf23975fe10942480d4dbf6d882103a7b696908f77d69ec89887f8c4a0423b9e80b5974dc43301bd7d8abad07e1211ac685be20900000000001976a914a8f1248b3c22b3a53855e3a47759ca05fadf741888ac808b7e57 <- sendrawtransaction bobdeposit.(0c7eec2f0b5f66e0a70364cf98fe3c3154b52dc4292fe2594dcbdee6fe36fa8d)
ALICE:
verifies the deposit is proper and sends:
0100000025797e57010acd55e30647957397faccb371031a54583b1f0ef6a74da494308cdefcf7899f020000006a4730440220360dafed37ab3d40d40f8badca8639fc20e9592825107006f0b7e8246c9837da022030cf6fcebd312aac0224a9196b50b2f9683004b34c4f01fc469e80a4681739c3012103377aea6f477582332f128acb197b9f463b5262571d23afaa113dfab48753e3cdffffffff0200e1f505000000004752210262389d35fab6a1ea8b776dae511126e8b4f9e6a2999604f300cb038c628923982103d65501ab7adc65e88b29cc7bca32af3bac9b2e4d0b44e2a574a6d02185b2264c52ae10f99335000000001976a914c210f6711e98fe9971757ede2b2dcb0507f3f25e88ac00000000 <- sendrawtransaction alicepayment.(802f91a8db3a4357fb24c31410301315fc982b7e0cefe376e318af11de4ae000)
BOB:
verifies the payment and sends his payment:
04000000011501573db522fad7c2597a91c725c6d0988fe4a7c9f038847ac37ec1af8646e3010000006a47304402203c1eee1d939f672e2f805b5dcf48b6b5ee877140c6ccf07f2e00a98143fdf40302206e3bf240767eddef63a17e38076a7f684ed70f0a0fe6e945626d7447e1d4c420012103958f90717f04239331a532353cebaf973025ea6586cbe70d70673ed025c2eb51ffffffff024ebf04000000000067630420827e57b17521034924708e5d3b76f695530f3e8dd28297565177882247c4829b56c7db33abcddaac67a914d0e187a0b07b3a36517f3f2517ab88359f58456c882102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac68e25b0a00000000001976a914a8f1248b3c22b3a53855e3a47759ca05fadf741888ac20827e57 <- sendrawtransaction bobpayment.(ebff5b4517f62f0cf4fbeda4d264f12460a3f5bd3584652f4d3d89ff1da25508)
ALICE:
gets bob's payment and spends it (thus revealing the secret bob needs)
04000000010855a21dff893d4d2f658435bdf5a36024f164d2a4edfbf40c2ff617455bffeb000000006b48304502210089f9026fe6618a9893bdfe7555783d57e98371139a155725ed7a818dee14915f022013bcfd69c5893a508f3a2abb63919a1cbd0603abc4a8f08587bfe4871d586634012102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdffffffff013e980400000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000 <- sendrawtransaction alicespend.(9a243fd64f7693ece5120a91514b94ff1656ff0a6d406544383416d48db65219)
BOB:
uses the secret to spend his half and gets refund of deposit
0400000014847e5701f5974873838847700d449e33ab037bc6a2100b8be47b4134fb756bd3ca26e7f200000000d648304502210090e186ab2645383feedc1e6ec66c0f786a0a4cb1e339d253129f27ca873f269602200cef8fefa7f5dfbf9ee1400e3bb056796b22f2ba29791d19592079b199722da101483045022100c95d1ae2c03666eb0f6541aad7d58ff08318f49f20592332c60b3eff6f7e857502204393773a7bd7bac011b60e1854c15462bdb4ca979f1a3e3767bcd0368dd509ff0121021510cb0f068ef50d47def117dd9119b2d218669daf1bbe0c4590ed9b797940a821038bc06ee1f3209ce1603985985b7fe82b0488f6e871f9a8476d0e06506a046281ffffffff01f0b9f505000000001976a9143ef4734c1141725c095342095f6e0e7748b6c16588ac00000000 <- sendrawtransaction bobspend.(1e1797ccd806dc1547566a9c03aaa2541c844a5caba680bdc7343d9b55fbe674)
04000000018dfa36fee6decb4d59e22f29c42db554313cfe98cf6403a7e0665f0b2fec7e0c000000006a47304402207bd38ffb34aa7da647c4842a01cd9bf04be1f38057fe8f98246395e839b1d0160220189f1521bf93abf7497152668e9da8d09db15803fcad365a211dfcf486a6e6ee012103a7b696908f77d69ec89887f8c4a0423b9e80b5974dc43301bd7d8abad07e1211ffffffff01c5110500000000001976a9143ef4734c1141725c095342095f6e0e7748b6c16588ac00000000 <- sendrawtransaction bobrefund.(92e349bd2435c52d1b78efa3f4153126536cdb1a0e19b5d6707f0f76b804dcac)
I wanted to have a single place to describe how a decentralized shapeshift functionality is created on top of the atomic cross chain protocol. more after I enable and test the actual broadcasting of the signed transactions. The above is the simplest case, but I have seen most of the non-completion states during testing, so even if some issues I dont see it as too much work to get it all fixed. Getting complete test results is the next step after verifying these tx will actually confirm.
hope to post more details soon
https://bitcointalk.org/index.php?topic=1340621.msg13828271#msg13828271
https://bitcointalk.org/index.php?topic=1364951
describe the atomic cross chain protocol, which I now have pretty much working on top of iguanacore. Still need to verify the blockchain's will accept the tx, but from order propagation, order match, protocol negotiation are all working, even most of the one party disconnects case. However I still have to add more validations of the rawtx data to make sure it matches the expected values, but for testing the basics, enough is working now.
Before even the fee tx are made, both sides go through a "cut and choose" protocol. Basically it is like shuffling a deck of cards and having the other side choose one. In order to prevent cheating, all the cards that were not chosen are revealed to the other side. In this case, the "card" is actually a keypair used for creating the transactions, both as reveal secret and 2of2 multisig. The fee is set to 1/777'th of the transaction value and 1000 keypairs are used, so if the someone tries to cheat and get away with a free ride, then will end up paying 1000 fees of 1/777 = 1000/777 = 28.7% penalty. Another attempt at cheating would be to put up a deposit and not go through with the trade, but in this case the other party gets to claim the deposit, which is 10% more than the trade value.
alice starts the process by issuing an API call using curl:
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"BTCD\",\"amount\":1,\"dest\":\"BTC\",\"minprice\":0.0025}}"
It is a request to convert 1 BTCD into BTC, with a minimum price of 0.0025
I have one of the relay servers setup to respond to incoming requests and if it finds one it can satisfy, it sends back a quote based on the current prices available on central exchanges. It adds a 1% profit margin and makes sure it is above the minimum price.
[(BTCD 1.00000000) -> (BTC 0.00000000) r.1555902389 q.0] destamount 0.00311118 aveprice 0.00314261 minamount 0.00250000
this starts the back and forth process that leads to:
ALICE:
0100000025797e57010acd55e30647957397faccb371031a54583b1f0ef6a74da494308cdefcf7899f020000006a473044022078dc07bb1a5052b6c3be55f3b0dbf215bccf53c2fe96214f7f631bf812dbb954022033381fcb1ed57024a6b55d9dde5c949a1c779e5588ba5582eca2b40760dbbdc4012103377aea6f477582332f128acb197b9f463b5262571d23afaa113dfab48753e3cdffffffff02a0860100000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ac7053883b000000001976a914c210f6711e98fe9971757ede2b2dcb0507f3f25e88ac00000000 <- sendrawtransaction alicefee.(4bc6dc649ce823463b833ad19489e56aac7768bc50c5a65fad628fb3bf62d0f1)
BOB:
01000000011501573db522fad7c2597a91c725c6d0988fe4a7c9f038847ac37ec1af8646e3010000006a473044022059a71e3cc249b6cce290b506991b79e1189e2184c7804ac5163d8bb9696d337b022030e9894f2bca492e0331cf3e2682fe16d8437f8c7d0a20d225223f77afdb6b12012103958f90717f04239331a532353cebaf973025ea6586cbe70d70673ed025c2eb51ffffffff0210270000000000001976a914daedddd8dbe7a2439841ced40ba9c3d375f9814688ac20f40e00000000001976a914a8f1248b3c22b3a53855e3a47759ca05fadf741888ac00000000 <- sendrawtransaction bobfee.(fce96811a213f7453a231f677969877ca26be63c44bd9d4c6c8ce01e0a353869)
04000000011501573db522fad7c2597a91c725c6d0988fe4a7c9f038847ac37ec1af8646e3010000006a473044022100ccade6ded0e435581e942538262521b4ad1d4d5cdb34e477fb6d4d40f2c8aa14021f5ff51e3b8fd7df79894359fc287bf95dff791d71881f0835f9fa1f1e911f56012103958f90717f04239331a532353cebaf973025ea6586cbe70d70673ed025c2eb51ffffffff02d538050000000000676304808b7e57b1752102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac67a914fc2fb2cc391fd04fdf23975fe10942480d4dbf6d882103a7b696908f77d69ec89887f8c4a0423b9e80b5974dc43301bd7d8abad07e1211ac685be20900000000001976a914a8f1248b3c22b3a53855e3a47759ca05fadf741888ac808b7e57 <- sendrawtransaction bobdeposit.(0c7eec2f0b5f66e0a70364cf98fe3c3154b52dc4292fe2594dcbdee6fe36fa8d)
ALICE:
verifies the deposit is proper and sends:
0100000025797e57010acd55e30647957397faccb371031a54583b1f0ef6a74da494308cdefcf7899f020000006a4730440220360dafed37ab3d40d40f8badca8639fc20e9592825107006f0b7e8246c9837da022030cf6fcebd312aac0224a9196b50b2f9683004b34c4f01fc469e80a4681739c3012103377aea6f477582332f128acb197b9f463b5262571d23afaa113dfab48753e3cdffffffff0200e1f505000000004752210262389d35fab6a1ea8b776dae511126e8b4f9e6a2999604f300cb038c628923982103d65501ab7adc65e88b29cc7bca32af3bac9b2e4d0b44e2a574a6d02185b2264c52ae10f99335000000001976a914c210f6711e98fe9971757ede2b2dcb0507f3f25e88ac00000000 <- sendrawtransaction alicepayment.(802f91a8db3a4357fb24c31410301315fc982b7e0cefe376e318af11de4ae000)
BOB:
verifies the payment and sends his payment:
04000000011501573db522fad7c2597a91c725c6d0988fe4a7c9f038847ac37ec1af8646e3010000006a47304402203c1eee1d939f672e2f805b5dcf48b6b5ee877140c6ccf07f2e00a98143fdf40302206e3bf240767eddef63a17e38076a7f684ed70f0a0fe6e945626d7447e1d4c420012103958f90717f04239331a532353cebaf973025ea6586cbe70d70673ed025c2eb51ffffffff024ebf04000000000067630420827e57b17521034924708e5d3b76f695530f3e8dd28297565177882247c4829b56c7db33abcddaac67a914d0e187a0b07b3a36517f3f2517ab88359f58456c882102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac68e25b0a00000000001976a914a8f1248b3c22b3a53855e3a47759ca05fadf741888ac20827e57 <- sendrawtransaction bobpayment.(ebff5b4517f62f0cf4fbeda4d264f12460a3f5bd3584652f4d3d89ff1da25508)
ALICE:
gets bob's payment and spends it (thus revealing the secret bob needs)
04000000010855a21dff893d4d2f658435bdf5a36024f164d2a4edfbf40c2ff617455bffeb000000006b48304502210089f9026fe6618a9893bdfe7555783d57e98371139a155725ed7a818dee14915f022013bcfd69c5893a508f3a2abb63919a1cbd0603abc4a8f08587bfe4871d586634012102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdffffffff013e980400000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000 <- sendrawtransaction alicespend.(9a243fd64f7693ece5120a91514b94ff1656ff0a6d406544383416d48db65219)
BOB:
uses the secret to spend his half and gets refund of deposit
0400000014847e5701f5974873838847700d449e33ab037bc6a2100b8be47b4134fb756bd3ca26e7f200000000d648304502210090e186ab2645383feedc1e6ec66c0f786a0a4cb1e339d253129f27ca873f269602200cef8fefa7f5dfbf9ee1400e3bb056796b22f2ba29791d19592079b199722da101483045022100c95d1ae2c03666eb0f6541aad7d58ff08318f49f20592332c60b3eff6f7e857502204393773a7bd7bac011b60e1854c15462bdb4ca979f1a3e3767bcd0368dd509ff0121021510cb0f068ef50d47def117dd9119b2d218669daf1bbe0c4590ed9b797940a821038bc06ee1f3209ce1603985985b7fe82b0488f6e871f9a8476d0e06506a046281ffffffff01f0b9f505000000001976a9143ef4734c1141725c095342095f6e0e7748b6c16588ac00000000 <- sendrawtransaction bobspend.(1e1797ccd806dc1547566a9c03aaa2541c844a5caba680bdc7343d9b55fbe674)
04000000018dfa36fee6decb4d59e22f29c42db554313cfe98cf6403a7e0665f0b2fec7e0c000000006a47304402207bd38ffb34aa7da647c4842a01cd9bf04be1f38057fe8f98246395e839b1d0160220189f1521bf93abf7497152668e9da8d09db15803fcad365a211dfcf486a6e6ee012103a7b696908f77d69ec89887f8c4a0423b9e80b5974dc43301bd7d8abad07e1211ffffffff01c5110500000000001976a9143ef4734c1141725c095342095f6e0e7748b6c16588ac00000000 <- sendrawtransaction bobrefund.(92e349bd2435c52d1b78efa3f4153126536cdb1a0e19b5d6707f0f76b804dcac)
I wanted to have a single place to describe how a decentralized shapeshift functionality is created on top of the atomic cross chain protocol. more after I enable and test the actual broadcasting of the signed transactions. The above is the simplest case, but I have seen most of the non-completion states during testing, so even if some issues I dont see it as too much work to get it all fixed. Getting complete test results is the next step after verifying these tx will actually confirm.
hope to post more details soon