Carlos Pérez
    • 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
    # Development path proposal for ZkEVM ## Lib Decision Independently of the library we pick, what we know for sure is that we will need to tweek it a bit. ### ZCash - halo2 - https://github.com/zcash/halo2 In the case of `halo2` we will basically need to: - Strip the Polynomial Commitment Scheme for something like KZG10 and integrate it propperly (taking ammortization into account). - PASTA curves won't be suitable for a KZG10 scheme (AFAIK), which means that at least, we will need to also switch to a different curve backend that follows the `ff`/`pairing` lib traits (Bn254 if possible). - The replacement of the curve means that we need to have another pairing-friendly curve implemented and ready to be used with the `ff` trait lib. If that's not the case (the only one suitable would be [zcrypto/bls12_381](https://github.com/zkcrypto/bls12_381) AFAIK) we would need to also strip and replace the `ff` crate per `ark-ff` (the arkworks version). In that case, we gain the curves and the algebra implementations for free. This lib is the preference as expressed in the last call as it's first of all beig audited and secondly and more importantly, being developed by a brilliant team. But we need to be concious of the amount of work that this will imply and wether is worth or not. Another thing to take into consideration is **How easy is to write circuits with this lib, and to debug them**. Since that is something which could consume a lot of time during the development process. ### Dusk Network - dusk-plonk - https://github.com/dusk-network/plonk In the case of `dusk-plonk` we will need to: - Implement a bn254 lib and replace the actual bls12-381 that is in usage (not based in `ff` or any other trait lib). Or refactor the backend and make it generic, using the zcrypto or arkworks backends and their curve impls (probably arkworks as they have them all implemented). - Check the status of the PLOOKUP integration (as is being done on a different fashion than on the halo2 impl IIRC). There's a paper comming in that will explain the logic. And depending on that status, either help on the integration or just decide not to use it or do it differently. Write and debug circuits with this lib is easy, but it hasn't been audited which is a quite big drawback. ## Start from the basis Although we want to start coding circuits & gadgets ASAP, we need to be sure that we actually have proper test vectors in a format which is easy-to-use for us in any context (JSON for example). Without some proper test vectors and a "minimally thought testing framework" we could fall into big problems when the time to test arrives. This does not get blocked by the decision mentioned avobe. And therefore is a task that we can already start to work on [here](https://github.com/appliedzkp/zkevm-testing-vectors). ### ZkEVM testing vectors The idea is simple. Get propper test vectors for our proof tests. But everything follows a reasoning line: Generally the circuit design/testing procedure for the circuits could be the following: 1) We build the most basic and easiest gadgets/circuits for the most basic and easiest opcodes/slots. For example, one of the first things to test will be the PUSH and POP OPCODES, since they're included in all of the Slots (or at least the majority). Therefore, we will code a contract that has functions that execute those: ```solidity= pragma solidity >=0.7.0 <0.9.0; /** * @title StackPushPop * @dev Store & retrieve value in a variable */ contract StackPushPop { function push_pop() public { uint number = 8; } } ``` From this two contract functions, we can extract the OPCODES, on a way we can represent them easily on a JSON or any other format that's easy to use for any language. Once done, we can test specific state changes done by small and basic slots/OPCODES. And from this, we can start to go towards the most complex ones. Once we are sure that the gadgets/circuits for the small ones are correct and tested exhaustively. The opcodes we want would be the ones from the specific testing functions: ```json { "push_pop" = [ 054 PUSH1 00 056 PUSH1 08 058 SWAP1 059 POP 060 POP ] } ``` That will prevent us situations like: - We build a circuit for a complex Slot that contains `ADD` or other "composite" OPCODES, and the circuit fails to verify a proof that should pass. If we're sure that the basis are tested, we know that the error is in the `ADD` circuit implementation and how we call the gadgets or similar, **BUT NEVER** on the implementation of the gadgets representing the OPCODES used inside `ADD`. Once the basic opcodes like push and drop from stack are tested, we can move on to the next functions to test new slots which can deal for example with memory: ```solidity= pragma solidity >=0.7.0 <0.9.0; /** * @title Storage * @dev Store & retrieve value in a variable */ contract Storage { uint256 number; /** * @dev Store value in variable * @param num value to store */ function sstore_test(uint256 num) public { number = num; } /** * @dev Return value * @return value of 'number' */ function sload_test() public view returns (uint256){ return number; } // Size of 0_code will not be parametric to avoid `extcodesize` // usage function memory_test(address _addr) public view returns (bytes memory o_code) { assembly { let size := 0x40 // allocate output byte array - this could also be done without assembly // by using o_code = new bytes(size) o_code := mload(0x40) // new "memory end" including padding mstore(0x40, 0x7f) // store length in memory mstore(o_code, size) // actually retrieve the code, this needs assembly extcodecopy(_addr, add(o_code, 0x20), 0, size) } } } ``` Here we will of course need to use `PUSH` and `DUP`, but since they'll be already tested, we can focus on the tests for `SLOAD`, `SSTORE`, `MLOAD`, `MSTORE`. As seen, having these contracts with functions which test specific slots/OPCODES on the most precise and individual way possible, allows us to extract OPCODES and previous and past states after the execution. And that, is what we use as test vectors which will be then used to test our circuits. ## Parallel development Since we will need to tweek any lib we pick but it should already give the change to write circuits, we could also decide to "split" ourseleves a bit. And while some part of the team takes care of replacing the backend of the lib, the other can use the previous backend **AS THE CIRCUIT API WILL STILL BE THE SAME** and on that way advance in the gadget/circuit testing path. ## TODOs - [ ] Write contracts for the slots/OPCODES we want to test and check with the team wether they're suitable to be used as test vectors. - [ ] Write some kind of BUS/BUS-Mapping prototype which will serve the data on the same way as the actual one will do it(at least on the same fashion). On that way the tests will be more reallistic and close to the final application. - [ ] Pick a PLONK lib and write the specific TODOs for it. - [ ] Check cc's project as per data visualization: https://github.com/ChihChengLiang/vmtrace_visualizer

    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