PatStiles
    • 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 New
    • Engagement control
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # SolidityChip ## Overview: SolidityChip adds support for proving statements about solidity operations over EVM storage in halo2 using axiom-core. It allows a user to prove a vector of witness values represents a primitive solidity type and provides methods for constraining the computation of these types to prove statements about values within ethereum storage. Given a supplied vector of witnesses, and a SolidityChip a user can constrain: - The field elements of the witness values of the vector represent byte values range 0-255 - The supplied byte vector represents a primitive fixed or dynamic size solidity type: - Fixed Size: bytes32, address, uint8, uint16, uint32, uint64, uint128, uint256 - Dynamic Size: bytes, string - Given a user supplied solidity type `key` and fixed bytes32 `mapping_slot` the storage slot corresponding to the value of `key` for a solidity mapping `mapping(key => value)` is constrained as follows: - (1): If `key` is a Fixed size solidity type, `key` is treated as a fixed size input and left padded to 32 bytes. The storage slot of the value of `key` for a solidity mapping `mapping(key => value)` is constrained as: <br>`value_slot = fix_len_keccak256(left_pad_32(key) . mapping_slot)`<br> To constrain left_pad_32 the value byte array of key is left 0-padded to 32 bytes and constrained to be a SafeType::Bytes32 value. Since both the padded `key` and `mapping_slot` are of constrained fixed length there concatenation is performed by directly appending there witness vectors without range check. To constrain the computation of the slot fixed length keccak is performed over 64 bytes. - (2): If `key` is a Dynamic size solidity type, `key` is treated as a variable length input with associated `max_len` and assigned witness`var_len` supplied by the user. The storage slot of the value of `key` for a solidity mapping `mapping(key => value)` is constrained as: <br>`value_slot = var_len_keccak256(key . mapping_slot)`<br> Since `key` is a variable length input the concatenation of `key` and `mapping_slot` is performed by first concatenating `key` and `mapping_slot` and then right 0-padding the resulting concatenation to `max_len`. The concatenation is constrained in `phase1` of halo2's proving system by computing the RLC's of `key` up to `var_len`, `mapping_slot` up to its fixed length, and `concat` to the `var_len` + 32. To constrain the computation of the slot value variable length keccak is performed over the `var_len` + 32 ## Description: ### Constraining a Vector of Assigned Witnesses is a Solidity Type To represent a primitive solidity type, the user converts a vector of assigned witness values representing bytes into a `SafeType` or `AssignedBytes` then wraps it as an enum variant of `SolidityType`. `SafeType` constrains that the assigned witness values of the input witness vector are within the range of one byte. For fixed `SolidityType` variants `Address`, `Bytes32`, `Uint` the uint value of the bytes represented by the witnesses of inputted array are further constrained to be within the correct range for the number of bits the type represents i.e. uint8 = 0..255 and that the "byte array" has enough elements to support this range. ### Constraining a Solidity Mapping: `SolidityChip` supplies functions that support proving the storage slot of a value corresponding to a solidity type `key` in a solidity mapping `mapping(key => value)` located in storage at `mapping_slot` represented as a `Bytes32` solidity type. A user instantiates a `EthChip` which implements `SolidityChip` and calls `parse_mapping_phase0` then `parse_mapping_phase1`. `parse_mapping_phase0` delegates how the mapping slot is calculated based on the `key` supplied by the user. If `key` is a variant of `SolidityType` that represents a fixed type the mapping slot value is constrained as explained in (1) if `key` is `SolidityType::NonValue` enum variant it is treated as a dynamic solidity type and variable length input and an additional witness value `var_len` wrapped within the enum variant is used to constrain the mapping slot value as described in (2). In both cases of `parse_mapping_phase0` witness assignment and computation is performed and the assigned concat value passed into zkevm::keccak to be computed in phase1. In `parse_mapping_phase1` rlc concatentation is performed to constrain the variable length computation for dynamic type keys. ### AssignedByte Represents a variable length vector of bytes. Constrains field elements of witness values of to be within the range of bytes. ### VarAssignedBytes Struct of AssigneBytes and AssignedValue. Associates a variable length byte vector with assigned value representing its variable length. Upon creation asserts that var_len.value() < value.len() (TODO: this should be a range check). Handles checks for variable length. ### SafeInt Constrains a vector of assigned witness values represents a signed two's complement integer. Constrains that the value of the array represents a two's compliment integer within a bit range. Has bytes and assc. sign 1.) Constrain each element is a byte value 2.) Constrain the number of inputs is enough to hold TOTAL_BITS based on ### Utilities: `bytes_to_assigned_bytes`: - Converts a vector of byte values to a vector of assigned witness values within halo2. ### Tests: - Pos Unit test for fixed SolidityType's types with on chain data sourced from the WETH contract `mapping(address => uint256)` asserting a test circuit that checks the concatenated value and resulting key are equal to the sourced data is satisfied. - Pos Unit test for SolidityType::NonValue types with data sourced from deploying a test contract to a anvil mainnet fork with `mapping(bytes => uint256)` asserting a test circuit that checks the concatenated value and resulting key are equal to the sourced data is satisfied using halo2's mock prover. - Pos Unit tests for SolidityType variants of NonValue, Address, Uint8, Uint16, Uint32, Uint64, Uint128, Uint256 that generate random assigned witness vectors of bytes, computes a ground truth concat value and slot value using ether-rs, and asserts a test circuit that checks the concatenated value and resulting key are equal to the sourced data is satisfied using halo2's mock prover - Neg Unit test for SolidityType's checking that assertions on input values panic when invalid `max_len` and `var_len` parameters are passed. - Pos property tests for Fixed and Dynamic SolidityType's that generate random assigned witness vectors of bytes, compute the ground truth concat value and slot value, asserts a test circuit that checks the concatenated value and resulting key are equal to the sourced data is satisfied using halo2's mock prover - A benchmark that creates a circuit constrains the computation of 10 mapping slot and runs halo2's prover and verifier and asserts the circuit is satisfied ## Outcomes: - A pull request to axion-core-working consisting of a solidity module that defines: - A new module `solidity` in axiom-eth modeled after `storage` - A Trait `SolidityChip` that `parse_mapping_phase0`, `parse_mapping_phase1`, `parse_mappings_phase0`, `parse_mappings_phase1`. - An enum `ValueType` delineating the different ways solidity types are calculated in mappings - Mock Prover test for generating a storage proof of a mapping - Mock Prover test for generating multiple storage proofs of mapping in parallel in phase1 - Satisfiability tests for all types that could be a key of a mapping - Benchmark of circuit - Helper methods to convert from &[u8] to FixedByteArray/SafeTypes -> TBD ## TODO/Next Steps (Listed in priority): - Finish Variable length keys - Provide support for nested mappings - Simpligy SolidityChip implementation by adding a trait abstraction for Value/NonValue types and using enum dispatch - Add end to end test sourcing a storage proof to provide an example of usage of SolidityChip - Add Support for two's complement Int solidity types by extending SafeTypes - Support proving statements about of struct values and there members - Support proving statements about values over multiple storage slots - Support proving statements about packed storage slots

    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