Andrew Borg
    • 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # ZK Deep Dive Created on: 31 July 2023 Author: akashin @ NEAR Related: [zkwasm sync](https://hackmd.io/MTmmOMOxShaMqMi83bxzRQ) --- ### Theory - [Gentle intro to SNARKs](https://www.di.ens.fr/~nitulesc/files/Survey-SNARKs.pdf) - ZK MOOC: https://zk-learning.org/ - KZG commitments: https://dankradfeist.de/ethereum/2020/06/16/kate-polynomial-commitments.html - Plonk: https://eprint.iacr.org/2019/953.pdf ### Tutorials - ZK VMs (Polygon Miden): https://www.youtube.com/watch?v=GRFPGJW0hic - Building opcode compatible zk EVMs: https://www.youtube.com/watch?v=Crzw7ccuHd0 ### ZK EVM Materials - Dev guide: https://zkevm.polygon.technology/docs/introduction - Spec: https://zkevm.polygon.technology/introduction - End-to-end life of a transaction: https://zkevm.polygon.technology/docs/protocol/l2-transaction-cycle-intro/ - Proof aggregation: https://github.com/0xPolygonHermez/zkevm-techdocs/blob/main/proof-recursion/v.1.1/proof-recursion.pdf - ZK Assembly docs: https://github.com/0xPolygonHermez/zkevm-techdocs/blob/main/zkevm-architecture/v.1.1/zkevm-architecture.pdf - Running a verifier: https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/verifyMainnetDeployment/verifyMainnetProofVerifier.md - ZK EVM ROM: https://github.com/0xPolygonHermez/zkevm-rom ### PIL - Tech document: https://github.com/0xPolygonHermez/zkevm-techdocs/blob/main/pil/v.1.0/pil.pdf - Example programs: https://github.com/0xPolygonHermez/zkevm-proverjs/tree/main/pil - Compiler: https://github.com/0xPolygonHermez/pilcom - PIL2 presentation: https://docs.google.com/presentation/d/13nb9Zx1yHTrrXYfowSJZh8bJi0P3Ku7iuOjWmI9Fg-8/edit?usp=sharing ## Meetup topics #### Modifying the PIL and Processor > E.g. let's try to add one more register. > Or let's add a new circuit for hash function like SHA256 #### Benchmarking and profiling proofs > How do I find out why the proof generation is slow? #### What can we do with "Compiler JIT bombs"? > Smart contracts that deliberately try to exploit the prover and increase the proof generation time > See https://docs.google.com/presentation/d/1n75Mo09HmyruV5S7q0cHWuq-UorrvdG1bRAYTNydBcY/edit#slide=id.g672d2eff65ef7faa_0 #### PIL2 Deep Dive/Future of proving speed > How can we support large computations (10^8 execution steps)? > How does the proving time depend on the number of rows/steps in the execution trace? #### NEAR Contract Runtime overview > How we pre-process contracts > The diagram here: https://nomicon.io/RuntimeSpec/Components/ #### How we collaborate going forward > The focus of NEAR team > The focus of Polygon team ## Questions #### ✅ How expensive (how many steps) is it to access external state (e.g. ETH state)? > What does it depend on? How does size of key and value influence this? > Can we use Merkle inclusion proofs or do we need to use something ZK-specific? #### ✅ How can we implement WASM indirect function calls? Is there a way to find out the current location in the program and JUMP to it? - Yes, we can use `@label` to get the address of the label and store it in a variable, e.g.: ``` @label => RR ``` #### ✅ How will WASM foreign (host) function calls work? > All functions are described in https://nomicon.io/RuntimeSpec/Components/BindingsSpec/, and they fall into the following categories: > - [Pure math functions](https://nomicon.io/RuntimeSpec/Components/BindingsSpec/MathAPI): sha256, sha512, keccak256, keccak512 > - [Execution context functions](https://nomicon.io/RuntimeSpec/Components/BindingsSpec/ContextAPI): E.g. `signer_account_id`, `block_index`, `storage_usage`, `gas_used` > - "Input functions": `input`, `read_register`, `storage_read` > - "Output functions": `value_return`, `panic`, `log`, `promise_create`, `storage_write` > > Implementation: https://github.com/near/nearcore/blob/master/runtime/near-vm-runner/src/logic/logic.rs > > - How hard would it be to implement each category? > - Can we have an escape hatch for things that we haven't implemented yet? Likely need a dedicated state machine for math functions. From point of PIL, don't need to implement it, but need to verify it. E.g. division is hard to compute but easy to verify. #### ❓ What does the verifier of the proof gets as an input? > How about recursive proofs? Previous proof and commitment to the history? #### ✅ How relevant is the ZK-WASM work from DelphinusLab? > https://delphinuslab.com/zk-wasm/ - Need to check if this is compatible - Need to check when will this be production ready Likely to be used as an inspiration #### ✅ What are Publics `x` and Privates `w` in case of EVM computation? Publics would be the old and new state root, transaction root. Privates would be the actual list of transactions, the execution trace. #### ✅ How long does the proof generation usually take? What does it depend on? > - Input size? Transaction complexity? State witness size? > - What happens during 30 mins of verification [described here](https://zkevm.polygon.technology/docs/protocol/transaction-execution/#verification-on-layer-1)? Proof generation until recursion is 2.5 minutes for a batch. (Faster CPU on machine -> Faster proof). Each batch contains many Ethereum transactions. Has limited number of ZK Counters. Related to the number of the rows in the PIL. A single 256 bit operation - 16 rows (CYCLES?). Resource consumption depends on the included transactions. Proving time does not depend on how many transactions are in the batch. Aggregation of proofs between batches take 15-20 seconds Final aggregated proof translated into SNARK. Ethereum has 30M Gas limit. There are limits per operation time. Dynamic proofs will allow to process larger. #### ✅ How is well-formedness/validity of transactions proven? > The parts that happen outside of WASM VM, e.g. signature validation, balance checks, WASM syntax and limits checks. Needs to be expressed as ZK circuit. E.g. this is done for consensus rules of Ethereum. #### ✅ What is the number of rows in PIL (2^10 in pil.pdf)? > - Does it limit the max possible size of the program? > - How do you select this number? First, you could define number of rows in PIL1 and PIL2, in PIL1 only has one number of rows but in pil2 you could decide for each subproof how many rows want. In production, with PIL1 we have 2^23 rows. This number of rows determines how many resources (arithmetics, binaries, keccaks) we have. We select this number considering size, cost, time, etc.. In PIL2 with vadcops you could divide the zkevm in some subproofs (as state machines). Each subproof has one or more numbers of rows (for example, S (2^16), M(2^23), XL(2^25),...) but not only this, you could aggregate subproofs of same or different size. For example, I need more than 2^24 rows of binary (2^24 + 2^15), I have some options: 1 subproof of XL (51% of use) 3 subproofs of size M (67% use) 2 subprofs of size M + 1 subproof of size S (99% use). #### ✅ How does zkASM relate to PIL? > Is it built on top of it? With zkASM generates columns (pols) of ROM, these cols are used in constraints of PIL to verify the program trace. We could make a specific meeting to show you some examples of this. Really zkasmcom is a tool to generate the ROM fixed cols (constant pols), but you could generate these cols by hand but it would be very tedious and complex (label, variable addresses, etc..). The zkasm makes the ROM more readable and auditable. #### ✅ What is in the output of PIL compilation? > What is in the file `out.pil.json`? Constraints in a convenient format? (https://zkevm.polygon.technology/docs/zkProver/overview#microprocessor-state-machines) #### ✅ What is [Bridge's Global Exit Merkle Tree](https://zkevm.polygon.technology/docs/protocol/transaction-batching#globalexitroot)? Should be answered in https://zkevm.polygon.technology/docs/protocol/exit-tree

    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