Alex Vlasov
    • 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
    --- title: (Py)Spec Formal Engineering tags: Talk, pyspec, formal engineering description: View the slide with "Slide Mode". slideOptions: transition: fade theme: beige --- # (Py)Spec Formal Engineering slides: https://hackmd.io/@ericsson49/pyspec-formal-engineering --- ## My background - S/W engineer, mostly Financial S/W - Familiar with Formal Methods for a long time - Mostly around Coq and SMT/SAT solvers - didn't have a (good) chance to apply as S/W Engineer - Joined Eth2 research recently - have a great chance now --- ## My work @TXRX My work @TXRX/PegaSys/ConsenSys: - clock sync, DeFi, oracles - fork choice tests + a bit of bug fixing - pyspec transpilation to Kotlin - pyspec formal engineering But concentrate on the latter here --- ## (Py)Spec ***Formal*** Engineering - Want high quality financial S/W - Bugs can be costly - Even more important for blockchains - Lack of control after deployment ==> Use **Formal** Methods --- ## (Py)Spec Formal ***Engineering*** - Formal Methods are a mostly academic topic - But things are changing - (Very) difficult to employ in a typical industrial setting - ConsenSys, in fact, the first real opportunity for me ==> Concentrate on **Engineering** aspects --- ## ***(Py)Spec*** Formal Engineering - Concentrate on beacon chain pyspec, currently - But should be applicable for Distributed Protocols, in general - E.g. network layer (libp2p), other blockchains, oracles --- ## Key problem Expressive language means it's more difficult to reason about. ==> S/W engineers and FM practioners chase different goals, as a consequence. --- ## Key problem Beacon chain perspective - Formal Methods importance is recognized - But the spec development process is centered around traditional S/W engineering ==> FM practioners needs are largely ignored. My research tries to answer "What can be done about it?" --- ## Beacon chain problems (FM perspective) - Python is a bad choice from FM perspective - lack of tools, semantics, etc - pyspec is not a spec - not only from FM perspective - pyspec is a moving target - syncing can be costly - manual implementations in different languages - easy to introduce bugs --- ## Opportunities Good stuff - EF team is open to suggestions (but won't blindly accept them) - FM importance is generaly recognized - Can introduce simplifying assumptions - Transpilation is not crazy difficult --- ## My approach - "Engineer" the spec - Meta-programming - Tailor FM to match problem domain - Light(er) weight formal methods --- ## Engineer the spec - A spec is arguably the most important artifact - Especially true for the beacon chain case - "Engineer" the pyspec to make it suitable for applying FMs (and reach other goals) - most part of the spec is executable - pyspec - Define requirements for the spec - what does "good spec" mean? --- ## Tailor FM to problem domain - Constrain expressivity but gain simpler formal reasoning - Python subset employed by the pyspec is already restricted - type annotations, limited OO features, limited set of types, no concurrency - Simplified memory model - mostly about restricted aliasing --- ## Meta-programming - Transpile pyspec to a "better" form - pure functional - for formal needs - other langs - for more practical stuff - Executable semantics for a subset of Python - Pehaps, other execution models: - Extensions of Datalog - Differential dataflow --- ## Light(er)-weight FMs - Start from light-weight formal methods (static type checking) - easier to introduce - less annotations (easy to adapt to changes) - still useful - Continue with middle-weight stuff - extended static checking - bounded model checking - concolic execution - But aim at full-blown verification in a long term --- # Current state --- ## Transpilation - Semi-automatic translation to Kotlin - Regular pyspec updates (phse0/phase1) - Used as a base for Mikhail Kalinin's work on Eth1/Eth2 simulation - Several pyspec bugs found+fixed - Working on dataflow analyses - to support translations - starting point for semantic work - Working on a translation to Rust --- ## Research stuff Mostly ready, but not published yet - [Formal Engineering for Blockchains, part 1](https://hackmd.io/REqkGV21T8Kf86Rh_FFN_g) - [Formal Engineering for Blockchains, part 2](https://hackmd.io/mq7a6mOPTYacVux7fssL-Q) - [Formal engineering of beacon chain spec](https://hackmd.io/29oG2wvORLmUekkPnhOjpw) Started to work on "semantics" - typing rules - memory model --- # Plans --- ## Near term plans - Complete dataflow analyses - Fully automated translation to Kotlin - Complete translation to Rust - Implement executable semantics - typing rules - memory model (based on Rust's one) - Spec purification - Pure functional/logic language target - Static analyses - Switch to datalog engines (Souffle, Formulog) --- ## Longer term plans - Complete Formal Engineering series of posts - Trusted Assumption Base concept - Middle-weight Formal Methods --- # Semantics Highlits --- ## Executable "semantics" "Semantics" - a model which allows to tranform the python subset (employed by pyspec) to a "better" form. - pure functional (Coq, Stainless/Scala, WhyML) - other formal frameworks - mainstream langs (Kotlin, Rust, Scala, etc) --- ## Components - start from annotated Python AST - supported features - infer variable declarations - infer types - resolve ambiguities - type libraries (BLS, SSZ, pylib, etc) - typing rules - memory model --- # Memory Model --- ## Some assumptions - Actor model - Protocol is built around a persistent data structure (e.g. blockchain) - Ignore concurrency (inside an actor) - but should be possible in a safe way (e.g. Rust-style) ==> - Pure functions mostly - But mutation is important for state updates --- ## Formal Engineering perspective - Reasoning about mutation can be way more difficult - Pure code can be way more slow Want the best of both ways, under reasonable restrictions --- ## Aliasing Aliasing is the core problem. Several ways to solve: - detect 'no aliasing' at runtime reference - counting + static analysis (Lean, Whiley) - - avoid aliasing - linear/uniqueness types (ATS, Idris, Mercury, Clean, SAC, etc) - avoid "dangerous" aliasing - e.g. Rust's ownership type system with borrowing --- ## "Dangerous" aliasing - Two or more references pointing to the same location - At least one of them is mutable In a concurrent program, access to the location should be synchronized to avoid a *data race*. Rust ownership type + borrow checker prevents such dangerous aliasing. There's either: - one mutable reference - or multiple immutable references --- ## Reasoning and aliasing Formal reasoning about detructive updates is notoriously difficult for very similar reasons. - Formal properties can be seen as *immutable references* - Aliasing means more info about mutations to be propgated --- ## Memory model Typically, some simplifying assumptions are made. Often it's about restricting aliasing: the less aliasing, the less info to propagate. The Rust memory model is very attractive in this respect: - multiple immutable references constitute no problem, as there is no update possible - any mutable reference is exclusive, i.e. there are no other reference to the location. - the approach works well in practice --- ## Fast and Purious My hypothesess are: - the Rust's memory model fits nicely the beacon chain pyspec - the same is true about Distributed Protocol specs, in general - 'Fast and Purious', both goals are achievable: - fast execution (destructive updates) - translation to a pure code w/o blow-up (mutable references are exclusive) --- # Q&A ---

    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