HackMD
  • Prime
    Prime  Full-text search on all paid plans
    Search anywhere and reach everything in a Workspace with Prime plan.
    Got it
      • Create new note
      • Create a note from template
    • Prime  Full-text search on all paid plans
      Prime  Full-text search on all paid plans
      Search anywhere and reach everything in a Workspace with Prime plan.
      Got it
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • 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
      • More (Comment, Invitee)
      • Publishing
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Save as template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
    Menu Sharing Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Gist
    Import
    Dropbox Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    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
    More (Comment, Invitee)
    Publishing
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like BookmarkBookmarked
    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

    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 lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    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

    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

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    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

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    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. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        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
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully