danhper
    • 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
      • Invitee
    • 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
    • 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 Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync 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
Invitee
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
--- title: Smart Contracts Upgradeability in DeFi protocols tags: Talk description: Slides for FC22 DeFi workshop slideOptions: theme: white --- <style> .reveal { font-size: 24px; } .two-columns { display: flex; } .col { flex: 1; } .tomorrow-comment, pre .comment, pre .title { color: #8e908c; } .tomorrow-red, pre .variable, pre .attribute, pre .tag, pre .regexp, pre .ruby .constant, pre .xml .tag .title, pre .xml .pi, pre .xml .doctype, pre .html .doctype, pre .css .id, pre .css .class, pre .css .pseudo { color: #c82829; } .tomorrow-orange, pre .number, pre .preprocessor, pre .built_in, pre .literal, pre .params, pre .constant { color: #f5871f; } .tomorrow-yellow, pre .class, pre .ruby .class .title, pre .css .rules .attribute { color: #eab700; } .tomorrow-green, pre .string, pre .value, pre .inheritance, pre .header, pre .ruby .symbol, pre .xml .cdata { color: #718c00; } .tomorrow-aqua, pre .css .hexcolor { color: #3e999f; } .tomorrow-blue, pre .function, pre .python .decorator, pre .python .title, pre .ruby .function .title, pre .ruby .title .keyword, pre .perl .sub, pre .javascript .title, pre .coffeescript .title { color: #4271ae; } .tomorrow-purple, pre .keyword, pre .javascript .function { color: #8959a8; } .reveal pre code { display: block; background: white; color: #4d4d4c; font-family: Menlo, Monaco, Consolas, monospace; line-height: 1.5; border: 1px solid #ccc; padding: 10px; } </style> # Smart Contract Upgradeability in DeFi protocols ### Daniel Perez and Paul Pritz #### Imperial College London <!-- Put the link to this slide here so people can follow --> --- ## Immutability vs Flexibility - Ethereum is immutable by default - Protocols use specific design patterns to work around this to be maintainable in practice - This leads to several risks as functionality can be changed <img width="80%" alt="Immutable contract" src="https://i.imgur.com/xdEIBUt.png"> --- # Proxy Pattern - The EIP 1822 proxy pattern is commonly used to allow upgradeability - This works by delegate calling functions in another contract that can be exchanged <img width="80%" alt="Immutable contract" src="https://i.imgur.com/MTZvrLN.png"> --- # Contract Setting Pattern - This works by splitting functionality in an entry point and a logic contract - The address of the logic contract can be set and changed - This offers more control as not everything is exchangeable but also limits flexibility <img width="80%" alt="Immutable contract" src="https://i.imgur.com/dSqklXC.png"> --- # Governance and Upgradeability - Upgrades are executed by some governance mechanims - Typically two patterns exist: On-chain voting or a multisig with optional off-chain voting - Timelocks are used to allow users to react to changes - trade-off between being able to react to problems and risk for users not being able to react to changes - Trade-off between gate-keeper function of multisig and trust requirement --- # Taxonomy - If large parts of a protocol are upgradeable, the barrier to executing upgrades should be high <img width="80%" alt="Immutable contract" src="https://i.imgur.com/SB8TK6q.png"> --- ## Automating Upgradeability Detection The tool scans contracts for upgradeability using the EIP 1822 pattern: - By convention, EIP 1822 stores the address of the logic contract in a specific storage slot - The tool analyses the bytecode to detect whether this solt has been set - The contract setting pattern and patterns deviating from EIP 1822 are harder to detect as these differ across protocols - The tool also checks for common proxy pattern functions such as `implementation()` --- ## Proxy Pattern Upgradeable Contracts | Protocol | Scanned | Upgradeable | Percentage | |------------|-----------|---------------|--------------| | Aave | 50 | 39 | 78.00% | | MakerDAO | 278 | 10 | 3.60% | | Curve | 111 | 1 | 0.90% | | Convex | 33 | 0 | 0.00% | | Compound | 72 | 36 | 50.00% | --- # Case Study #1: Compound - Everything upgradeable (proxy pattern), everything goes through on-chain governance - Time locks are enforced (currently 2 days) - Reliance on voters to review and understand proposals - Timelocks meant that they couldn't immediately react: $90m funds lost ```solidity if (supplierIndex == 0 && supplyIndex > compInitialIndex) { supplierIndex = compInitialIndex; } Double memory deltaIndex = Double({ mantissa: sub_(supplyIndex, supplierIndex)}); uint supplierTokens = CToken(cToken).balanceOf(supplier); uint supplierDelta = mul_(supplierTokens, deltaIndex); ``` --- # Case Study #2: MakerDAO <div class="two-columns"> <div class="col"> <ul> <li>Everything upgradeable (contract setting pattern), everything goes through on-chain governance</li> <li>Time locks employed (24h)</li> <li>Poor voting design (no lock period) led to flash loan attack on voting mechanism</li> <li>No monetary consequences as attacker only whitelisted a coin - but could have led to loss of all funds [1] </li> </ul> </div> <div class="col"> <img alt="Flash loan proteciton" src="https://i.imgur.com/ghHk9h3.png" width="500px"> </div> </div> <div style="margin-top: 3em; font-size: 1.2rem"> [1] Gudgeon, Lewis, et al. "The decentralized financial crisis." 2020 Crypto Valley Conference on Blockchain Technology (CVCBT). IEEE, 2020. </div> --- # Case Study #3: Convex - Almost nothing upgradeable, except for StakingProxy (which holds almost all vote locked CVX) through contract setting pattern ```solidity function setStakingContract(address _staking) external onlyOwner { require(stakingProxy == address(0) || (minimumStake == 0 && maximumStake == 0), "!assign"); stakingProxy = _staking; } ``` - Upgrade executable by multisig without time delay, all 1.5B USD worth of CVX could have been stolen in single transaction - This has now been fixed in a V2 version of the ConvexLocker ```python ConvexLocker cvxLocker; CvxStakingProxy stakingProxy; cvxLocker.setStakeLimits(0, 0, {"from": multisig}); cvxLocker.setStakingContract(stakingProxy, {"from": multisig}); cvxLocker.setStakeLimits(1, 1, {"from": multisig}); ``` --- # Conclusion - Our tool shows that many protocols are not actually fully immutable - Upgradeability is a necessary evil to allow protocols to be maintained - Protocols with extensive upgradeability should put barriers to upgrade execution in place (efficient frontier)

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