shelvenzhou
    • 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
    • Make a copy
    • 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 Make a copy 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
    # 20230220 - Andrew Q&A > hey Shelven, we are writing some follow up paper mostly focusing on new vuln disclosures in Secret but explaining some differences between Obscuro Phala Oasis also. Hi there, good to chat again. > I have a couple of follow up questions from last time basically! > First - while Phala is an L2 for Ethereum, is it the case that the Phat Contracts are written in rust/wasm? Basically I'm trying to see if pruntime contains evm code or mainly only wasm > wiki.phala.network/en-us/build/stateless/language-basic/ following with this basically Phala is not an L2 for Ethereum, we are a parachain of Polkadot (and Khala is the parachain for Kusama). Our Phat Contract is running off-chain so technically it can serve any blockchain, and we say it's the missing computation unit for Ethereum smart contract for commercial reasons. To write Phat Contract you will need to use [ink! language](https://github.com/paritytech/ink). It's a Rust-based DSL and is finally compiled to WASM. There is no EVM code in Phala runtime (pRuntime in short, it's in SGX). We implement the WASM runtime in pRuntime which is mainly a migration of the [pallet-contracts](https://github.com/paritytech/substrate/tree/master/frame/contracts) from Substrate SDK. Of cource we replace the underlying implementation to the off-chain version, and we call it [pink](https://github.com/Phala-Network/phala-blockchain/tree/master/crates/pink) (Phala ink! runtime). > mainly we're looking at; > - how the TEE execution provides state consistency / ensure you can only execute transactions after > they've been committed/finalized? In Dotsama ecosystem, actually a parachain does not provide blocks itself. The Polkadot/Kusama serves as the relaychain to produce blocks for all the parachains. And pRuntime only accepts the blocks that are already finialized (we implement a light client in pRuntime). Also in Polkadot concensus, there is no revert after blocks are finalized. > - how the TEE execution interacts with persistent storage like SSTORE/SLOAD in evm. Does it leak exactly which record is being accessed? We don't support EVM so no SSTORE/SLOAD support either. But ink! contract also can read/write storage, and this is done through the [host functions](https://github.com/paritytech/substrate/blob/master/frame/contracts/src/wasm/runtime.rs#L1004-L1012) in ink! runtime. The official ink! contract is running on-chain. To move it off-chain, we mainly replace its storage to a [TrieDB](https://github.com/Phala-Network/phala-blockchain/blob/master/crates/pink/src/storage.rs) in SGX memory. All these logic is in SGX so no leakage. > - replay protection in the application state storage, like does it check a merkle trie on each read? Yes, the merkel trie check happens at the first place when the block is synced to our pRuntime following the light client (implementation [here](https://github.com/Phala-Network/phala-blockchain/blob/master/crates/phactory/src/prpc_service.rs#L163-L287)). > I see there's like a "get" method implemented in pink storage, i think this relates to this comment from whitepaper: > "Contract states are encrypted and checkpointed on the blockchain with a symmetric key" > How does this work, what happens if your contract state is really large, does it decrypt the entire thing at once? (I know the point isn't to have an ERC20 token implemented in phala contract but i guess thats what im asking about :p) This may work in an undesired way. - Only transactions are stored in blocks on-chain, not contract states. The latest contract states are only available in our off-chain workers (in SGX memory, so encrpypted) and are never written back to chain. Now we keep some checkpoints in local filesystem with SGX sealing as cache, but workers can always replay all the historical transactions on-chain from the start. FYI, the transactions to a contract are also end-to-end encrypted using ECDH with ContractKey. - To get the states, you need to query the workers directly. The queries are also end-to-end encrypted using ECDH with WorkerKey. - One missing part in our key rotation implementaion is the re-encryption of the contract states, since all the ContractKeys are changed with the MasterKey rotation. Now it's not a problem for the Phat Contract release since there is no historical contract states, but will be when we enable the regular key rotation after release. The general idea is to set a period of time for the workers to update the in-memory TrieDB to amortize the cost.

    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