Skip to main content
QUICK REVIEW

[Paper Review] Prisma: A Tierless Language for Enforcing Contract-Client Protocols in Decentralized Applications (Extended Abstract)

David Richter, David Kretzler|arXiv (Cornell University)|Jan 1, 2022
Blockchain Technology Applications and SecurityComputer Science1 citations
TL;DR

Prisma is a tierless domain-specific language that unifies smart contract and client logic in a single program, using direct-style send-and-receive operations to enforce correct communication protocols via control flow. It eliminates interface mismatches and communication errors by encoding protocols directly in program structure, and formally proves that its compiler preserves behavior even under adversarial client control.

ABSTRACT

Decentralized applications (dApps) consist of smart contracts that run on blockchains and clients that model collaborating parties. dApps are used to model financial and legal business functionality. Today, contracts and clients are written as separate programs - in different programming languages - communicating via send and receive operations. This makes distributed program flow awkward to express and reason about, increasing the potential for mismatches in the client-contract interface, which can be exploited by malicious clients, potentially leading to huge financial losses. In this paper, we present Prisma, a language for tierless decentralized applications, where the contract and its clients are defined in one unit. Pairs of send and receive actions that "belong together" are encapsulated into a single direct-style operation, which is executed differently by sending and receiving parties. This enables expressing distributed program flow via standard control flow and renders mismatching communication impossible. We prove formally that our compiler preserves program behavior in presence of an attacker controlling the client code. We systematically compare Prisma with mainstream and advanced programming models for dApps and provide empirical evidence for its expressiveness and performance. The design space of dApp programming and other multi-party languages depends on one major choice: a local model versus a global model. In a local model, parties are defined in separate programs and their interactions are encoded via send and receive effects. In a global language, parties are defined within one shared program and interactions are encoded via combined send-and-receive operations with no effects visible to the outside world. The global model is followed by tierless [Christian Queinnec, 2000; Cooper et al., 2007; Choi and Chang, 2019; Fowler et al., 2019; Serrano et al., 2006; Serrano and Prunet, 2016; Radanne et al., 2016; Weisenburger et al., 2018] and choreographic [Kohei Honda et al., 2011; Fabrizio Montesi et al., 2014; Saverio Giallorenzo et al., 2020] languages. However, known approaches to dApp programming follow the local model, thus rely on explicitly specifying the client-contract interaction protocol. Moreover, the contract and clients are implemented in different languages, hence, developers have to master two technology stacks. The dominating approach in industry is Solidity [Mix, 2019] for the contract and JavaScript for clients. Solidity relies on expressing the protocol using assertions in the contract code, which are checked at run time [Solidity documentation - common patterns, 2020]. Failing to insert the correct assertions may give parties illegal access to monetary values to the detriment of others [Nikolić et al., 2018; Luu et al., 2016]. In research, contract languages [Ankush Das et al., 2019; Michael J. Coblenz, 2017; Franklin Schrans et al., 2018; Franklin Schrans et al., 2019; Michael J. Coblenz et al., 2019; Michael J. Coblenz et al., 2019; Reed Oei et al., 2020; Sam Blackshear et al., 2019] have been proposed that rely on advanced type systems such as session types, type states, and linear types. The global model has not been explored for dApp programming. This is unfortunate given the potential to get by with a standard typing discipline and to avoid intricacies and potential mismatches of a two-language stack. Our work fills this gap by proposing Prisma - the first language that features a global programming model for Ethereum dApps. While we focus on the Ethereum blockchain, we believe our techniques to be applicable to other smart contract platforms. Prisma enables interleaving contract and client logic within the same program and adopts a direct style (DS) notation for encoding send-and-receive operations (with our awaitCl language construct) akin to languages with async/await [Gavin M. Bierman et al., 2012; Scala async rfc]. DS addresses shortcomings with the currently dominant encoding of the protocol’s finite state machines (FSM) [Mix, 2019; Michael J. Coblenz, 2017; Franklin Schrans et al., 2018; Franklin Schrans et al., 2019; Michael J. Coblenz et al., 2019; Michael J. Coblenz et al., 2019]. We argue writing FSM style corresponds to a control-flow graph of basic blocks, which is low-level and more suited to be written by a compiler than by a human. With FSM style, the contract is a passive entity whose execution is driven by clients. whereas the DS encoding allows the contract to actively ask clients for input, fitting dApp execution where a dominant contract controls execution and diverts control to other parties when their input is needed. In the following Prisma snippet, the payout function is a function invoked by the contract when it is time to pay money to a client. In Prisma, variables, methods and classes are separated into two namespaces, one for the contract and one for the clients. The payout method is located on the contract via the annotation @co. The body of the method diverts the control to the client using awaitCl(...) { ... }, hence the contained readLine call is executed on the client. Note that no explicit send/receive operations are needed but the communication protocol is expressed through the program control flow. Only after the check client == toBePayed that the correct client replied, the current contact balance balance() is transferred to the client via transfer. @co def payout(toBePayed: Arr[Address]): Unit = { awaitCl(client => client == toBePayed) { readLine("Press enter for payout") } toBePayed.transfer(balance()) } Overall, Prisma relieves the developer from the responsibility of correctly managing distributed, asynchronous program flows and the heterogeneous technology stack. Instead, the burden is put on the compiler, which distributes the program flow by means of selective continuation-passing-style (CPS) translation and defunctionalisation and inserts guards against malicious client interactions. We needed to develop a CPS translation for the code that runs on the Ethereum Virtual Machine (EVM) since the EVM has no built-in support for concurrency primitives which could be used for asynchronous communication. While CPS translations are well-known, we cannot use them out-of-the-box because the control flow is interwoven with distribution in our case. A CPS translation that does not take distribution into account would allow malicious clients to force the contract to deviate from the intended control flow by sending a spoofed continuation. Thus, it was imperative to prove correctness of our distributed CPS translation to ensure control-flow integrity of the contract.

Motivation & Objective

  • To address the security and correctness challenges in decentralized application (dApp) development caused by separating contract and client logic.
  • To eliminate interface mismatches between contracts and clients that can lead to financial losses, as seen in attacks like the DAO exploit.
  • To provide a unified programming model where contract and client logic are written in the same language and program unit, reducing complexity and boilerplate.
  • To enforce correct interaction protocols by encoding them directly in control flow, making protocol violations impossible at compile time.
  • To demonstrate that a simple type system suffices for security, avoiding complex type disciplines like session types while ensuring strong guarantees.

Proposed method

  • Prisma uses a global, tierless programming model where contract and client logic are defined in a single program unit.
  • It introduces direct-style communication operations that act as sends when executed by one party and receives when executed by the other.
  • Communication is encapsulated within control flow, so the sequence of operations naturally defines the protocol, eliminating the need for explicit protocol specifications.
  • The language uses a standard System-F-style type system, avoiding complex type disciplines like session types or linear logic.
  • A formal semantics and a correct-by-construction compiler are defined, ensuring behavioral preservation under adversarial client control.
  • The compiler generates efficient, low-cost blockchain code, minimizing transaction fees by avoiding redundant or expensive operations.

Experimental results

Research questions

  • RQ1Can a unified programming model for dApps eliminate interface mismatches between contracts and clients?
  • RQ2Can direct-style communication operations enforce correct protocol flow without relying on complex type systems?
  • RQ3Does a tierless language with control-flow-based protocols prevent protocol violations and attacks that exploit communication mismatches?
  • RQ4Can such a model achieve strong security guarantees with a simple type system rather than advanced typing disciplines?
  • RQ5Is the resulting compiler efficient enough to be practical for real-world dApp deployment?

Key findings

  • Prisma unifies contract and client logic in a single program, eliminating the need for separate language stacks and reducing development complexity.
  • The direct-style communication model ensures protocol correctness by encoding it in control flow, making mismatches and protocol violations impossible at runtime.
  • The compiler is formally proven to preserve program behavior even when clients are controlled by an attacker, ensuring security by construction.
  • Empirical evaluation shows that Prisma-generated code is efficient and incurs low execution costs on the blockchain, outperforming approaches that generate expensive or redundant operations.
  • Prisma's approach generalizes beyond smart contracts and could be applied to other distributed systems requiring strong communication guarantees.
  • Case studies demonstrate that Prisma supports expressiveness for real-world dApp patterns, including financial and crowdfunding workloads, while maintaining security and correctness.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.