`
+1. `vi .env` - add your Kovan private key to deploy contracts
+1. `npm run migrate`
+1. `npx http-server` - serve current dir, you can use any other http server
+1. Open `localhost:8080`
+
+## Credits
+
+Special thanks to @barryWhiteHat and @kobigurk for valuable input,
+and to @jbaylina for awesome [Circom](https://github.com/iden3/circom) & [Websnark](https://github.com/iden3/websnark) framework
diff --git a/cli.js b/cli.js
index 9f4edbd..be4bd69 100755
--- a/cli.js
+++ b/cli.js
@@ -1,4 +1,5 @@
#!/usr/bin/env node
+// Temporary demo client
const fs = require('fs')
const assert = require('assert')
const snarkjs = require('snarkjs')
@@ -68,8 +69,10 @@ async function withdraw(note, receiver) {
}
console.log('Generating SNARK proof')
+ console.time('Proof time')
const proof = await websnarkUtils.genWitnessAndProve(groth16, input, circuit, proving_key)
const { pi_a, pi_b, pi_c, publicSignals } = websnarkUtils.toSolidityInput(proof)
+ console.timeEnd('Proof time')
console.log('Submitting withdraw transaction')
await mixer.methods.withdraw(pi_a, pi_b, pi_c, publicSignals).send({ from: (await web3.eth.getAccounts())[0], gas: 1e6 })
diff --git a/index.html b/index.html
index eeea218..359c20b 100644
--- a/index.html
+++ b/index.html
@@ -7,6 +7,7 @@
Open dev console!
+ Make sure your Metamask is unlocked and connected to Kovan (or other network you've deployed your contract to)
Deposit
Withdraw
diff --git a/mixer.png b/mixer.png
new file mode 100644
index 0000000..70491ff
Binary files /dev/null and b/mixer.png differ
diff --git a/relay/relay.js b/relay/relay.js
index 044824a..dee03ac 100644
--- a/relay/relay.js
+++ b/relay/relay.js
@@ -1,19 +1,24 @@
-let bigInt = require('snarkjs/src/bigint')
+// This is still WiP
+const bigInt = require('snarkjs/src/bigint')
const utils = require('../scripts/utils')
const express = require('express')
const app = express()
app.use(express.json())
+// todo get from config
+const RPC_ENDPOINT = 'http://localhost:8545'
+const NET_ID = 42
+// const PRIVATE_KEY = ''
+
const Web3 = require('web3')
-const web3 = new Web3('http://localhost:8545', null, { transactionConfirmationBlocks: 1 })
+const web3 = new Web3(RPC_ENDPOINT, null, { transactionConfirmationBlocks: 1 })
const contractJson = require('../build/contracts/Mixer.json')
-let netId = 42
-const mixer = new web3.eth.Contract(contractJson.abi, contractJson.networks[netId].address)
+const mixer = new web3.eth.Contract(contractJson.abi, contractJson.networks[NET_ID].address)
function getMinimumFee() {
// todo calc acceptable fee
- return 1e16
+ return bigInt(1e16)
}
app.post('/deposit', async (req, resp) => {
@@ -31,9 +36,17 @@ app.post('/deposit', async (req, resp) => {
}
try {
- let receipt = await mixer.withdraw(proof.pi_a, proof.pi_b, proof.pi_b, proof.publicSignals)
- console.log(receipt)
- resp.send({ transaction: receipt.transactionHash })
+ const gas = await mixer.withdraw(proof.pi_a, proof.pi_b, proof.pi_b, proof.publicSignals).estimateGas()
+ if (gas > 1e6) {
+ // something is wrong
+ }
+ const result = mixer.withdraw(proof.pi_a, proof.pi_b, proof.pi_b, proof.publicSignals).send()
+ result.once('transactionHash', function(hash){
+ resp.send({ transaction: hash })
+ }).on('error', function(e){
+ console.log(e)
+ resp.status(400).send('Transaction was reverted')
+ })
} catch (e) {
console.log(e)
resp.status(400).send('Transaction was reverted')