pscott
    • 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # VC Slashing Protection ## Description The Validator Client should ensure that it never signs a slashable attestation or a slashable block proposal. To do so, a validator only needs to follow these 3 simple rules: 1. Never sign two different blocks for the same epoch 2. Never sign a surround vote 3. Never sign a double vote The first rule is to protect from proposer slashings; the two following rules are to protect from attester slashings. ## A naive implementation A straightforward approach would be to use a simple DB in which we store every block we proposed and every attestation we signed. Everytime we need to check for a new block or attestation, we just scan the DB and check if a similar block/attestation already exists, and if the new attestation/block is valid against all entries in the DB. Needless to say this is extremely inefficient, both in terms of lookup time and DB size. ## A conservative implementation See [this issue](https://github.com/sigp/lighthouse/issues/254). ## A suggested implementation ### Stored data It turns out the minimal information we need to store is pretty light. Given that a validator should create an attestation for every epoch but not necessarily propose a block for each epoch, I would suggest having two separate files. ```rust struct ValidatorHistoricalBlock { epoch: Epoch, preimage_hash: Hash256, } ``` ```rust struct ValidatorHistoricalAttestation { source_epoch: Epoch, target_epoch: Epoch, preimage_hash: Hash256 } ``` > [name=pscott] Where preimage refers to the data we would send to the signing function. Not sure how to make this clear. > [name=michaelsproul] The spec refers to this as the "signing root" for blocks, and I think we could use the same term without confusion for attestations (where the signed data is the `AttestationDataAndCustodyBit`'s hash tree root). These structs could be SSZ-encoded and stored in two separate files (both files being sorted in increasing order; one by `block_epoch` and the other one by `attestation_data_target_epoch`). ### Size Storing this information would require `3 * 8B + 2 * 32B` i.e `88B` of data. > [name=pscott] Maybe a bit more with SSZ encoding? Given that there are 82_125 epochs in a year (`3_600 * 24 * 365 / (64 * 6)`), the total information stored by each validator client would grow by `82_125 * 88B` i.e `6.89 MiB` per year **at most**. ### (cross-client) Portability Using a simple SSZ encoded container could not only facilitate Lighthouse's validator portability but also cross-client portability. Having a standard format could help us test, and could reduce the amount of work needed if a user wishes to switch from using a client to another client using the same validator keys. ### Algorithm to follow #### For blocks: - On validator initialization: 1. Open and deserialize the `proposed_blocks_history` file and load it up in memory. - When a `new_block` arrives: 1. Starting from the most recent block, find the first block in the history such that `historical_block.block_epoch <= new_block.epoch`. > [name=pscott] If no such block exists: if history is empty -> sign block. Else -> there was an error while pruning the DB. - If `new_block.epoch > historical_block.block_epoch`, go to step 4 - else if `(historical_block.block_preimage_hash == Hash256(new_block_preimage))`, continue - else reject block 2. Append the new SSZ-encoded`ValidatorHistoricalBlock` to the `proposed_blocks_history` file. (make sure it works). 3. Append the new `ValidatorHistoricalBlock` to the history kept in memory. (make sure it works) 4. Generate block and sign it 5. Broadcast block #### For attestations: - On validator initialization: 1. Open and deserialize the `signed_attestations_history` and load it up in memory. > [name=pscott] Storing it as a vector is sufficient because most new attestations should be appended to the history, and not inserted in it. If insertion happens, it should be near the end of the vector. If this proves to be a bottleneck, maybe consider a beap? - When a `new_attest_data` arrives: 1. Please have a look at this [simple PoC repo](https://github.com/pscott/attestation_slashing_protection) and my [attempt at formalizing the correctness of this algorithm](https://hackmd.io/@6Uku5jlsSVewmiY5aPVYIA/S1eoIqSKr/edit). - For every target epoch higher than the `new_attestation` target epoch, check that the corresponding source epoch is higher than the `new_attestation` source epoch (checking that the `new_attestation` is not surrounded by any previous vote). - If the `new_attestation` target epoch is already in the historical attestation list, check that they have the same hash (checking for double votes). - For every target epoch between the `new_attestation` source epoch and the `new_attestation` target epoch, check that the corresponding source epoch is smaller than the `new_attestation` source epoch (checking we're not surrounding any previous votes). > [name=pscott] small optimization: rather than the source epoch we can start at the target following the source epoch. 3. Append the new SSZ-encoded`ValidatorHistoricalAttestation` to the `block_proposer_history` file. (make sure it works) 4. Append the new `ValidatorHistoricalAttestation` to the history kept in memory. (make sure it works) 5. Generate the attestation and sign it 6. Broadcast attestation. ### Pruning suggestions #### By finalized block - One simple idea is to remove from the history all attestations that have a target epoch smaller than the current finalized epoch. However this opens up an attack vector in which the beacon node "lies" about finalized attestations and prunes the whole DB, cancelling out any protection. #### By epoch distance - Another idea would be to prune by epochs, keeping only the attestations that have a source epoch at least `X` epochs away from the latest signed attestation. `X` could be any number high enough that would allow us to be sure that no new attestation could have a target epoch smaller than the first target epoch in our history. Finding such an `X` sounds arbitrary, but if big enough, might be an acceptable solution. ## Attack vectors ? 1. The Beacon node could simply ask the validator client to sign an attestation that has a really small source epoch and a really high target epoch. This would result in validator no longer signing any attestations for a big period of time, as it would be signing "surrounded" votes. ## Proof ? See [my attempt at prooving the correctness of the attestation checking algorithm](https://hackmd.io/@6Uku5jlsSVewmiY5aPVYIA/S1eoIqSKr/edit).

    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