Shuhei Hiya
    • 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
    • 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 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
    # L2 client spec(chamber spec) This client spec of OVM. A whole document is [here](https://hackmd.io/@syuhei/HJRKfUOwr). ### Modules - [clients](https://hackmd.io/3003WCghTou-oXGBcTmuUg?view#L2-Clients): Plasma aggregator and light client implementation, we will add other L2 client here in the future - [ovm](https://github.com/cryptoeconomicslab/wakkanay/tree/master/src/ovm): core OVM implementation - [db](https://github.com/cryptoeconomicslab/wakkanay/tree/master/src/db): general use case databases. KeyValueStore and RangeDb. - [events](https://github.com/cryptoeconomicslab/wakkanay/tree/master/src/events): EventWatcher polling contract events from Ethereum. - [contract](https://github.com/cryptoeconomicslab/wakkanay/tree/master/src/contract): Contract API. we may use Web3 like library for implementing this. - [network](https://github.com/cryptoeconomicslab/wakkanay/tree/master/src/network): L2 network interface and implementation. would be Pubsub model. - wallet: Key Management ## Primitive Types We have several primitive types for inner representation. ### Bytes ### Address ### Integer ### BigNumber BigNumber = max uint256(L1 dependent) ### List ### Tuple ### Struct ### Range ``` struct Range { start: BigNumber, end: BigNumber } ``` ## Data Structure ### Basic data structure. #### Property ``` struct Property { address: Address, inputs: Bytes[] } ``` ### Plasma data structure #### StateUpdate ``` struct StateUpdate { blockNumber: Integer, depositContractAddress: Address, range: Range, stateObject: Property } Property({ address: StateUpdate.address, inputs: [blockNumber, depositContractAddress, range, stateObject] }) ``` #### Block ``` Block: { blockNumber: Integer stateUpdatesMap: Map<Address, StateUpdate[]> } ``` #### Transaction ``` struct Transaction { deprecatedBlockNumber: Integer, depositContractAddress: Address, range: Range, stateObject: Property } ``` # L2 Clients Developed in [lite client](https://github.com/cryptoeconomicslab/wakkanay-plasma-light-client) and [aggregator](https://github.com/cryptoeconomicslab/wakkanay-plasma-aggregator). ## Common Class ### StateManager Manage StateUpdates which have been verified by Merkle Tree. * getAllVerifiedStateUpdate * getVerifiedStateUpdates(depositContractAddress: Address, start: Integer, end: Integer) * putVerifiedStateUpdate(stateUpdate: StateUpdate) ## Plasma client Plasma Cash's lite client to send a transaction and recieve a transaction verifying coin history. ## Plasma aggregator Plasma aggregator client collects transactions in BlockManager and constructs their Merkle tree. The aggregator submits Merkle Root to Commitment Contract. ### BlockManager * enqueueTransaction(transaction: Transaction) * enqueueStateUpdate(stateUpdate: StateUpdate) * submitBlock * `getBlock(blockNumber: Integer): Promise<Block>` ### HTTP endpoint * POST `/send_tx` * recieve transaction and calculate stateupdate, then returns 201(CREATED) status code. * returns 422 when invalid transaction * returns 422 when not enough amount # Core Database Developed in `db`. Core Databases are general purpose database such as KeyValueStore or RangeDb. RangeDb is a special form of KVS which can handle record using range(start: u64, end: u64) as a key. ## KeyValueStore * `put(key: Bytes, value: Bytes): Promise<void>` * `get(key: Bytes): Promise<Bytes | null>` * `del(key: Bytes): Promise<void>` * `iter(bound: Bytes)`: Creates iterator with bound key. Iterator seek greater than equal bound. * `bucket(name: Bytes)`: Returns bucket instance with bucket name. Bucket just appends a prefix to key but connecting one database. ### Iterator * next(): Promise<{key: Bytes, value: Bytes}> ### RangeDb * `put(start: Integer, end: Integer, value: Bytes): Promise<void>` * `get(start: Integer, end: Integer): Promise<Bytes[]>` * `bucket(name: Bytes): Bucket` `start` and `end` must support 256bit integer. ## Local information Database The database for local information. local infomation is described in [this article](https://medium.com/plasma-group/introducing-the-ovm-db253287af50). We call these database WitnessDatabase. moved WitnessDatabase to [here](https://github.com/cryptoeconomicslab/wakkanay/blob/master/src/ovm/deciders/getWitnesses.ts). We use "hint-data" to query witness database. The format is "type:bucket:key". ### SignedByDb ``` struct SignedByRecord { address, message, signature } ``` A key is address + Hash(message). ### TransactionDb ### RangeAtBlockDb # Network # Core OVM decider https://github.com/cryptoeconomicslab/wakkanay/tree/master/src/ovm OVM decider system check a property is true or false. This system include various deciders and each decider load witness from database to decide. The list of deciders. ### Logical Connective and quantifier * ForAllSuchThat * ThereExistsSuchThat * And * Or * Not ### Atomic deciders * Equal * IsContained * IsSameAmount * ISLessThan * IsValidSignature * VerifyInclusion * ... ## Data Structure ### Decision ``` struct Decision { outcome: bool, challenges: Challenge[] } ``` ### Challenge It stands for validChallenge of a property. e.g.) Challenge of `Not(P)` is `Challenge` ``` struct Challenge { challengeInput: Bytes | null, challengeProperty: Property } ``` ## getWitness `getWitnesses` function get witnesses from database by hint string. ### The format of hint `bucket,type,param` type is KEY, RANGE, ITER or NUMBER. bucket is db bucket where witnesses are stored. THe format of param is different by `type`. For `KEY`, param is hex string of key of KVS db. For `RANGE`, param is L1 specific encoded Range data(hex). For `ITER`, the format is same as `KEY`. For `NUMBER`, param is `${s}-${e}`: s and e are hex string of numbers. # Wallet ### getBalance(): Balance ```json { amount: 10000, decimal: 3, unit: "gwei" } ``` ### sign(message) ### veryfySignature(message, signature, address) ## WalletFactory * We want to inject testnet and dev network. * Switch L1 by environment variable. ### createFromPrivateKey(privateKey: Bytes) Create a wallet instance from private key. ### createFromEncryptedJson(json: string, password: string) Create a wallet instance from encrypted JSON data and a password. Encrypted JSON should be stored at a user's device such as PC or smartphone. The password is provided by the user every time the user opens the wallet. The purpose of this password is for encrypting privatekey. So even if user lost their smartphone, nobody can’t peek(spy?) the password. ### getMetaMaskWallet() Return a wallet instance connecting to Metamask extension. # Contract Wrapper Contract API. we may use Web3 like library for implementing this. - CommitmentContract - DepositContract(Plasma) - AdjudicatorContract - ERC20 - PlasmaPredicate These are minimal requirement. We need more contract wrapper contract repo is [here](https://github.com/cryptoeconomicslab/ovm-contracts) ## CommitmentContract ### submitRoot(root: Bytes32, blockNumber: Integer) ### getEventWatcher() Gets EventWatcher instance connecting to Commitment Contract. ## DepositContract ### deposit(amount: Integer, initialState: Property) ### finalizeCheckpoint(checkpoint: Property) ### finalizeExit(exit: Property, depositedRangeId: Integer) ### subscribeCheckpointFinalized ```js subscribeCheckpointFinalized( handler: (checkpointId: Bytes, checkpoint: [Range, Property]) => void ): void ``` ### subscribeExitFinalized ```js subscribeExitFinalized( handler: (exitId: Bytes) => void ): void ``` ## AdjudicatorContract ### claimProperty(property: Property) ### decideClaimTrue ### subscribePropertyClaimed ``` subscribePropertyClaimed( handler: (claimedProperty: Property, createdBlock: Integer) => void ) ``` # Event Watcher Polling ethereum events. Default polling interval is 10000 seconds, but we can set interval in constructor. ## EventWatcher class ### Constructor ``` constructor(endpoint: URL, targetContract: Address, contractInterface: ContractInterface, options: EventWatcherOptions) ``` `ContractInterface` is created by ethereum contract abi, and most web3 library has this class. It is used by pasing log bytes. options has only polling interval as `interval`. ### addHandler(event: string, handler: EventHandler): void Add handler for a contract event. ### removeHandler(event: string): void Unsubscribe an event and remove all handlers. ### initPolling(errorHandler?: ErrorHandler): void Start polling. ### EventHandler function ``` (event: Log) => void ``` We should think EventHandler argument shouldbe raw log byte data or parsed log data. If EventHandler pass raw log bytes, contractInterface isn't required in EventWatcher's constructor. ### Implementation * https://github.com/cryptoeconomicslab/wakkanay/tree/master/src/events #### Events examples? * BlockSubmitted * ClaimDecided * CheckpointFinalizedEvent * ExitFinalizedEvent Also you can check [contracts](https://github.com/cryptoeconomicslab/ovm-contracts/tree/master/contracts).

    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