Janmajayamall
    • 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
    # Scaled (quasi-rollup mode ) Consider that there's an on-chain contract that maintains a sequence of updates to accounts state (account_obj = owner's address + balance). Accounts state is represented by the root of a sparse markle tree (referred to as `account tree`). To add an account_obj to account tree, you first calculate path (path = keccack256(account_obj.address)) and concatenate it with account_obj and store it at `path` in the account tree. Now consider that user A, B, C, D, E have accounts in the account tree. Moreover B maintains receipts with A, C, D. Receipts are between two users and are latest record of how much each of them owe the other. For example B's receipt with A would look something like - ``` { A_address: 0xABC, B_address: 0xBCD, A_owes: 10000, B_owes: 120, expires_by: 12901391 (timestamp) } ``` For a receipt to be valid both users between which the receipt is maintained should sign it. A receipt can be updated with new values by updating "expires_by" timestamp to some later time than the previous one. Thus, a valid receipt is the one to which both users have agreed as latest (i.e. both have signed & there exists no other receipt with a later "expires_by"). User B can settle the owed amounts on receipts by updating accounts in account tree on-chain. To do so B does the following - 1. Retrieves latest state of account tree (latest_root). 2. Builds updates_arr where each receipt corresponds to a single sequence of minor updates to account tree. For each receipt - User B generates a tuple of (TU, sigTU), where TU consists of updates to account tree caused by receipt and sigTu is B's signature on TU. TU is a tuple of form (root_before, root_after, receipt), where root_after is root of account tree after applying updates to respective account_objs, according to the receipt, to root_before. For example, take the receipt shown above - Consider B_old & A_old as B's & A's existing account_objs. The update should change (1) B_old -> B_updated where B_updated.balance = B_old.balance + A_owes - B_owes and (2) A_old -> A_updated where A_updated.balance = A_old.balance + B_owes - A_owes. User B first derives B_updatd and A_updated then does the following - * Updates leaf corresponding to A's account_obj in account tree from A_old to A_updated. * Updates leaf corresponding to B's account_obj in account tree from B_old to B_updated * Calculates new of root (root_after) of account tree. B then generates TU = (root_before, root_after, receipt) and signs it to generate sigTU. B then appends (TU, sigTU) to updates_arr. Note that root_before of element at index `i` is equal to root_after of element at index `i-1` in updates_arr and root_before at index 0 is equal to latest_root retrieved in step 1. In the end User B has updates_arr that transitions account tree from latest_root to root_after of last element in updates_arr. root_after of last element in updates_arr will become the latest_root when posted on-chain and will be finalised after challenge period. 3. Posts the updates_arr on-chain. After user B posts updates on-chain there's a challenge period of few days during which anyone can post a proof that proves updates posted by B are invalid. Like optimistic rollups if no challeges are received during challenge period, the update will be finalised. Challenges can be of following types - 1. Invalid receipt - User B posted invalid receipt in the update (i.e. receipt with invalid signatures OR "expires_by" smaller than block.timestamp). Challenger can submit the update (i.e. (TU, sigTU)) that contains the invalid receipt on-chain. The contract will check (1) B attested to update (i.e. valid sigTU) (2) Signatures do not match respective users (i.e. A and B for receipt between A & B) and slash user B. 2. Invalid state update - User B posted invalid state update (i.e. when account_objs are updated according to receipt in root_before, the reesult root does not match root_after). To prove, challenger prepares the following evidences & posts them on-chain (taking example receipt as a case) - * A_old & B_old account objects (i.e. before update). * B's invalid state update (i.e. (TU, sigTU)). * Witness data {w1, w2} - Challenger provides inclusion proof A_old (w1) in root_before. Updates root_before to intermediary_state_1 by updating A_old to A_updated. Provides inclusion proof B_old (w2) in intermediary_state_1. Contract does the following in the given sequence - * Derives A_updated, B_updated from A_old, B_old using receipt in B's state update. * Verifies w1 in root_before * Updates A_old to A_updated using w1, thus deriving intermediary_state_1. * Verifies w2 in intermediary_state_1. * Updates B_old to B_updated, thus deriving *correct* root_after. * If *correct* root_after does not matches root_after in TU posted by B, then B is slashed. There exist few additional cases through which users can cheat 1. User owes more than their account balance in account tree (i.e. User A owes more than their balance when all their receipts are aggregated) - To disincentivise such behaviour, as long as receipt is valid, update can cause account balance to go negative. Plus, if account balance goes from + to - in the update, the amount can be amplified by some factor (ex. 2x) to cause penalty. The dishonest user cannot try to withdraw right after owing more than they their account could afford and before the other user could post updates on-chain, since a withdraw state update isn't valid until after all receipts have expired. So the other user, whom dishonest user was trying to cheat, can produce not expired receipts on-chain to slash dishonest user. 2. Dishonest user posted updates on-chain, but did not include latest receipt for an update - The other user with the latest receipt (i.e. receipt of which "expires_by" is greater than the "expires_by" of receipt included in the update) can produce the latest receipt on-chain to cause slashing to dishonest user. #### Note on data size 1. Updates: Size of Receipt: (32 bytes * 2 + 8 bytes * 2 + 4 bytes) = 84 bytes Size of TU: 32 bytes + 84 bytes + 32 bytes = 148 bytes Size of updates_arr = 148 bytes * no_of_receipts 2. Invalid update challenge: Number of accounts = N Account size = 32 bytes + 8 bytes = 40 bytes Single merkle proof size = 32 + (32 * log(N)) bytes. Total Size of {w1, w2} = 2 * (32 + (32 * log(N))) bytes Total evidence size = 148 bytes + 2 * (32 + (32 * log(N))) bytes + 2 * 40 bytes. ### Extra [In progress doc that tries to get into detailed specification can be found here](https://hackmd.io/n3jdcFSoQU-zmZMxgjx5Hg)

    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