Argument
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • 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 Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    ## Introduction The Light Client (LC) provides a streamlined and efficient way to verify blockchain state transitions and proofs without needing to store or synchronize the entire blockchain. This documentation outlines the client’s features, API endpoints, and data structures, providing developers with comprehensive guidance for effective integration. ## LC high level design At the core of the LC there are two features: - Prove epoch transition on the Aptos chain, which is effectively proving a transition from one set of validator to another one. - Prove at any given point that an account is part of the Aptos state to provide the bridging capabalities between the Aptos chain and Ethereum. ![LC Proofs](https://hackmd.io/_uploads/H1RP0wsMC.png) ### Epoch Transition Proof (ETP) The Aptos consensus has at any given time as set of validators that is charged with executing blocks and sign them to append them to the chain state. A set of given validators is updated at the last block of every epoch on the chain. An epoch on the Aptos chain has a duration of 2 hours. For a given epoch `N` with a set of validators `Vn`, it is expected to have a block for the transition to epoch `N+1` signed by `Vn` containing the new validator set `Vn+1`. It is the job of the LC to produce a proof at every epoch change to verify the signature on the validators for the new epoch. ### Account Inclusion Proof (AIP) To bridge an account from the Aptos chain to the Ethereum chain at any given time the LC needs to prove that the given account exists in the chain state for the latest block produce. To do so, the LC will first need to verify that the signature on the latest block corresponds to the validator list known for the current epoch. Then, it will have to prove that the account is part of the updated state that this block commits. ### Edge case The worst edge case that can happen for our LC is when a user wants to get both proofs at the start of a new epoch, meaning that we want to prove both the ETP and the AIP at the same time. A naïve approach would lead us to a total proving time being equal the sum of their respecting time `Dtotal = Detp + Daip`. However, in our setting we can have an optimistic approach where we consider that the epoch transition received is valid. Thus, starting both proof generation in prallel. As the proving time for the two proofs is equivalent we end up with `Dtotal = 2 * Detp` which can be reduced to `Dtotal = 2 * Dsig_ver_proving` as most of the proving time is dedicated to the signature verification. ## Aptos Data Structures Now that we have in mind the high level features brought by the LC, we can take a closer look to the core data structures in the Aptos codebase that are of interest for us to generate the two proofs. ### `ValidatorVerifier` [*Aptos Core*](https://github.com/aptos-labs/aptos-core/blob/1c6bf2f2940f6357fabcee9260c35ff2ed0119a7/types/src/validator_verifier.rs#L131-L144) The `ValidatorVerifier` is the representation of a validator list. It contains all information about the validators like their public key or their balance. ### `LedgerInfoWithSignatures` [*Aptos Core*](https://github.com/aptos-labs/aptos-core/blob/4eae1fa3cf34218dd8b1f2bc1572bd043c3e58cd/types/src/ledger_info.rs#L153-L155) A `LedgerInfoWithSignatures` represents a signed block by a set of validators. The structure contains two main data of interest to us: the aggregated signature for the block and the block information. This means that the data structures embodies the transition of the chain from one state to another. For an epoch transition, the block information contains data about the next epoch (i.e. the `ValidatorVerifier` for the next epoch). ### `EpochChangeProof` [*Aptos Core*](https://github.com/aptos-labs/aptos-core/blob/4eae1fa3cf34218dd8b1f2bc1572bd043c3e58cd/types/src/epoch_change.rs#L39-L42) The `EpochChangeProof` data structure contains all the necessary data to transition from a given epoch to another one. This can be translated to an `EpochChangeProof` containing all the `LedgerInfoWithSignatures` that represent every increment of epoch along with their respoective change of `ValidatorVerifier`. ### Proof of inclusion for an account The inclusion of an account in the state needs two data structures to be proven. While a `LedgerInfoWithSignatures` represents a new state of the chain signed by a set of validators, this new state is represented by an accumulation of transaction in the Aptos codebase, with each transaction setting a new state checkpoint. This means that we need two data structures representing inclusion proofs to prove that an account exists on the chain: a `TransactionAccumulatorProof` and a `SparseMerkleProof`. ### `TransactionAccumulatorProof` [*Aptos Core*](https://github.com/aptos-labs/aptos-core/blob/4eae1fa3cf34218dd8b1f2bc1572bd043c3e58cd/types/src/proof/definition.rs#L129) A `TransactionAccumulatorProof` is a data structure used to verify that a given transaction is a part of a `LedgerInfoWithSignatures` and thus is a valid part of the state. The inclusion can be conceptually tied to a Merkle proof, leading to a root hash that is part of the message signed by the validators in a `LedgerInfoWithSignatures`. ### `SparseMerkleProof` [*Aptos Core*](https://github.com/aptos-labs/aptos-core/blob/4eae1fa3cf34218dd8b1f2bc1572bd043c3e58cd/types/src/proof/definition.rs#L137-L152) The `SparseMerkleProof` is a Merkle proof for an account leaf in the state tree. Its verification outputs a Merkle Tree root hash, which represents a state checkpoint that is part of a transaction in the `TransactionAccumulatorProof`. ## Verification **Epoch Change Message (Every 2 Hours)**: The Light Client sends the ValidatorVerifier hash along with the epoch change proof. It then extracts the public values (the ValidatorVerifier) and compares them to verify that the proof is accurate and that the computation was successful. **Account Inclusion Message (On Demand)**: The Light Client sends the required Merkle proof data for account inclusion, accompanied by the relevant state hash and the corresponding proof. The Merkle proofs are then used to generate the state root hash, which is compared against the proof output to ensure data consistency. > Note: All necessary data required for on-chain verification, along with the proof itself, will be returned after the computation is completed to enable efficient and accurate validation. ## Implementation To generate the two proofs we need we have created to WP1 programs the can be leveraged both at proving and verification time. Those programs can be found in our [`example-light-client-internals`](https://github.com/wormhole-foundation/example-zk-light-clients-internal/) repositiory. *[`Epoch transition program`](https://github.com/wormhole-foundation/example-zk-light-clients-internal/blob/main/aptos/programs/ratchet/src/main.rs)* *[`Account inclusion proof`](https://github.com/wormhole-foundation/example-zk-light-clients-internal/blob/main/aptos/programs/merkle/src/main.rs)* ### Epoch transition program IO #### Inputs The following data structures are required for proof generation (detailed data structure references can be found at the end of this document): - **Latest Known `TrustedState`**: The most recent known state, representing the trusted state for the current epoch. - **`ValidatorVerifier`:** Validator set information for epoch N, provided by the user. - **`EpochChangeProof`**: Proof structure required to transition to the next epoch. - **`LedgerInfoWithSignatures`:** Signed ledger info that includes the new validator set for epoch N+1, provided by the user. #### Outputs - **Previous `ValidatorVerifier` Hash:** The previous validator verifier hash, used for comparison. - **Ratcheted `ValidatorVerifier` Hash:** The hash representing the new validator set for epoch N+1. ### Account inclusion program IO #### Inputs The following data structures are required for proof generation (detailed data structure references can be found at the end of this document): - **Block Validation** - **Latest `LedgerInfoWithSignatures`:** Contains the signed ledger info that acts as a root of trust for the current epoch. - **`ValidatorVerifier`:** The verifier set for the current epoch. - **Merkle Inclusion** - **Transaction Inclusion in `LedgerInfo`:** Verifies that the specified transaction exists in the block with a valid state checkpoint. - **`TransactionInfo`:** Details of the transaction to be verified. - **Transaction Index in Block:** Position of the transaction within the block. - **`TransactionAccumulatorProof`:** Accumulator proof that confirms the transaction’s inclusion. - **Latest `LedgerInfoWithSignatures`:** Acts as a root of trust. - **Account Inclusion in State Checkpoint:** Verifies that the account exists in the blockchain’s state at the block level. - **`SparseMerkleProof`:** Proof that the account is included in the state. - **Account Key in Tree:** Path of the account within the Merkle tree. - **Value Hash for Account Leaf:** Initial hash used for inclusion verification. #### Outputs - **Previous `ValidatorVerifier` Hash:** The previous validtor verifier hash, used to validate the incoming data. - **State Root Hash:** The root hash of the state, derived from the `TransactionInfo::state_checkpoint`. ### Verification Process and Predicate Integration The Light Client verification mechanism integrates three fundamental predicates to ensure the integrity and authenticity of blockchain data: 1. Predicate $P1(n)$: Validates the existence of a block header at block height $h$ containing the Merkle root $S_h$, which is signed validly by the committee with hash $H_n$. This ensures that the block header and its contents are legitimate and recognized by the current validator set. 2. Predicate $P2(n)$: Confirms the existence of a block header that includes the stake table with hash $H_{n+1}$, signed by the committee with hash $H_n$. This predicate is mandatory for the epoch transition proof where the validator set for the next epoch $(H_{n+1})$ must be authenticated by the current epoch's validators $(H_n)$. 3. Predicate $P3(A, V, S_h)$: Demonstrates the inclusion of value $V$ for account $A$ in the Merkle root $S_h$. This predicate is essential for verifying that a specific account state is included in the verified block. #### Integration with Light Client Programs Epoch Transition Proof (ETP) primarily implements Predicate $P2(n)$. It utilizes the `EpochChangeProof` and the current `ValidatorVerifier` to authenticate the transition from one validator set to another, ensuring that the transition is recognized and signed by the current set of validators. Account Inclusion Proof (AIP) incorporates both Predicate $P1(n)$ and Predicate $P3(A, V, S_h)$. It leverages the `LedgerInfoWithSignatures` to validate the existence and correctness of a block header $(P1)$, and uses `SparseMerkleProof` along with `TransactionAccumulatorProof` to validate the inclusion of an account's state value $(P3)$. ### Sequential Verification for Account Inclusion To demonstrate an account's inclusion at any block height, the verifier, that updates and maintain the latest known validator set hash $(H_n)$, can use the proofs in the following sequence: 1. Ratcheting the Validator Set: A sequence of `EpochChangeProof` $(P2(i) for i = 0..N)$ allows the verifier to authenticate each epoch's transition and update the known validator set accordingly. 2. Validating Account State: Once the latest validator set is established, the Light Client can use the Account Inclusion Proof to verify the presence of an account's state in the latest valid block. This proof uses the final validator set to ensure the account state's inclusion, corresponding to Predicate $P3$ applied to the result of $P1$ for the largest $N$. By structuring the verification process around these predicates, the Light Client ensures the integrity of the blockchain data it processes while providing a clear, verifiable path for external parties to trust the proofs it generates. ### Implementation References To explore the implementation of these verification mechanisms, please refer to our example programs: - [Epoch Transition Program](https://github.com/wormhole-foundation/example-zk-light-clients-internal/blob/main/aptos/programs/ratchet/src/main.rs): Implements the logic for ratcheting through epoch transitions. - [Account Inclusion Proof Program](https://github.com/wormhole-foundation/example-zk-light-clients-internal/blob/main/aptos/programs/merkle/src/main.rs): Provides the mechanism to verify account inclusion through Merkle proofs. ### Run verification The verification for our programs can be done leveraging WP1 features when not on a chain. To do so, leverage the `wp1-sdk` crate and its `ProverClient` structure. Some examples of this can be found in our [tests](https://github.com/wormhole-foundation/example-zk-light-clients-internal/blob/main/aptos/light-client/src/merkle.rs#L250-L255) or [benchmarks](https://github.com/wormhole-foundation/example-zk-light-clients-internal/blob/main/aptos/light-client/benches/merkle/src/main.rs#L61-L65). > Note: > You will need the compiled program to be able to verify a proof for it. The binaries for our programs can also be found in our repository, both for the [ETP](https://github.com/wormhole-foundation/example-zk-light-clients-internal/blob/main/aptos/aptos-programs/artifacts/ratchet-program) and [AIP](https://github.com/wormhole-foundation/example-zk-light-clients-internal/blob/main/aptos/aptos-programs/artifacts/merkle-program).

    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