Nam Ngo
    • 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
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • 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
    • Note Insights
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
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
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    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
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    > WIP, comments are welcomed. Thanks in advance! > Technical paper on [IACR eprint 2016/969](https://eprint.iacr.org/2016/969), and R's talk's slides deck on [R's public website](https://web.engr.oregonstate.edu/~rosulekm/pubs/gc-gadgets-talk.pdf). > A Primer to Garbled Circuit and Optimizations [here](https://hackmd.io/frMushaeSESma2OEdNseRQ). TLDR: super efficient for arithmetic computation except for comparison: ![](https://hackmd.io/_uploads/SyAOyI22h.png) # Generalizing Free-XOR --- **Free-XOR is mod $2$** ![](https://hackmd.io/_uploads/r1d72fCqh.png) --- **We can generalize to Free-XOR mod $m$** ![](https://hackmd.io/_uploads/Hyxa2zAch.png) > For $x \in \mathbb{Z}_m$, we have $W_x = W_0 + x\Delta_m$; > Concretely we just pick $W_0$ then encode the rest as in the formula. --- With the generalized Free-XOR encoding we have: - Free addition mod $m$. - Free multiplication by a constant $c$. - Point-and-Permute still works by setting $\Delta_m$'s last "digit" (an element of $\mathbb{Z}_m$ not a bit anymore) to be 1 and for each wire label $W_x$ the color digit is set to be a random cyclic shift of $x$ from the color digit of wire $W_0$, > i.e. color($W_x$) + $W_x$ = 1 and color($W_x$) = color($W_0$) + $x$. ## Mixed-Moduli Ciruit (MMC) for *Arbitrary* Projection MMC is possible via a unary gate that allows conversion from Generalized Free-XOR mod $m$ to Generalized Free-XOR mod $l$, called "Projection". This can be done in a straight forward manner, i.e. by encrypting the arbitrary projection $\phi(x) \in \mathbb{Z}_l$ of $x \in \mathbb{Z}_m$ from mod $m$ to mod $l$, > i.e. $C + \phi(x)\Delta_l$ is encrypted with key $A + x\Delta_m$ (resulting in $m$ ciphertexts). ![](https://hackmd.io/_uploads/ryaazTNo3.png) Projection in BMR16 is compatible with Row Reduction (resulting in $m-1$ ciphertexts) and Point-and-Permute, i.e. - **Point-and-Permute:** The $m$ ciphertexts can be ordered by the color digit as in Generalized Free-XOR, > i.e. $\Delta_l$ is appended with the digit 1; > and the $m$ ciphertexts can be ordered by the color digits of the input wire (i.e. $x + color(W_0)$): > concretely each ciphertext is encrypted as > $\hat{C}_{x+color(A_0)} = H(g, A_0 + x\Delta_m) + C_0 + \phi(x)\Delta_l$; > thus $\hat{C}_{x+color(A_0)} = H(g, A_x) + C_{\phi(x)}$. - **Row Reduction** By choosing $C_0 = -H(g, A_{-color(A_0)}) - \phi(-color(A_0)\Delta_l)$ we have $\hat{C} = 0$ and thus only $m-1$ ciphertexts are to be communicated. <!-- - **Row Reduction 2** --> --- ### Concrete Algorithms ![](https://hackmd.io/_uploads/HkV_pJHih.png) --- ## Multiplication mod $m$ ![](https://hackmd.io/_uploads/ByuALxHoh.png) > Generalized Half-Gates and 3-Halves [here](https://hackmd.io/h7Tcx6ZkQzKNyQO5uUeqjw). > > Somehow this generalization yields $2(m-1)$ ciphertexts so my guess is that BMR16 did not consider Row-Reduction when doing the above analysis? ## Garbling Arithmetic using CRT with MMC To represent a large integer ($2^{32}$ or $2^{64}$) it is sufficient to use the CRT (Chinese Remainder Theorem) representation: > $2 \cdot 3 \cdot 5 \cdot 7 \ldots 29 > 2^{32}$ (first 10 primes). > $2 \cdot 3 \cdot 5 \cdot 7 \ldots 53 > 2^{64}$ (first 16 primes). > $2 \cdot 3 \cdot 5 \cdot 7 \ldots 103 > 2^{128}$ (first 27 primes). MMC can be leveraged to support many moduli in a single circuit. > For each $\mathbb{Z}_{2^{32}}$ wire we use 10 CRT wires $\mathbb{Z}_{2}$, $\mathbb{Z}_{3}$, $\ldots$, $\mathbb{Z}_{29}$. > We use notation: $[[x]]_{crt} = \{[x]_2, [x]_3, \ldots, [x]_{29} \}$ ### Basic Arithmetic in CRT reps Free addition --> just add each CRT residue. > $[[x]]_{crt} + [[y]]_{crt} = \{[x + y]_2, [x + y]_3, \ldots, [x + y]_{29} \}$ Free multiplication by a constant --> just multiply each CRT residue. > $c*[[x]]_{crt} = \{[c*x]_2, [c*x]_3, \ldots, [c*x]_{29} \}$ > However note that: >> ![Screenshot 2024-03-10 at 08.17.40](https://hackmd.io/_uploads/BkudcKcaa.png) >> Use for scaling: https://en.wikipedia.org/wiki/List_of_prime_numbers Raise to a public power --> use projection gate with power function $\phi(x) = [x^c]_p$ on each CRT residue mod $p$: > cost $(2-1) + (3-1) + \ldots + (29-1)$ ciphertexts. Similarly, remainder mod $q$ can be done with a projection gate with modulo function $x \mbox{ mod } q$ on each CRT residue mod $p$: > cost $9 * (q-1)$ ciphertexts. Multiplication mod $2 \cdot 3 \cdot \ldots 29$ --> can just multiply each CRT residue: > cost $2*(2 + 3 + \ldots + 29)$ ciphertexts via [generalized half-gate](https://hackmd.io/h7Tcx6ZkQzKNyQO5uUeqjw). ### Alternate Multiplication This alternate multiplication method scales better for high fan-in gate which will be used for advanced gadgets in the next Sections. Observe that $x \cdot y = g^{dlog_g(x) + dlog_g(y)}$ > (provided that $x \cdot y \neq 0$); > where $g$ is a primitive root mod $p$ and the exponent is in mod $p-1$. GC in case $x \cdot y \neq 0$ - power of $g^z$ (1 projection gate $z \rightarrow g^z$ (mod $p$) costing $p-2$ ciphertexts) - dlog(x) and dlog(y) (2 projection gates mapping $x, y \rightarrow dlog(x), dlog(y)$ (mod $p-1$) each costing $p-1$ ciphertexts) - addition (free) > cost $2(p-1) + (p-2) = (3p-4)$ ciphertexts GC in case $x \cdot y = 0$ - compare $x = 0$ or $y = 0$ (2 equality tests which are 2 projection gates that map $\mathbb{Z}_p \setminus \{0\} \rightarrow 0$ and $0 \rightarrow 1$ each costing $p-1$ ciphertexts) - OR gate which costs 2 ciphertexts (if we make the comparison output mod $2$) Combining the two cases we actually compute $f(z,b) = g^z \mbox{ if } b = 0 \mbox{ OR } 0 \mbox{ otherwise}$. > cost $6p - 5$ ciphertexts In case of MMC total cost is $(6*2-5) + \ldots + (6*29-5)$ > Notice that high fan-in MUL gates such as fan-in 3 MUL gate $x \cdot y \cdot z$ benefits from free addition on the exponent as it only increase the number of dlog gates. ### Gadgets #### Equality Test To test $[[x]]_{crt} = [[y]]_{crt}$ we test $\large\land([x-y]_2 = 0; \ldots; [x-y]_{29} = 0)$ > subtraction is free > comparison is a projection gate that costs $p-1$ ciphertexts > AND gate which costs $10$ ciphertexts if we make comparison output mod $10$ In case of MMC total cost is $10 + (2-1) + \ldots + (29-1)$ #### Exact Weighted Threshold The gate $\mathsf{Th}_{t,c_1,\ldots,c_m}(x_1,\ldots,x_m) = 1$ if $t = \sum^m_i c_i x_i$: > Multiplication of $x_i$ by a public constant $c_i$ is free > Addition is free > Equality test (in MMC) cost $10 + (2-1) + \ldots + (29-1)$ #### Comparison Comparison is typically done in binary form. Hence we need to convert the CRT reps to Boolean reps. Another method is to perform comparison in primorial-mixed-radix (PMR) form: $[[x]]_{pmr} = (d_{29}, \ldots, d_1)$ where $d_i = \frac{x}{1\cdot\ldots\cdotp_i} \mbox{ mod } p_i$. ![](https://hackmd.io/_uploads/H1Bw2Hnh3.png) In such form, $[[x-y]]_{pmr}$'s most significant digit will server as the sign bit: $d_i = 0$ if $x > y$ and vice versa. To convert CRT to PMR reps we can do the following: ![](https://hackmd.io/_uploads/HJFmRB3n2.png) An example: ![](https://hackmd.io/_uploads/HyPBRSnn3.png) Overall cost includes conversion from CRT to PMR, comparison in PMR form and conversion back to CRT form: $2(k-1)\sum_{i=1}^kp_i +2k^2 -k+p_k$ #### Weighted Threshold The gate $\mathsf{Th}_{t,c_1,\ldots,c_m}(x_1,\ldots,x_m) = 1$ if $t > \sum^m_i c_i x_i$: > Cost is as the exact weighted gate but with equality replaced with comparison. ## OT for Arithmetic CRT Trivial approach is to use 1-out-of-p OT which yields base cost $(p-1)\lambda$ bits. In BMR16 the authors suggest a more efficient approach. For a mod $p$ wire $w$, let $\ell = log p$ and we represent $w = \sum_{j=0}^{\ell-1} w_j2^j$. We can use $\ell$ 1-out-of-2 OTs to obtain the bits representation of $w$, then reconstruct the mod $p$ representation (for free) as $2^j$ are public constants. ## Input in CRT form ![](https://hackmd.io/_uploads/Sko6JIh22.png)

    Import from clipboard

    Paste your markdown or webpage here...

    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 has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a 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

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    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

    Note content is identical to the latest version.
    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