Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Indexed Types for a Statically Safe WebAssembly

Published: 05 January 2024 Publication History
  • Get Citation Alerts
  • Abstract

    We present Wasm-prechk, a superset of WebAssembly (Wasm) that uses indexed types to express and check simple constraints over program values. This additional static reasoning enables safely removing dynamic safety checks from Wasm, such as memory bounds checks. We implement Wasm-prechk as an extension of the Wasmtime compiler and runtime, evaluate the run-time and compile-time performance of Wasm-prechk vs WebAssembly configurations with explicit dynamic checks, and find an average run-time performance gain of 1.71x faster in the widely used PolyBenchC benchmark suite, for a small overhead in binary size (7.18% larger) and type-checking time (1.4% slower). We also prove type and memory safety of Wasm-prechk, prove Wasm safely embeds into Wasm-prechk ensuring backwards compatibility, prove Wasm-prechk type-erases to Wasm, and discuss design and implementation trade-offs.

    References

    [1]
    Bytecode Alliance. 2019. Wasmtime: A fast and secure runtime for WebAssembly. https://wasmtime.dev/ Accessed: 2023-06-29
    [2]
    Ravi Chugh, David Herman, and Ranjit Jhala. 2012. Dependent types for JavaScript. In Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). https://doi.org/10.1145/2384616.2384659
    [3]
    Charlie Curtsinger and Emery D. Berger. 2013. STABILIZER: statistically sound performance evaluation. In Architectural Support for Programming Languages and Operating Systems (ASPLOS). https://doi.org/10.1145/2451116.2451141
    [4]
    Leonardo De Moura and Nikolaj Bjørner. 2008. Z3: An Efficient SMT Solver. In Theory and Practice of Software, International Conference on Tools and Algorithms for the Construction and Analysis of Systems (TACAS/ETAPS). https://doi.org/10.5555/1792734.1792766
    [5]
    Emscripten Contributors. 2015. emscripten. https://emscripten.org/ Accessed: 2023-06-29
    [6]
    Matthias Felleisen, Robert Bruce Findler, and Matthew Flatt. 2009. Semantics engineering with PLT Redex. https://redex.racket-lang.org/
    [7]
    Cormac Flanagan and K. Rustan M. Leino. 2001. Houdini, an Annotation Assistant for ESC/Java. In International Symposium of Formal Methods Europe (FME): Formal Methods for Increasing Software Productivity. https://doi.org/10.5555/647540.730008
    [8]
    Adam T. Geller, Justin Frank, and William J. Bowman. 2023. Indexed Types for a Statically Safe WebAssembly Artifact. https://doi.org/10.1145/3580426
    [9]
    Samuel Ginzburg, Mohammad Shahrad, and Michael J. Freedman. 2023. VectorVisor: A Binary Translation Scheme for Throughput-Oriented GPU Acceleration. In USENIX Annual Technical Conference (USENIX ATC). isbn:978-1-939133-35-9 https://www.usenix.org/conference/atc23/presentation/ginzburg
    [10]
    Andreas Haas, Andreas Rossberg, Derek L. Schuff, Ben L. Titzer, Michael Holman, Dan Gohman, Luke Wagner, Alon Zakai, and J. F. Bastien. 2017. Bringing the web up to speed with WebAssembly. In International Conference on Programming Language Design and Implementation (PLDI). https://doi.org/10.1145/3062341.3062363
    [11]
    Abhinav Jangda, Bobby Powers, Emery D. Berger, and Arjun Guha. 2019. Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code. In USENIX Annual Technical Conference (USENIX ATC). https://doi.org/10.5555/3358807.3358817
    [12]
    Ranjit Jhala and Niki Vazou. 2020. Refinement Types: A Tutorial. arXiv:2010.07763. arxiv:2010.07763
    [13]
    Ming Kawaguchi, Patrick Maxim Rondon, and Ranjit Jhala. 2009. Type-based data structure verification. In International Conference on Programming Language Design and Implementation (PLDI). https://doi.org/10.1145/1542476.1542510
    [14]
    Milod Kazerounian, Niki Vazou, Austin Bourgerie, Jeffrey S. Foster, and Emina Torlak. 2018. Refinement Types for Ruby. In Verification, Model Checking, and Abstract Interpretation - 19th International Conference, VMCAI. https://doi.org/10.1007/978-3-319-73721-8_13
    [15]
    A. Mine. 2001. The octagon abstract domain. In Working Conference on Reverse Engineering. https://doi.org/10.1109/WCRE.2001.957836
    [16]
    J. Gregory Morrisett, David Walker, Karl Crary, and Neal Glew. 1999. From System F to Typed Assembly Language. ACM Transactions on Programming Languages and Systems (TOPLAS), https://doi.org/10.1145/319301.319345
    [17]
    George C. Necula. 1997. Proof-Carrying Code. In Symposium on Principles of Programming Languages (POPL). https://doi.org/10.1145/263699.263712
    [18]
    David Peter. 2023. hyperfine. https://github.com/sharkdp/hyperfine
    [19]
    Natalie Popescu, Ziyang Xu, Sotiris Apostolakis, David I. August, and Amit Levy. 2021. Safer at Any Speed: Automatic Context-Aware Safety Enhancement for Rust. OOPSLA, https://doi.org/10.1145/3485480
    [20]
    Louis-Noel Pouchet and Tomofumi Yuki. 2016. PolyBench/C: The Polyhedral benchmark suite, v4.2.1. https://sourceforge.net/projects/polybench/files/polybench-c-4.2.1-beta.tar.gz/download Accessed: 2023-06-29
    [21]
    Patrick Rondon, Alexander Bakst, Ming Kawaguchi, and Ranjit Jhala. 2012. CSolve: Verifying C with liquid types. In Computer Aided Verification (CAV). 744–750. https://doi.org/10.1007/978-3-642-31424-7_59
    [22]
    Patrick Maxim Rondon, Ming Kawaguchi, and Ranjit Jhala. 2010. Low-level liquid types. In Symposium on Principles of Programming Languages (POPL). https://doi.org/10.1145/1706299.1706316
    [23]
    Andreas Rossberg. 2022. WebAssembly Core Specification. https://www.w3.org/TR/wasm-core-2/
    [24]
    David Tarditi, J. Gregory Morrisett, Perry Cheng, Christopher A. Stone, Robert Harper, and Peter Lee. 1996. TIL: A Type-Directed Optimizing Compiler for ML. In International Conference on Programming Language Design and Implementation (PLDI). https://doi.org/10.1145/231379.231414
    [25]
    Niki Vazou, Eric L. Seidel, and Ranjit Jhala. 2014. LiquidHaskell: Experience with Refinement Types in the Real World. In Symposium on Haskell. https://doi.org/10.1145/2633357.2633366
    [26]
    Niki Vazou, Eric L. Seidel, Ranjit Jhala, Dimitrios Vytiniotis, and Simon L. Peyton Jones. 2014. Refinement types for Haskell. In International Conference on Functional Programming (ICFP). https://doi.org/10.1145/2628136.2628161
    [27]
    Panagiotis Vekris, Benjamin Cosman, and Ranjit Jhala. 2016. Refinement Types for TypeScript. In International Conference on Programming Language Design and Implementation (PLDI). https://doi.org/10.1145/2908080.2908110
    [28]
    Hongwei Xi and Robert Harper. 2001. A Dependently Typed Assembly Language. In International Conference on Functional Programming (ICFP). https://doi.org/10.1145/507635.507657
    [29]
    Drew Zagieboylo, G. Edward Suh, and Andrew C. Myers. 2020. The Cost of Software-Based Memory Management Without Virtual Memory. CoRR, abs/2009.06789 (2020), arxiv:2009.06789. arxiv:2009.06789
    [30]
    Christoph Zenger. 1997. Indexed types. Theoretical Computer Science, https://doi.org/10.1016/S0304-3975(97)00062-5

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image Proceedings of the ACM on Programming Languages
    Proceedings of the ACM on Programming Languages  Volume 8, Issue POPL
    January 2024
    2820 pages
    EISSN:2475-1421
    DOI:10.1145/3554315
    Issue’s Table of Contents
    This work is licensed under a Creative Commons Attribution 4.0 International License.

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 05 January 2024
    Published in PACMPL Volume 8, Issue POPL

    Permissions

    Request permissions for this article.

    Check for updates

    Badges

    Author Tags

    1. Indexed Types
    2. Optimization and Compiler Design
    3. Program Logics
    4. Type Systems
    5. WebAssembly

    Qualifiers

    • Research-article

    Funding Sources

    • NSERC

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • 0
      Total Citations
    • 326
      Total Downloads
    • Downloads (Last 12 months)326
    • Downloads (Last 6 weeks)64

    Other Metrics

    Citations

    View Options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Get Access

    Login options

    Full Access

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media