From 5c3233ce9181ae2e98b40b0fab913bbbc8a421b1 Mon Sep 17 00:00:00 2001 From: Valeriy Gavrilin Date: Thu, 18 Apr 2019 15:33:20 +0300 Subject: [PATCH 1/6] R4D mixer script example --- ride4dapps/mixer/README.md | 11 +++++++++++ ride4dapps/mixer/mixer.ride | 36 ++++++++++++++++++++++++++++++++++ ride4dapps/mixer/mixer_test.js | 18 +++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 ride4dapps/mixer/README.md create mode 100644 ride4dapps/mixer/mixer.ride create mode 100644 ride4dapps/mixer/mixer_test.js diff --git a/ride4dapps/mixer/README.md b/ride4dapps/mixer/README.md new file mode 100644 index 0000000..1fdcef3 --- /dev/null +++ b/ride4dapps/mixer/README.md @@ -0,0 +1,11 @@ +# R4D Mixer +This is an example of crypto coins mixer + +1. A user can send money with an arbitrary Blake2b256 hash +2. After that, anyone with address matching that hash and knowing how much bytes of address used can take the money back + +Try now: https://cb73ac4e-d39f-4a9f-a196-3c46b445f8fe.pub.cloud.scaleway.com/ (Requires Waves Keeper with InvokeScript support in TESTNET mode) + +# Example +1. Taken destination address is `3Musn2zFuw3G71yg6G7PDRAq7CjWxK7Z4pk` and complexity is 3, caller takes first 3 and last 3 bytes of it: `3Mu + 4pk`, hashes it with Blake2b256 and invokes `deposit(hash)` with attached Waves payment +2. Then owner of `3Musn2zFuw3G71yg6G7PDRAq7CjWxK7Z4pk` invokes `withdraw(3)`, script compares his address with stored hash and withdraws all money associated with it diff --git a/ride4dapps/mixer/mixer.ride b/ride4dapps/mixer/mixer.ride new file mode 100644 index 0000000..03ddda7 --- /dev/null +++ b/ride4dapps/mixer/mixer.ride @@ -0,0 +1,36 @@ +{-# STDLIB_VERSION 3 #-} +{-# CONTENT_TYPE DAPP #-} +{-# SCRIPT_TYPE ACCOUNT #-} + +let FeePercent = 1 + +@Callable(i) +func deposit(hash: ByteVector) = { + let pmt = extract(i.payment) + if (isDefined(pmt.assetId) || pmt.amount < 100) then throw("can hold waves only at the moment") + else { + let currentKey = toBase58String(hash) + let currentAmount = match getInteger(this, currentKey) { + case a:Int => a + case _ => 0 + } + let fee = pmt.amount * FeePercent / 100 + let newAmount = currentAmount + pmt.amount - fee + WriteSet([DataEntry(currentKey, newAmount)]) + } +} + +@Callable(i) +func withdraw(complexity: Int) = { + let currentKey = toBase58String(blake2b256(take(drop(i.caller.bytes, 2), complexity) + takeRight(i.caller.bytes, complexity))) + let amount = match getInteger(this, currentKey) { + case a:Int => a + case _ => 0 + } + if (amount <= 0) + then throw("Can't withdraw negative amount") + else ScriptResult( + WriteSet([DataEntry(currentKey, 0)]), + TransferSet([ScriptTransfer(i.caller, amount, unit)]) + ) +} diff --git a/ride4dapps/mixer/mixer_test.js b/ride4dapps/mixer/mixer_test.js new file mode 100644 index 0000000..9710128 --- /dev/null +++ b/ride4dapps/mixer/mixer_test.js @@ -0,0 +1,18 @@ +describe('Mixer test', () => { + const dappAddress = "3Musn2zFuw3G71yg6G7PDRAq7CjWxK7Z4pk" + + const hash = "8N5gCoRKcCD4BxJNGn2kKUzMBieetEh4r7DUMHa1m2gq" + + it('Deposit funds', async function(){ + const tx = invokeScript({ fee: 500000, dappAddress: dappAddress, call:{function:"deposit",args:[{"type": "binary", "value": hash}]}, + payment: [{amount: 1000000, assetId: null}]}) + await broadcast(tx) + await waitForTx(tx.id) + }) + + it('Withdraw funds', async function(){ + const tx = invokeScript({ fee: 500000, dappAddress: dappAddress, call:{function:"withdraw",args:[{"type": "integer", "value": 3}]}, payment: null) + await broadcast(tx) + await waitForTx(tx.id) + }) +}) From 11429f78e1e04b2821e272d07029d85473a303ed Mon Sep 17 00:00:00 2001 From: Valeriy Gavrilin Date: Thu, 18 Apr 2019 15:48:44 +0300 Subject: [PATCH 2/6] R4D mixer script example --- ride4dapps/mixer/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ride4dapps/mixer/README.md b/ride4dapps/mixer/README.md index 1fdcef3..1ac20b5 100644 --- a/ride4dapps/mixer/README.md +++ b/ride4dapps/mixer/README.md @@ -1,5 +1,5 @@ # R4D Mixer -This is an example of crypto coins mixer +This is an example of the crypto coins mixer 1. A user can send money with an arbitrary Blake2b256 hash 2. After that, anyone with address matching that hash and knowing how much bytes of address used can take the money back @@ -9,3 +9,6 @@ Try now: https://cb73ac4e-d39f-4a9f-a196-3c46b445f8fe.pub.cloud.scaleway.com/ (R # Example 1. Taken destination address is `3Musn2zFuw3G71yg6G7PDRAq7CjWxK7Z4pk` and complexity is 3, caller takes first 3 and last 3 bytes of it: `3Mu + 4pk`, hashes it with Blake2b256 and invokes `deposit(hash)` with attached Waves payment 2. Then owner of `3Musn2zFuw3G71yg6G7PDRAq7CjWxK7Z4pk` invokes `withdraw(3)`, script compares his address with stored hash and withdraws all money associated with it +3. You can tune complexity from 1 to 9 + 1. With low complexity everyone can generate address that matches the resulting hash, but then no one can prove that you took the money + 2. So with complexity = 9 address should match exactly, and it's safe but there is no [plausible deniability](https://en.wikipedia.org/wiki/Plausible_deniability) From 84fe8de8c226c8a11194a8b9098325e5af540b34 Mon Sep 17 00:00:00 2001 From: Le Karasique Date: Wed, 5 Jun 2019 18:48:55 +0300 Subject: [PATCH 3/6] Update mixer_test.js --- ride4dapps/mixer/mixer_test.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/ride4dapps/mixer/mixer_test.js b/ride4dapps/mixer/mixer_test.js index 9710128..22c3eed 100644 --- a/ride4dapps/mixer/mixer_test.js +++ b/ride4dapps/mixer/mixer_test.js @@ -1,18 +1,12 @@ describe('Mixer test', () => { - const dappAddress = "3Musn2zFuw3G71yg6G7PDRAq7CjWxK7Z4pk" + const dappAddress = "3N3st6Cp9ZLz8kmT33EY41AVjwKqBVebvyq" - const hash = "8N5gCoRKcCD4BxJNGn2kKUzMBieetEh4r7DUMHa1m2gq" + const hash = "8N5gCoRKcCD4BxJNGn2kKUzMBieetEh4r7DUMHa1m2gq" - it('Deposit funds', async function(){ - const tx = invokeScript({ fee: 500000, dappAddress: dappAddress, call:{function:"deposit",args:[{"type": "binary", "value": hash}]}, - payment: [{amount: 1000000, assetId: null}]}) - await broadcast(tx) - await waitForTx(tx.id) - }) - - it('Withdraw funds', async function(){ - const tx = invokeScript({ fee: 500000, dappAddress: dappAddress, call:{function:"withdraw",args:[{"type": "integer", "value": 3}]}, payment: null) - await broadcast(tx) - await waitForTx(tx.id) - }) -}) + it('Deposit funds', async function(){ + const tx = invokeScript({ fee: 900000, dApp: dappAddress, call:{function:"deposit",args:[{"type": "binary", "value": hash}]}, + payment: [{amount: 1000000, assetId: null}]}) + await broadcast(tx) + await waitForTx(tx.id) + }) + }) From ebfa9857d68d82bdc2d50a9599021cee1c7821c4 Mon Sep 17 00:00:00 2001 From: Le Karasique Date: Tue, 25 Jun 2019 17:12:11 +0300 Subject: [PATCH 4/6] Update mixer_test.js --- ride4dapps/mixer/mixer_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ride4dapps/mixer/mixer_test.js b/ride4dapps/mixer/mixer_test.js index 22c3eed..e2c0e1a 100644 --- a/ride4dapps/mixer/mixer_test.js +++ b/ride4dapps/mixer/mixer_test.js @@ -1,5 +1,5 @@ describe('Mixer test', () => { - const dappAddress = "3N3st6Cp9ZLz8kmT33EY41AVjwKqBVebvyq" + const dappAddress = "3MwmaLMtWTaTyjhzywLLRQa4BH1PYZdvpKy" const hash = "8N5gCoRKcCD4BxJNGn2kKUzMBieetEh4r7DUMHa1m2gq" From cbea62e0e5330b3dc8535d520e99d9c19c2e0c05 Mon Sep 17 00:00:00 2001 From: Le Karasique Date: Wed, 26 Jun 2019 14:04:08 +0300 Subject: [PATCH 5/6] Update README.md --- ride4dapps/mixer/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ride4dapps/mixer/README.md b/ride4dapps/mixer/README.md index 1ac20b5..2727294 100644 --- a/ride4dapps/mixer/README.md +++ b/ride4dapps/mixer/README.md @@ -4,7 +4,7 @@ This is an example of the crypto coins mixer 1. A user can send money with an arbitrary Blake2b256 hash 2. After that, anyone with address matching that hash and knowing how much bytes of address used can take the money back -Try now: https://cb73ac4e-d39f-4a9f-a196-3c46b445f8fe.pub.cloud.scaleway.com/ (Requires Waves Keeper with InvokeScript support in TESTNET mode) +Try now: https://chat.waves.today (Requires Waves Keeper with InvokeScript support **in TESTNET mode**) # Example 1. Taken destination address is `3Musn2zFuw3G71yg6G7PDRAq7CjWxK7Z4pk` and complexity is 3, caller takes first 3 and last 3 bytes of it: `3Mu + 4pk`, hashes it with Blake2b256 and invokes `deposit(hash)` with attached Waves payment From 2f8e97b1e2a884b1b18904cc2e5cd97fdf382874 Mon Sep 17 00:00:00 2001 From: Le Karasique Date: Wed, 26 Jun 2019 14:04:23 +0300 Subject: [PATCH 6/6] Update README.md --- ride4dapps/mixer/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ride4dapps/mixer/README.md b/ride4dapps/mixer/README.md index 2727294..a641a8c 100644 --- a/ride4dapps/mixer/README.md +++ b/ride4dapps/mixer/README.md @@ -4,7 +4,7 @@ This is an example of the crypto coins mixer 1. A user can send money with an arbitrary Blake2b256 hash 2. After that, anyone with address matching that hash and knowing how much bytes of address used can take the money back -Try now: https://chat.waves.today (Requires Waves Keeper with InvokeScript support **in TESTNET mode**) +Try now: https://mixer.waves.today (Requires Waves Keeper with InvokeScript support **in TESTNET mode**) # Example 1. Taken destination address is `3Musn2zFuw3G71yg6G7PDRAq7CjWxK7Z4pk` and complexity is 3, caller takes first 3 and last 3 bytes of it: `3Mu + 4pk`, hashes it with Blake2b256 and invokes `deposit(hash)` with attached Waves payment