Hayden Adams
    • 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
    • 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 Versions and GitHub Sync 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
  • 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
    # 🔮💸🌊 Plasma Cashflow ⚠️⚠️⚠️ **WORK IN PROGRESS** ⚠️⚠️⚠️ > [color=#4ca9a2] [TOC] # Introduction Plasma Cashflow is an adaptation of Plasma Cash, draws from [Plasma Debit](https://ethresear.ch/t/plasma-debit-arbitrary-denomination-payments-in-plasma-cash/2198), and is based around [Plasma Cash defragmentation](https://ethresear.ch/t/plasma-cash-defragmentation/3410). This document describes the process of depositing, transacting, and exiting the Plasma Cashflow chain. Throughout this process it will provide details regarding how each component can be implemented. # 🏦 Deposit The Plasma contract will live on the Ethereum mainnet. Tokens can be transferred to be owned by this contract. Upon transfer the Plasma contract will issue new tokens on the Plasma chain. Issuance of Plasma chain tokens is done in two steps: 1. Record the deposit to be processed at the beginning of the next block: ``` deposits[next_block_number] += [token_type, start, offset, owner] ``` 2. Increment total deposits for the particular token (eg. ETH, MKR, etc): ``` total_deposits[token_name] += amount_deposited ``` # 🔀 Transact ## Transaction Format #### `Send` ``` ['send', [[[parent_hash, parent_block],...], start, offset, recipient], signature] ``` Send transactions can specify a number of transaction input ranges & send them to a single recipient. Note that all of the input ranges must be contiguous & owned by the same address. #### `Swap` ``` ['swap', [ [ [[parent_hash, parent_block],...], start, offset, recipient], [[[parent_hash, parent_block],...], start, offset, recipient], ..., # n-party swaps are allowed timeout ], [signatures,...] ] ``` Swap transactions are comprised of a number of unsigned send transactions. All owners of all tokens must have signed the swap signatures. ## Defragmentation Any number of contiguous tokens owned by the same private key can be exited without extra storage required. Exiting tokens `(100-500)` is the same gas cost on Ethereum as exiting tokens `(100-5000000)`. However, when tokens are not contiguous each segment adds significant gas usage. For example, exiting `(0-500)` and `(1000-1500)` is two times more expensive than exiting `(0-1000)`. Defragmentation refers to the process of shifting tokens which are owned by a particular owner such that they are contiguous. Strategies can be developed (client-side) to 1) increase the number of contiguous tokens, and 2) avoid creating unnecessary fragmentation of tokens ownership. To reduce fragmentation we must reduce the number of adjacent tokens. However, while transacting we will often increase the number of adjacencies. The growth of adjacencies can be modeled with: ``` Alice sends to Bob If Alice & Bob... | Change in total adjacencies - have no adjacent tokens | +1 - have 1 adjacent token | +0 - have n adjacent tokens | -(n-1) ``` An example of this can be seen here: ``` Alice: $$$$$ Bob: ***** Charlie: ^^ State 1: $$$$$*****^^ Alice sends 3 tokens to Charlie State 2: ^^^$$*****^^ +1 adjacency. ``` We can also use atomic swaps to route payments as a way to avoid creating more adjacencies. eg: ``` Alice: $$$$$ Bob: ***** Charlie: ^^ State 1: $$$$$*****^^ Alice sends 3 tokens to Charlie using an 3 person atomic swap with Bob State 2: $$*****^^^^^ +0 adjacency. ``` ## Validity Proofs Like in Plasma Cash, token histories grow linearly with the number of blocks. This means that validating a particular token can get extremely expensive. Some ways to address these concerns are zkSNARKs, Plasma XT-style checkpointing, and block validity bonds # ⬛ Plasma Blocks ## Transaction Tree Structure As with Plasma Cash, transactions are periodically merklized and then committed on chain. However, the structure of the merkle tree has been updated for simplicity and efficiency gains. The tree is structured as a merkle-sum-tree where the leaf nodes are separated into ranges which have either been effected by a transaction or remained untouched. Then within each leaf, there is a list of transactions which effect that leaf's range. The merkle-sum-tree guarantees that these ranges are positioned correctly & include all tokens. ### Constructing a transaction tree The following is how one might construct a transaction tree: 1. Arrange all transactions ordered by their `start` field. From this, produce the minimal list of ranges which have been altered by the transactions, while making sure to cover every token. For instance: ``` # reference: ['send', [[[...], start, offset, recipient], signature] # With a total_deposit size of 10, # The following transactions: [ tx1: ['send', [[[...], 0, 3, 0x...], 0x...], tx2: ['send', [[[...], 6, 3, 0x...], 0x...], tx3: ['send', [[[...], 7, 2, 0x...], 0x...], ] # Would produce the following buckets: [ (0-2), (3-5), (6), (7-8), (9) ] ``` 2. Create a merkle sum tree of buckets with the relevant transactions at the leaves. The sum is the number of tokens which each bucket covers. eg: ``` ______(10, 0x...)_____ / \ ____(9, 0x...)______ (9) / \ [] (6, 0x...) (3, 0x...) / \ / \ (0-2) (3-5) (6) (7-8) [tx1] [] [tx2] [tx2,tx3] ``` # 🚪 Exit Exits can be submitted to the Plasma contract. They must simply specify a range of tokens they wish to exit, an owner & pay a bond to pay for challenges. ## Exit spent token, exit double spend, & exit invalid history Same as Plasma Cash (see [the spec here](https://karl.tech/plasma-cash-simple-spec/)); however, challenges must provide a particular token within the range attempting to be exited that is invalid. Proving one token is invalid cancels the entire exit. ## Atomic Swap Force Include In order to handle atomic swaps, we must add the ability to force include swap transactions. This game is required when an operator is withholding blocks & users are not able to determine if their swap transaction was included. Users can thereby force the withheld atomic swap transaction to be posted to the main chain. This lets them enough information to exit their new tokens as well as cancel any invalid exits. Signatures from phase 1 of the atomic swap transaction are required for force includes to be accepted. This prevents a malicious atomic swap counter-party from griefing by submitting undesired atomic swap force includes. ### Force include procedure User submits a swap transaction to the mainchain. It must have attached to it all Phase 1 signatures. An exit bond must be paid for every token in the swap. If it is a 3-party atomic swap, then 3 exit bonds must be paid. The force include will go through and cancel any exits of subsequent tokens unless someone shows 1) the atomic swap was already included, or 2) there is a spend of one of the inputs to the atomic swap already. If the force include goes through without fail, then any exits of tokens that are between the force included swap & the previous token the swap references are canceled. ## Token Withdraws If an exit succeeds, a record of the token ranges which have been withdrawn is made. These tokens can never be transacted again. ### Exit Withdrawn Token Challenge If a user attempts to exit tokens which have already been withdrawn, they may be challenged, pointing to the record of withdrawn tokens. ## [TODO] Smart Contract ### Constants ### Storage ### Functions

    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