Onur
    • 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
    # AutoPrice ## Background ### Control Mechanisms for Trustless Self-Governing Protocols It is a feature of public blockchains, where a protocol parameter needs to adapt to certain conditions, but should not be controlled by a specific participant. The solution is to implement a mechanism where it auto-adjusts, according to quantifiable and objective conditions. The primary example is Bitcoin’s difficulty adjustment. There, variations in average block time are used to dynamically adjust Bitcoin’s block difficulty, every 2016 blocks. Owing to difficulty adjustment, Bitcoin blocks are mined every 10 minutes on average without any external control. Shifts in block time feed back into the difficulty parameter, which then dampens said shifts, creating a negative feedback loop. Here, Bitcoin's designer made use of elementary control theory, setting mean block time as a process variable and difficulty adjustment as the control action: ![](https://i.imgur.com/AgB5paV.png) ### Gas Price Volatility Blockchains have a limited supply, and a vertical supply curve. For that reason, blockchain resources are subjected to very high price volatilities, once user demand surpasses platform capacity. Let's consider Ethereum. Demand for gas isn’t distributed equally around the globe. Ethereum users exist in every inhabited continent, with the highest demand seen in East Asia, primarily China. Europe+Africa and the Americas seem to be on par in terms of demand. This results in predictable patterns that follow the peaks and troughs of human activity in each continent. The correlation between gas usage and price is immediately noticeable, demonstrated by a 5 day period from March 2019. ![](https://solmaz.io/img/gas_price_fee_volatility/fig2.svg) The grid marks the beginnings of the days in UTC, and the points in the graph correspond to hourly averages, calculated as: - Average hourly gas usage per block = Total gas used in an hour / Number of blocks in an hour - Average hourly gas price = Total fees collected in an hour / Total gas used in an hour Price oscillations are caused by the daily demand cycle. When we average out daily chunks of data, we obtain the following profiles: ![](https://solmaz.io/img/gas_price_fee_volatility/fig4.svg) To learn more about gas price volatility in Ethereum, see this [blog post](https://solmaz.io/2019/10/21/gas-price-fee-volatility/). Control mechanisms to stabilize gas prices have been proposed in Ethereum, such as [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md). In this proposal, the feedback loop is set in a way to adjust an in-protocol price floor. This time, the process variable is block fullness. The price floor adjusts dynamically according to block fullness to ensure that demand at a given time does not exceed supplied blockchain throughput. The proposed mechanism does not aim to neutralize long term volatility though---it aims to extract an objective gas price, increase market efficiency and bring only short-term stability to the gas price. The frequency of the control action is every ~13 seconds (Ethereum's block time), where the price can adjust by 1/8. For that reason, hour to hour and day to day volatilities remain. What if we wanted the price to remain stable in the longer term, but also ensure that surges are infrequent enough not to affect the user experience? ## Long-term Gas Price Adjustment The control mechanism admits the following parameters: - `CONTROL_RANGE`: Number of blocks between two consecutive price adjustments. - `TARGET_FULLNESS`: The reference fullness value the mechanism should correct to. - `INITIAL_PRICE`: The initial value of the fixed gas price. - `PRICE_ADJUSTMENT_RATE`: The rate at which price increases or decreases after an adjustment. - `BLOCK_GAS_LIMIT`: The maximum amount of gas that can be used by transactions included in a block. Once every `CONTROL_RANGE` blocks, the following algorithm updates the in-protocol fixed gas price: ```python # blocks: an array of the last CONTROL_RANGE blocks # prev_price: previous fixed price fullnesses = [] for b in blocks: fullnesses.append(b.get_gas_used()/BLOCK_GAS_LIMIT) if median(fullnesses) > TARGET_FULLNESS: next_price = prev_price * (1 + PRICE_ADJUSTMENT_RATE) else: next_price = prev_price / (1 + PRICE_ADJUSTMENT_RATE) ``` We believe that optimal values for above parameters exist, which can be found by a combination of simulations, econometrics and trial & error. Once set, the control mechanism would bring day to day gas price stability to the protocol. ## Simulations The implementation of the simulations below can be found in [this git repository](https://github.com/CasperLabs/fee-market-simulator). ### Generating Demand We treat the demand curve as a [cumulative distribution function](https://en.wikipedia.org/wiki/Cumulative_distribution_function), and use [inverse transform sampling](https://en.wikipedia.org/wiki/Inverse_transform_sampling) to generate prices for the transactions submitted by users. We then verify our method by superimposing the histogram of sampled prices with the original demand curve: ![](https://i.imgur.com/ZPecO3z.png) While simple, this method depends on the following assumption: Changes in demand are reflected by a shifting of the demand curve which doesn't have to be uniform. The exact behavior of the demand curve is often complex, and simple models may fail to capture the nuances of a given market. In our method, increased demand reflects as a uniform *scaling* of demanded quantity with respect to a given price. E.g. in the figure above, changes in demand would cause the blue line to be scaled uniformly and vertically around the horizontal axis. ### Modeling Number of Buyers (Users) per Block Given a demand curve, we can sample as many prices as we want. To model the daily demand cycle realistically, we can use a certain model to set the number of available users in the market that bid for inclusion in a single block. Whether they would send a transaction or get it included would depend on - whether the price is floating or fixed, - and others' transactions and gas prices. Below is a model which oscillates between 3000 and 7000 users per block. ![](https://i.imgur.com/hmZRUvb.png) ### Simulating a Floating Gas Price We try to reproduce the daily demand cycle with a system that allows the gas price to float. Samples from the demand curve determine the willingness-to-pay (WTP) values of the agents. The agents then look at the minimum price of the previous block as a benchmark to determine how much they will set their gas price. By default, agents who can afford it overbid the previous block's minimum price by a factor of `OVERBIDDING_RATE`. - If `WTP <= min_price`, they don't submit a transaction, because they can't afford to get it included. - If `min_price <= WTP < min_price*(1+OVERBIDDING_RATE)`, they submit a transaction with `WTP` as the gas price. - If `WTP >= min_price*(1+OVERBIDDING_RATE)`, they submit a transaction with `min_price*(1+OVERBIDDING_RATE)` as the gas price. With this strategy, we can run a simulation and plot the median gas price from each block to see how it evolves. We let the initial price be relatively low, to see if it eventually converges to the market price: ![](https://i.imgur.com/kDZJacW.png) Here, most agents overbid in the first half of the first day, which results in an exponential trend, due to how they keep multiplying price with the same rate. The trend continues until some agents aren't able to afford getting their transactions included in blocks, after which we see the prices mimic the curve we have given above. Since the agents who can't afford inclusion don't submit transactions, we initially see a drop in the number of transactions submitted per block, which then converges to a stable value. ![](https://i.imgur.com/a4uEQs3.png) Indeed, it converges to around 476, the maximum number of transactions that can exist in a block. ### Simulating Price Adjustment We implement the price adjustment algorithm that we described above. This simulation is simpler than the floating price case in terms agent strategy, since agents have only one option: submit a transaction at the protocol enforced fixed gas price, or not, depending on whether they can afford it: - If `WTP >= fixed_price`, they submit a transaction. - Otherwise, they don't submit a transaction. We run the simulations with the following parameters: ``` BLOCK_GAS_LIMIT = 10_000_000 TX_GAS_USED = 21_000 BLOCK_TIME = 600 BLOCKS_IN_DAY = floor(SECONDS_IN_DAY / BLOCK_TIME) CONTROL_RANGE = BLOCKS_IN_DAY TARGET_FULLNESS = 0.65 PRICE_ADJUSTMENT_RATE = 0.01 ``` Block time is 10 minutes, because simulations take too long otherwise. The first 2 parameters are taken from Ethereum, which result in 476 transactions per block. We set the control range as 1 day, target a median fullness of 65%, and allow the price to adjust 1% at a time. We use the same function as before to generate the number of users per block, and let it run for 40 days: ![](https://i.imgur.com/cCYPA5A.jpg) We set the initial price to 35, and see if it converges to the market price we observed in the previous simulation: ![](https://i.imgur.com/yAz7Y9o.jpg) It indeed converges to ~39, the maximum price we have observed in the previous simulation! This is because of the median fullness value we are targeting, 0.65, is selected to ensure that blocks are roughly 100% full during the height of the demand, with the current degree of daily volatility. This is indeed the case, once the price stabilizes: ![](https://i.imgur.com/AqCaH58.jpg) If we were to plot the process variable, we would see it converge to 0.65: ![](https://i.imgur.com/cbwMnHs.jpg) With price adjustment, transactions don't wait in the transaction pool and immediately get included. If we plot the size of the transaction pool versus time, we should see it converge to zero once the price stabilizes: ![](https://i.imgur.com/VkLe0fv.jpg) There are a few days where a few transactions don't get included immediately, but price adjustment did not claim to eliminate all surges in the first place. Price adjustment remove 99% of the surges, and the remaining 1% can be mitigated through other means, such as users being allowed to pay a premium to prioritize their transactions if the previous couple of blocks were completely full. ### Choosing Optimum Target Fullness TBD ### Price Adjustment during a Long-Term Trend In the previous example, price adjustment successfully absorbed the daily volatility of our toy blockchain. However, we also wonder what would have happened if there were a long-term trend, superimposed with the daily cycle. To answer the question, we use the following demand versus time curve: ![](https://i.imgur.com/FaVUv8b.jpg) It's the same cycle as before, but in the longer term, it increases until maximum height is reached around 100 days, and then decreases with the same rate. We see that price evolves parallel to the trend: ![](https://i.imgur.com/P7dTVVh.jpg) The price reaches a high of 54, after which it subsides and converges back to the usual 39. The important thing is, while we don't observe volatility during the day, the gas price automatically adjusts to new market conditions without an external actor deciding for it. The size of the transaction pool shows us that price adjustment still prevents surges, even when there is a long-term trend with the demand. ![](https://i.imgur.com/AmOtO2c.jpg) # Accounting for Token Price Volatility In the previous sections, we considered a closed economic system where the demand is independent of the price of the token (in fiat) used to pay for gas. # Attacks and Manipulations TBD # Conclusion We introduced a way for blockchain protocols to adjust prices of resources in a self-governing way, without the need for an external actor, and absorb most of the daily volatility. The mechanism uses block fullnesses as a process variable to adjust an in-protocol gas price. This eliminates short term surges, and allows the price to slowly adapt to new market conditions at the same time. WIP

    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