Wanseob Lim
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Publish Note

      Everyone on the web can find and read all notes of this public team.
      Once published, notes can be searched and viewed by anyone online.
      See published notes
      Please check the box to agree to the Community Guidelines.
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Publish Note

Everyone on the web can find and read all notes of this public team.
Once published, notes can be searched and viewed by anyone online.
See published notes
Please check the box to agree to the Community Guidelines.
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# Private order matching & zk atomic swap Private order matching uses the 'Socialist Millionare' protocol to match the trade orders without revealing the details. The matched result can also be used to enforce a zk transfer pool to execute a zk atomic swap correctly. ## Private order matching ### Step 1. Make a new order Let's assume that Alice wants to get 100 DAI by giving 1 ETH. And Bob wants to get 1 ETH by giving 100 DAI. Alice's order: `'GET DAI' (1, 100)(ETH/DAI)` Bob's order: `'GET ETH' (1, 100)(ETH/DAI)` ``` sell = field('GET DAI') buy = field('GET ETH') order = field('(1, 100)(ETH/DAI)') ``` | What only Alice knows | What everyone knows | What only Bob knows | | -------- | -------- | -------- | |$order_a$ | $sell$, $buy$, $pk_a$, $pk_b$ | $order_b$ | ### Step 2. Create the homomorphic hidings for each other. In this situation, Alice and Bob will generates new homomorphic hidings for the 'socialist millionare' protocol using their own salts and each other's public key. As a result, each homomorphic hidings are below: - Alice's homomorphic hiding: $H_a = g^{sell \cdot pk_b \cdot salt_{a} \cdot order_a}$ - Alice's public salt: $S_a = g^{sell \cdot pk_b \cdot salt_{a}}$ - Bob's homomorphic hiding: $H_b = g^{buy \cdot pk_a \cdot salt_{b} \cdot order_b}$ - Bob's public salt: $S_b = g^{buy \cdot pk_a \cdot salt_{b}}$ And they share their homomorphic hidings each other. | What only Alice knows | What everyone knows | What only Bob knows | | -------- | -------- | -------- | |$order_a$, $salt_a$ | $sell$, $buy$, $pk_a$, $pk_b$, $H_a$, $H_b$, $S_a$, $S_b$ | $order_b$, $salt_b$| ### Step 3. Alice and Bob checks that they have a same order. Now using the given values, Alice and Bob check that they have a same order by themselves. - If Alice's calculation $H_b == order_a \cdot S_b$ is true, she knows that $order_a == order_b$. - If Bob calculate $H_a == order_b \cdot S_a$ is true, he also knows that $order_b == order_a$. - Now they know that they have a same order each other. | What Alice only knows | What everyone knows | What Bob only knows | | -------- | -------- | -------- | |$order_a$, $salt_a$ , $order_a \cdot S_b == H_b$| $sell$, $buy$, $pk_a$, $pk_b$, $H_a$, $H_b$, $S_a$, $S_b$ | $order_b$, $salt_b$, $order_b \cdot S_a == H_a$| ## Using $H$ for zk atomic swap To make the atomic swap happen with the matched order, use the combined homomorphic hiding $H$ to combine 2 zk transfers. Here $H$ equals to the below: $H = g^{sell \cdot buy \cdot pk_a \cdot pk_b \cdot salt_a \cdot salt_b \cdot order}$ And then Alice's and Bob's zk transfers for the atomic swap should look like this: #### Alice's zk transfer for the atomic swap | - NoteA1(input) | + NoteA2(output) | + NoteA3(output) | Sum | | --------------- | ---------------- | ---------------- | --- | | ETH: 3 | ETH: 2 | ETH: 1 | 0 | | DAI: 500 | DAI: 500 | DAI: 0 | 0 | | Owner: Alice | Owner: Alice | Owner: Bob | | #### Bob's zk transfer for the atomic swap | - NoteB1(input) | + NoteB2(output) | + NoteB3(output) | Sum | | --------------- | ---------------- | ---------------- | --- | | ETH: 8 | ETH: 8 | ETH: 0 | 0 | | DAI: 900 | DAI: 800 | DAI: 100 | 0 | | Owner: Bob | Owner: Bob | Owner: Alice | | In this pair, Alice splits her asset into two notes and give one to Bob. Otherwise, Bob also split his assets and give one to Alice. The newly exchanging notes should have the same information in the homomorphicall hidden commitment $H$. ### Alice's SNARK ``` public inputs: Note A1's nullifier Note A2's hash Note A3's hash H<=(sell, buy, pk_a, pk_b, salt_a, salt_b, order) private inputs: Note A1's details [3, 500, Alice] Note A1's spending signature from Alice's key Note A2's details [2, 500, Alice] Note A3's details [1, 0, Bob] Bob's public key [pk_b] Bob's public salt S_b<=(buy, pk_a, salt_b) order [1, 100] = (order_x, order_y) salt_a Constraints: 1. The hash of Note A1, A2, and A3 are all valid. 2. Note A1's included in the shielded pool. 3. Note A1's nullifier is correctly derived from the A1's details. 4. output notes - input notes == 0 (A2 + A3 - A1 == 0) 5. A3's owner == pk_b 6. A3's value == if 'sell' then (order_x, 0) else (0, order_y) 7. if sell: H == sell * pk_b * salt_a * order * S_b elif buy: H == buy * pk_b * salt_a * order * S_b ``` ### Bob's SNARK ``` public inputs: Note B1's nullifier Note B2's hash Note B3's hash H<=(sell, buy, pk_a, pk_b, salt_a, salt_b, order) private inputs: Note B1's details [8, 900, Bob] Note B1's spending signature from Alice's key Note B2's details [8, 800, Bob] Note B3's details [8, 100, Alice] Alice's public key [pk_a] Alice's public salt S_a<=(buy, pk_b, salt_a) order [1, 100] = (order_x, order_y) salt_a Constraints: 1. The hash of Note B1, B2, and B3 are all valid. 2. Note B1's included in the shielded pool. 3. Note B1's nullifier is correctly derived from the B1's details. 4. output notes - input notes == 0 (B2 + B3 - B1 == 0) 5. B3's owner == pk_a 6. B3's value == if 'sell' then (order_x, 0) else (0, order_y) 7. if sell: H == sell * pk_a * salt_b * order * S_a elif buy: H == buy * pk_a * salt_b * order * S_a ``` With this construction, we can let Alice and Bob match their order privately and also execute the zk atomic swap.

Import from clipboard

Paste your webpage below. It will be converted to Markdown.

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template is not available.
Upgrade
All
  • All
  • Team
No template found.

Create custom template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

How to use Slide mode

API Docs

Edit in VSCode

Install browser extension

Get in Touch

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

No updates to save
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully