HackMD
  • Beta
    Beta  Get a sneak peek of HackMD’s new design
    Turn on the feature preview and give us feedback.
    Go → Got it
      • Create new note
      • Create a note from template
    • Beta  Get a sneak peek of HackMD’s new design
      Beta  Get a sneak peek of HackMD’s new design
      Turn on the feature preview and give us feedback.
      Go → Got it
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • 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
      • More (Comment, Invitee)
      • Publishing
        Please check the box to agree to the Community Guidelines.
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Save as template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive Export to Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive Import from Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
    Menu Sharing Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Export to Google Drive Gist
    Import
    Dropbox Google Drive Import from Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    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
    More (Comment, Invitee)
    Publishing
    Please check the box to agree to the Community Guidelines.
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Off-chain storage & management for Lido validators’ keys The crucial Lido protocol actors are Node operators: teams running ETH2 validator nodes and earning ETH2 beacon chain rewards for the protocol. Each Node Operator controls many Validators which are independent actors that participate in the consensus of the Ethereum 2.0 protocol. Lido stake delegation process consists of several steps: 1. Node Operators generate locally a bunch of BLS key pairs and calculates `deposit_data_root` using `withdrawal_credentials` provided by Lido. 2. Node Operators uploads this DepositData to the smart contract and awaiting approval. 3. The protocol governance checks the public key uniqueness and that every `deposit_data_root` matches Lido `withdrawal_credentials`. 4. After key approval anyone could start delegation of the next 32 Ether chunk to the next validator because the contract has all data prepared on-chain. If there are no unused and approved key+signature pairs, no ether gets delegated on the delegation method call. Currently, the protocol stores all the Node Operators’ keys in the separate smart contract — [Node operators registry](https://github.com/lidofinance/lido-dao/blob/master/contracts/0.4.24/nos/NodeOperatorsRegistry.sol). This results in significant gas costs, as the need in blockchain storage grows linearly with the amount of ether deposited. The proposed change is to bring operators’ keys off-chain. ## Design The main challenge is to keep `Lido.submit` method which starts stake delegation process permission-less. The smart contract should be able to enforce key order and accepts only approved keys without storing them on-chain. To achieve this, we can take a hackathon winner's approach (add a link on PR and Tom’s full name) using Merkle proofs as a basis. The main idea before that approach that smart contract calculates mekle root on key submission and anyone could call `Lido.submit` method with merkle proof passed as argument. We propose to get rid of passing keys as a call data on key submission. Instead, Node Operator could upload them to IPFS and submit merkle root and ipfs_cid to the smart contract. To eliminate duplicate use of the same key, we suggest storing the key together with the index in the merkle tree. ## Happy Path 1. Node Operator generates a bunch of keys with indexes to eliminate duplicate use: ``` [1, pubkey1, deposit_data_root1], [2, pubkey2, deposit_data_root2], … [N, pubkeyN, deposit_data_rootN] ``` 2. Node Operator upload this bunch of keys to the IPFS and gets `ipfs_cid` in return. 3. Node Operator calculates merkle root out of keys: `bunch_data_root=MerkleRoot(keys)` 4. Node Operator submits to the smart contract: ``` ValidatorKeyBunch({ bunch_data_root: bunch_data_root, bunch_size: N, ipfs_cid: ipfs_cid }) ``` 5. The protocol governance checks the submission and approves a bunch of keys. 6. Anyone can call `Lido.submit` and provide merkle proof. Since merkle leaf contains indexes the order of key submissions is automatically ensured. ## Two instances of KeyBunches for each Node Operator Since key generation and approval operation takes several days and more there is a good idea to have two instances of *KeyBunch*es: one for current usage and another that waits for approval. Once one of *KeyBunch*es is out of keys the Node Operator should generate a new one and submits it for approval. In a meantime submitters using another *KeyBunch*. Since each of public key and withdrawal credentials pair has an index the order of key submission is strictly guaranteed. To choose what *KeyBunch* to use during permission-less deposit the smart contract should calculate the `bunch_data_root` based on submitted proof and takes that *KeyBunch* that matches the root. ## Offchain infrastructure In the current version of Lido ethereum liquid staking protocol, all keys are stored in the smart contract which leads to huge gas costs but also makes operations simple. 1. Easy permission-less submit: anyone could call submit which takes the next approved key and submits the key with buffered ether to the deposit contract. 2. Easy check that keys does not contain duplicates and hashes calculates right using Lido withdrawal credentials 3. Easy fetch all set of public keys to calculate the total balance of Lido validators on the Beacon chain. All keys that are submitted to the *Deposit Contract* are stored in ethereum blockchain as events / call data and might be easily consumed through the Subgraph protocol. Keys that has been submitted but not used and approved are not storing on-chain but can be fetched through IPFS. It’s very important to enforce the availability of that data using oracles network or using financial incentives on top of IPFS layer such as FileCoin. So, all validator keys can be accessed off-chain through IPFS and Subgraph protocol or a combination of both. ## Glossary * *Deposit Contract* is a smart contract on ethereum 1.0 side for deposits of ETH to the beacon chain. The deposit contract has a public `deposit` function to make deposits. * *Node Operator* is an entity running ETH2 validator nodes and earning ETH2 beacon chain rewards for the protocol. Each Node Operator controls many Validators. * *Validator* is an independent actor that participates in the consensus of the Ethereum 2.0 protocol and is controlled by one of Node Operator. * *ValidatorKeyData* is a tuple `(key_index, pubkey, deposit_data_root)` * *ValidatorKeyBunch* is tuple `(bunch_data_root, bunch_size, ipfs_cid)`

    Import from clipboard

    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 lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    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

    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

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    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

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    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. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        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
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully