Bobbin Threadbare
    • 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
    # Miden fee model This note contains the current sketch of the fee model for the Miden protocol. Not all aspects of the model have been finalized and there are open questions which may affect the design in significant ways. The full discussion about the fee model can be found [here](https://github.com/0xMiden/miden-base/discussions/1217). ## Preliminaries There are 3 conceptual entities that participate in the Miden protocol which are relevant for the fee model: - **Users** execute, prove, and submit transactions to the network. Each transaction updates the state of a single account, but can consume and produce zero or more notes. - **Batch builders** aggregate transactions into batches. - **Block builders** aggregate batches into blocks. Currently, batch and block building is done by a single centralized node operator. In the future, both batch and block production can be decentralized (e.g., some entities may be involved in batch production while others would be involved in block production). Transactions can also be executed/proven by the network (e.g., when notes interact with network accounts) - we call these *network transactions* to distinguish them from *local transaction* which are executed by the users. However, for the purposes of this discussion, there is no significant difference between local and network transactions. ## Goals The fee model tries to achieve the following goals: - Provide a mechanism for prioritizing transactions if/when the network is congested (i.e., there is more transaction demand than network capacity). - Ensure that batch and block producers are incentivized to include transactions into batches and batches into blocks (i.e., to avoid, empty batches and blocks). - To make fee payment for the users as easy as possible. This includes: - Allow fee payment in multiple currencies to avoid the situation when a user's account has some assets but the user is not able to engage in transactions because they don't have the native asset in the account. - Make fee estimation as simple as possible to ensure that users don't end up underpaying or overpaying fees in most situations. Another auxiliary goal of the fee model is to encourage "note cut-through" when a transaction which consumes some note is included into the same batch/bock as the transaction which generated this note. When this happens, the note is effectively "erased" (i.e., it is not recorded on-chain) . ## Design The design of the fee model is loosely based on the multi-dimensional EIP-1559, and works roughly as follows: - Every transaction includes a fee set by the user. - When a transaction is included in a batch, part of this fee is used to satisfy the protocol-defined base fee for the resources the transaction consumes. The base fee is burned. The remaining portion of the fee is treated as a "tip" for the batch builder. If a transaction fee is insufficient to cover the base fees, it cannot be included in a batch. - When a batch is included in a block, it can pay a "tip" to the block builder. - If a given block consumes more of some resource than its target utilization, the base fee for this resources goes up in the next block. If the block consumes less than the target, the base fee goes down until it reaches some protocol-defined minimum level. ![image](https://hackmd.io/_uploads/rySIB_V-xe.png) ### Resources The resources for which the fees are charged are yet to be finalized, but they will likely include some combination or aggregation of the following: - Number of cycles it takes to execute the transaction. - Number of notes consumed by the transaction. - Number of notes created by the transaction. - Total size of produced on-chain notes (in bytes). - Total size of state deltas of on-chain accounts (in bytes). As mentioned above, for each resources the protocol defines three parameters: - Target utilization. - Maximum utilization. - Minimum fee. For example, for consumed notes it could be something like: - Target utilization: 1000 notes per block. - Maximum utilization: 4000 notes per block. - Minimum fee: 1 unit per consumed note. Then, if the current base fee is 2 units per consumed note and a block includes transactions which consume 2000 notes, the base fee will increase in the next block. If however, the block consumes 500 notes, the base fee will decrease. ### Multi-currency fees The base fee must be paid in the native token of the protocol, however, users should be able to pay transaction fees in any token. To bridge this gap, batch builders can convert user-provided fees into the native token at the rates they deem acceptable during batch construction process. For example, let's say a transaction consumes resources requiring 200 native units in base fees. The user may decide to pay fees in USDC instead and include $0.02 USDC with their transaction. If the current exchange rate is greater than 10000 native units for 1 USDC, then it would be profitable for a batch builder to take the $0.02 USDC and cover the base fee for the user. If, however, the exchange rate is less than 10000 native units for 1 USDC, no batch builder would pick this transaction for batching as it would be unprofitable for them to cover the base fee in exchange for the fee provided by the user. ### Batch anchoring When building a batch, a batch builder must pick an *anchor block* in the chain against which the batch is built (this is needed because the batch builder may not know the the most recent block in the chain). This block will define the base fees for the transactions included in the batch. To make sure that the batch builder does not pick a stale block, the anchor block must be close to the chain tip (e.g., within $n$ blocks of the chain tip where $n$ could be small value - something like 10). If the anchor block is further away from the chain tip than $n$, then the batch cannot be included in a block. Thus, batch builders are incentivized to pick the most recent block as their anchors. ## Action modeling ### Estimating transaction fees When constructing a transaction, the user needs to estimate a transaction fee. This requires: - Calculating resources consumed by the transaction. - Determining base fees needed to be paid for each resource. - Determining the amount of tip to pay for the transaction. Computing consumed resources shouldn't be too difficult and we can provide a kernel procedure to help with this. Determining base fees can be done either by looking at the anchor block of the transaction or getting the information from an external source (e.g., wallet). Determining the tip amount would need to be done with a help of an external source (e.g., the wallet), though, there may be some automated strategies (e.g., set tip to 10% of the base fee). To increase the likelihood of having the transaction included in the chain, the user can pay a bigger tip. This will serve two purposes: - It will incentivize batch builders to prioritize the transaction. - It will protect the user against potential fluctuations of the base fee. If the user wants to pay the fee in non-native currency, they would need to obtain the current exchange rate from an external source (e.g., wallet) and apply it to the estimated fee in the native units. ### Batch constructions When constructing a batch, a batch builder needs to: - Pick transactions to include into the batch. - Pick the anchor block against which to construct the batch. - Decide how much tip to pay to the block producer for this batch. As mentioned above, the batch builder is incentivized to pick the most recent block as the anchor. They are also incentivized to include transactions into the batch because this is the only way for them to get compensated for batch production (i.e., there is no incentive to build empty batches). Batch builder compensation comes from the following sources: - Tips remaining after transactions pay their base fees, minus the tip that the batch builder pays to the block builder. - Extra fees remaining after "note cut-through". These fees remain because users need to allocate base fees for produced/consumed notes, but if the notes are erased, the base fees can be pocketed by the batch builder. - Extra fees remaining from transactions executed against the same account. These fees remain because users would need to allocate base fees for every account update, but if the same account was updated twice in the same batch, the base fee would need to be burned only once. And thus, the batch builder would be able to pocket the difference. The exact strategy for picking transactions for a specific batch may get pretty complex and may require sophisticated "solver" logic. However, it is also possible to use simple "greedy" heuristics which could be sufficient in the vast majority of cases (the only time greedy heuristic would not be optimal is when blocks are at the maximum capacity). ### Block construction When constructing a block, a block builder needs to pick a set of batches which don't violate maximum resource allocations (e.g., all batches in a block should not consume more than 4000 notes) and pay attractive enough tip. This incentivizes the block producer to include batches into blocks (i.e., not to build empty blocks). ## Open questions - Currently, the tip portion of the transaction fee is used to compensate both batch and block builders for their work. Would this result in a situation where the tip portion becomes the dominant part of the fee? - If so, then we may need to introduce block rewards so that block builders are compensated primarily via block rewards. However, this would decrease the incentive for block builders to include batches into blocks (and this may result in some blocks being empty). Is there a way to compensate block builders differently and still retain an incentive for them to build non-empty blocks? For example: - Could block builders receive some portion (e.g., 50% or 75%) of the base fee? - Could there be other incentives for block builders to include batches into blocks? (e.g., using batches in consensus logic). - Even if we introduce block rewards, would tips be sufficient to incentivize batch builders? Or would we need to introduce separate batch rewards? And if so, how can we ensure that batch builders are not incentivized to build empty batches?

    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