Skip to content

Commit

Permalink
Merge pull request #16 from kendricktan/enhancements
Browse files Browse the repository at this point in the history
Enhancements To Relayer
  • Loading branch information
kendricktan committed Jul 23, 2019
2 parents 4166e54 + 4096e27 commit 61901f0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -10,9 +10,9 @@

Heiswap (黑 swap) is an Ethereum transaction mixer that ultilizes parts of [CryptoNote](https://cryptonote.org) to enable zero-knowledge transactions.

It ulitilizes Ring Signatures and pseudo-stealth addresses to achieve its zero-knowledge properties. The [deployed smart contract](https://ropsten.etherscan.io/address/0xbbbf35a4485992520557ae729e21ba35aab178d7) handles the signature verification, while the client is responsible for generating the pseudo-stealth address.
It ulitilizes Ring Signatures and pseudo-stealth addresses to achieve its zero-knowledge properties. The [deployed smart contract](https://ropsten.etherscan.io/address/0x8AAbE42EeCA45E040fab330fD24eA6746b832Ad2) handles the signature verification, while the client is responsible for generating the pseudo-stealth address.

Ring signatures was only possible on the EVM (gas-wise) due to the recent addition of [EIP198](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-198.md).
Ring signatures was only possible on the EVM (gas-wise) due to the recent addition of [EIP198](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-198.md) and [EIP1895](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1895.md).

[You can play with the Ropsten version right now](https://heiswap.exchange/).

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -64,6 +64,7 @@
"eslint-plugin-react": "^7.14.2",
"eslint-plugin-standard": "^4.0.0",
"flow-bin": "^0.102.0",
"flow-remove-types": "^2.103.0",
"ganache-cli": "^6.4.4",
"truffle": "^5.0.26",
"truffle-hdwallet-provider": "^1.0.12"
Expand Down
1 change: 1 addition & 0 deletions src/components/DepositPage.js
Expand Up @@ -169,6 +169,7 @@ const DepositPage = (props: { dappGateway: DappGateway, noWeb3: Boolean, noContr
<Form.Field label='ETH amount' width={1}>
<Select
items={[
'1',
'2',
'4',
'8',
Expand Down
20 changes: 19 additions & 1 deletion src/components/WithdrawPage.js
Expand Up @@ -256,6 +256,8 @@ const WithdrawPage = (props: { dappGateway: DappGateway, noWeb3: Boolean, noCont
})
.filter(x => x[0].cmp(bnZero) !== 0 && x[1].cmp(bnZero) !== 0)

console.log(publicKeys)

// Check if user is able to generate any one of these public keys
const stealthSk: Scalar = h1(
serialize([randomSk, ethAddress])
Expand Down Expand Up @@ -289,11 +291,11 @@ const WithdrawPage = (props: { dappGateway: DappGateway, noWeb3: Boolean, noCont

// Create the transaction
const c0 = append0x(signature[0].toString('hex'))
const s = signature[1].map(x => append0x(x.toString('hex')))
const keyImage = [
append0x(signature[2][0].toString('hex')),
append0x(signature[2][1].toString('hex'))
]
const s = signature[1].map(x => append0x(x.toString('hex')))

const dataBytecode = heiswapInstance
.methods
Expand All @@ -313,7 +315,18 @@ const WithdrawPage = (props: { dappGateway: DappGateway, noWeb3: Boolean, noCont
if (useRelayer) {
const relayerURL = useDefaultRelayer ? 'https://relayer.heiswap.exchange' : customerRelayerURL
try {
// Nicer user flow for withdrawal (has prompts to sign message even through relayer)
// Also safer since relayer knows address authorized it
const message = `Get ETH from Heiswap via Relayer (Destination: ${dappGateway.ethAddress})`

const signedMessage = await web3.eth.personal.sign(
message,
dappGateway.ethAddress
)

const resp = await axios.post(relayerURL, {
message,
signedMessage,
receiver: ethAddress,
ethAmount,
ringIdx,
Expand All @@ -339,6 +352,11 @@ const WithdrawPage = (props: { dappGateway: DappGateway, noWeb3: Boolean, noCont
} else if (errorMessage.indexOf('EVM revert') !== -1) {
// EVM Revert is likely that the key image was used
setWithdrawalState(WITHDRAWALSTATES.SignatureUsed)
} else if (
errorMessage.indexOf('Invalid Message Signature') !== -1 ||
errorMessage.indexOf('Invalid Ring Signature') !== -1
) {
setWithdrawalState(WITHDRAWALSTATES.InvalidSignature)
} else {
setUnknownErrorStr(errorMessage)
setWithdrawalState(WITHDRAWALSTATES.UnknownError)
Expand Down
26 changes: 26 additions & 0 deletions yarn.lock
Expand Up @@ -5249,6 +5249,20 @@ flow-bin@^0.102.0:
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.102.0.tgz#3d5de44bcc26d26585e932b3201988b766f9b380"
integrity sha512-mYon6noeLO0Q5SbiWULLQeM1L96iuXnRtYMd47j3bEWXAwUW9EnwNWcn+cZg/jC/Dg4Wj/jnkdTDEuFtbeu1ww==

flow-parser@^0.103.0:
version "0.103.0"
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.103.0.tgz#7afc50498e543856e090c5b5d924ae60e7c1add6"
integrity sha512-H5UaM7mCzrssGa/HiPcr+oWBKosZTI7AlRk3jCEznBC786mdWIrTRjjGIAlRwuTVwT6SlPzV0M7kM6e3GGIQYA==

flow-remove-types@^2.103.0:
version "2.103.0"
resolved "https://registry.yarnpkg.com/flow-remove-types/-/flow-remove-types-2.103.0.tgz#31d7eb6258f815962ca48a330efff643cdc65c6a"
integrity sha512-R+zMApKML358LbfOdifns8ZOFA/xKiX7JaRvPhN0nBjyl3Yot6tyltl3uNFRyzDt0hBFyHJV9mo1s4HGlRyyIA==
dependencies:
flow-parser "^0.103.0"
pirates "^3.0.2"
vlq "^0.2.1"

flush-write-stream@^1.0.0, flush-write-stream@^1.0.2:
version "1.1.1"
resolved "https://registry.yarnpkg.com/flush-write-stream/-/flush-write-stream-1.1.1.tgz#8dd7d873a1babc207d94ead0c2e0e44276ebf2e8"
Expand Down Expand Up @@ -9111,6 +9125,13 @@ pinkie@^2.0.0:
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
integrity sha1-clVrgM+g1IqXToDnckjoDtT3+HA=

pirates@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/pirates/-/pirates-3.0.2.tgz#7e6f85413fd9161ab4e12b539b06010d85954bb9"
integrity sha512-c5CgUJq6H2k6MJz72Ak1F5sN9n9wlSlJyEnwvpm9/y3WB4E3pHBDT2c6PEiS1vyJvq2bUxUAIu0EGf8Cx4Ic7Q==
dependencies:
node-modules-regexp "^1.0.0"

pirates@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.1.tgz#643a92caf894566f91b2b986d2c66950a8e2fb87"
Expand Down Expand Up @@ -12580,6 +12601,11 @@ vinyl@^2.0.0:
remove-trailing-separator "^1.0.1"
replace-ext "^1.0.0"

vlq@^0.2.1:
version "0.2.3"
resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.3.tgz#8f3e4328cf63b1540c0d67e1b2778386f8975b26"
integrity sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow==

vm-browserify@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.0.tgz#bd76d6a23323e2ca8ffa12028dc04559c75f9019"
Expand Down

0 comments on commit 61901f0

Please sign in to comment.