pshenichnyy
    • 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
    # Mitigations for deposit front-running vulnerability ## Abstract On Tuesday, Oct 5, the vulnerability allowing the malicious Node Operator to intercept the user funds on deposits to the Beacon chain in the Lido protocol was reported to Immunefi. On Wednesday, Oct 6, [the short-term fix was implemented](https://blog.lido.fi/vulnerability-response-update/). **Currently, no user funds are at risk, but the deposits to the Beacon chain are paused**. This document outlines the long-term mitigation allowing deposits in the Lido protocol. The vulnerability could only be exploited by the Node Operator front-running the `Lido.depositBufferedEther` transaction with direct deposit to the [DepositContract](https://etherscan.io/address/0x00000000219ab540356cbb839cbe05303d7705fa) of no less than 1 ETH with the same validator public key & withdrawal credentials different from the Lido's ones, effectively getting control over 32 ETH from Lido. To mitigate the vulnerability, Lido contracts should be able to check that Node Operators' keys hadn't been used for malicious pre-deposits. DepositContract provides the Merkle root encoding of all the keys used in staking deposits. We propose to establish the **Deposit Security Committee** checking all deposits made and approving the current `deposit_data_root` for Lido deposits. The idea was outlined on [research forum post](https://research.lido.fi/t/mitigations-for-deposit-front-running-vulnerability/1239#d-approving-deposit-contract-merkle-root-7) as the option `d)`. The Merkle root data should be checked & signed by the guardian committee off-chain to save gas costs. Anyone with the signed `depositRoot` can call `depositBufferedEther` sending the ether from the Lido buffer to the DepositContract. In case any deposit happens before the `depositBufferedEther` transaction, the Merkle root on the DepositContract is changed and the Lido deposit transaction is reverted. ```solidity= function depositBufferedEther( bytes32 depositRoot, Signature[] memory signatures ) external { bytes32 onchainDepositRoot = IDepositContract(depositContract).get_deposit_root(); require(depositRoot == onchainDepositRoot, "deposit root changed"); require(_verifySignatures(depositRoot, signatures), "invalid signatures"); _depositBufferedEther(); } ``` The outlined approach requires relatively small changes of the protocol, preserving the current operations flow between the protocol, Node Operators and the Lido DAO. To implement the proposed mitigation, the DAO would have to: 1) implement the upgrade for the protocol smart contracts; 2) establish a committee; 3) write & check the software for monitoring deposits, approving the Merkle roots & exchanging and publishing signed approval messages. As all things require a significant amount of work & time, we propose to start with a committee of one operated by the Lido dev team to unblock deposits in the protocol as soon as possible. ## NodeOperatorsRegistry keyOpIndex To reliably check that the next deposit is safe for the protocol, it is necessary to check that there is no intersection between the set of all historical public keys used for deposits in the DepositContract and the set of all ready to use public keys in [NodeOperatorRegistry](https://github.com/lidofinance/lido-dao/blob/master/contracts/0.4.24/nos/NodeOperatorsRegistry.sol). This means that it is not enough to keep track of only the `deposit_data_root`, but it is also necessary to keep track of pubkey set in the NodeOperatorRegistry. One could build the same Merkle-tree solution for the NodeOperatorRegistry, but this would require a major smart contract rewrite. Therefore, we propose to introduce a Lamport-style counter, which we will increment for every modification of the depositable pubkey set. The pair of `deposit_root` from DepositContract and `key_op_index` from NodeOperatorRegistry provides all the data required for the guardian committee to sign & the deposit contract to check before sending the deposits. ```solidity= function depositBufferedEther( bytes32 depositRoot, uint256 keysOpIndex, Signature[] memory signatures ) external { bytes32 onchainDepositRoot = IDepositContract(depositContract).get_deposit_root(); require(depositRoot == onchainDepositRoot, "deposit root changed"); uint256 onchainKeysOpIndex = INodeOperatorsRegistry(nodeOperatorsRegistry).getKeysOpIndex(); require(keysOpIndex == onchainKeysOpIndex, "keys op index changed"); require(_verifySignatures(depositRoot, signatures), "invalid signatures"); _depositBufferedEther(); } ``` Indeed, in the case when the committee members sign the pair of `depositRoot` and `keysOpIndex`, then in the case when one of the sets changes, the off-chain proof expires and deposit transaction reverts. ## Deposit Security Committee As stated above, we propose to establish the **Deposit Security Committee** dedicated to ensuring the safety of deposits on the Beacon chain: 1) monitoring the history of deposits and the set of Lido keys available for the deposit, signing and disseminating messages allowing deposits; 2) signing the special message allowing anyone to pause deposits once the malicious Node Operator pre-deposits are detected. To make a deposit, we propose to collect a quorum of 2/3 of the signatures of the committee members. Members of the committee can collude with node operators and steal money by signing bad data that contains malicious pre-deposits. To mitigate this we propose to allow single committee member to stop deposits and also enforce space deposits in time (e.g. no more than 150 deposits with 150 blocks in between them). This design ensures the protocol robustness even with single honest committee member. The impact is limited to about, say 4800 ETH at most (150 keys allowed within a time window, 32 ETH deposited to every key). False positive pause would stop the deposits for couple days. Positive stop reveals the rogue committee member, which is good for the protocol. Overall, DoS seems not to be a big problem, and if it would be, the DAO can change the mitigation. Each member must generate an EOA address to sign the pair `(depositRoot, keysOpIndex)` with their private key. The addresses of the committee members will be added to the smart contract. Below is the pseudocode of the `depositBufferedEther` function, updated following the above considerations. ```solidity= function depositBufferedEther( uint256 maxDeposits, bytes32 depositRoot, uint256 keysOpIndex, Signature[] memory sortedGuardianSignatures ) external { bytes32 onchainDepositRoot = IDepositContract(DEPOSIT_CONTRACT).get_deposit_root(); require(depositRoot == onchainDepositRoot, "deposit root changed"); require(!paused, "deposits are paused"); require(quorum > 0 && sortedGuardianSignatures.length >= quorum, "no guardian quorum"); require(maxDeposits <= maxDepositsPerBlock, "too many deposits"); require(block.number - lastDepositBlock >= minDepositBlockDistance, "too frequent deposits"); uint256 onchainKeysOpIndex = INodeOperatorsRegistry(nodeOperatorsRegistry).getKeysOpIndex(); require(keysOpIndex == onchainKeysOpIndex, "keys op index changed"); _verifySignatures(depositRoot, keysOpIndex, sortedGuardianSignatures); ILido(LIDO).depositBufferedEther(maxDeposits); lastDepositBlock = block.number; } ``` ## On-Chain Deposit Flow Instead of adding the code directly to the Lido contract, we propose to extract the described functionality to a separate non-upgradable contract – `DepositSecurityModule`. This approach will reduce the gas price of an unsuccessful deposit transaction (e.g. due to deposit data root change) and reduce the number of modifications to the Lido contract - it would be necessary only to wrap `depositBufferedEther` with ACL role and allow `DepositSecurityModule` contract to call the function. `DepositSecurityModule` implements `Ownable` interface, so only the owner could change configuration parameters such as guardian addresses list and security parameters(e.g minDepositBlockDistance, maxDeposits, ...). After deploying and setting up the contract, the ownership would be transferred to the [DAO Agent](https://etherscan.io/address/0x3e40D73EB977Dc6a537aF587D48316feE66E9C8c). ```solidity= contract DepositSecurityModule is Ownable { function setMinDepositBlockDistance(uint256 newValue) external onlyOwner; function setMaxDeposits(uint256 newValue) external onlyOwner; function setPauseIntentValidityPeriodBlocks(uint256 newValue) external onlyOwner; function addGuardians(address[] memory addresses, uint256 newQuorum) external onlyOwner; function addGuardian(address addr, uint256 newQuorum) external onlyOwner; function removeGuardian(address addr, uint256 newQuorum) external onlyOwner; function setGuardianQuorum(uint256 newValue) external onlyOwner /** * The function might be called by the guardian directly * OR by passing a valid guardian's signature. * * blockHeight is required to prevent reply attack. */ function pauseDeposits(uint256 blockHeight, Signature memory sig) external; function unpauseDeposits() external onlyOwner; /** * Calls Lido.depositBufferedEther(maxDeposits), * which is not callable in any other way. */ function depositBufferedEther( uint256 maxDeposits, bytes32 depositRoot, uint256 keysOpIndex, Signature[] memory sortedGuardianSignatures ) external; } ``` ## Off-chain part ### DSC Daemon Each committee member has to run DSC Daemon that monitors the validators' public keys in the `DepositContract` and `NodeOperatorRegistry`. The daemon must have access to the committee member's private key to be able to perform ECDSA signing. The daemon constantly watches all updates in `DepositContract` and `NodeOperatorRegistry`: * If the state is correct, it signes the current `to_sign` struct and emits it to an off-chain message queue. * If the state has malicious pre-deposits, it signs the "something's wrong" message at the current block and attempts to send `pauseDeposits()` tx. ### Depositor Bot The proposal makes the deposits in Lido permissioned: one must gather the quorum of signatures and pass several on-chain checks to make deposit. Therefore, this process must be automated. Lido dev team will run a deposit bot that will deposit buffered ether. The bot will listen to an off-chain message queue and: * if there is a “something's wrong” message, try to pause a protocol with high gas * else if there’s a quorum on the fresh deposit data root, there’s money in the buffer and the gas is low enough, try to call `depositBufferedEther` ## Minor additional changes not related to vuln 1. Mitigation for [A Node Operator can circumvent DAO validator key approval](https://github.com/lidofinance/lido-dao/issues/141). 2. Set DEFAULT_MAX_DEPOSITS_PER_CALL to 150 in [Lido.sol#59](https://github.com/lidofinance/lido-dao/blob/master/contracts/0.4.24/Lido.sol#L59). 3. Prevent creating node operators with [a non-zero staking key limit](https://github.com/lidofinance/lido-dao/blob/master/contracts/0.4.24/nos/NodeOperatorsRegistry.sol#L112). 4. Add batch key removal methods [removeSigningKey](https://github.com/lidofinance/lido-dao/blob/master/contracts/0.4.24/nos/NodeOperatorsRegistry.sol#L260) and [removeSigningKeyOperatorBH](https://github.com/lidofinance/lido-dao/blob/master/contracts/0.4.24/nos/NodeOperatorsRegistry.sol#L272). 5. Add missing event for [trimUnusedKeys](https://github.com/lidofinance/lido-dao/blob/master/contracts/0.4.24/nos/NodeOperatorsRegistry.sol#L207) method. ## Action Plan It is very important to unpause the deposits to the Beacon chain, so we assume the deployment in several stages: 1) single committee member, simple daemon, full-fledged smart contract; 2) multiple committee members on a centralized mq, complex-ish daemon, complex-ish deposit bot, monitoring; 3) multiple committee members on a p2p network. ### Smart contract deploy plan - [ ] Deploy Lido.sol implementation (no init) - [ ] Deploy NodeOperatorsRegistry.sol implementation (no init) - [ ] Deploy DepositSecurityModule.sol (constructor) - [ ] Initialize DepositSecurityModule (add 1 guardian and set quorum to 1) - [ ] Transfer ownership to the DAO Agent - [ ] Create voting with several items: 1. Publishing new implementation of Lido to the APM repo 2. Updating implementaion of Lido app with a new one 3. Publishing new implementation of NodeOperatorsRegistry to the APM repo 4. Updating implementaion of NodeOperatorsRegistry app with a new one 5. Granting new permission DEPOSIT_ROLE for DepositSecurityModule 6. Increase limits for Node Operators to the current available key numbers. ## Links - Pull request with all smart contracts changes (WIP): https://github.com/lidofinance/lido-dao/pull/357 - DepositSecurityModule.sol: https://github.com/lidofinance/lido-dao/blob/feature/deposit-frontrun-protection-upgrade/contracts/0.8.9/DepositSecurityModule.sol - Mitigations research forum post: https://research.lido.fi/t/mitigations-for-deposit-front-running-vulnerability/1239 - Blog post with events log: https://blog.lido.fi/vulnerability-response-update/

    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