Skip to main content
QUICK 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 Security被引用数 1
ひとこと要約

Prisma は、制御フローを介して正しい通信プロトコルを強制する直接スタイルの送受信操作を使用して、スマートコントラクトとクライアントロジックを1つのプログラムに統合する、階層のないドメイン固有言語である。これは、プログラム構造にプロトコルを直接埋め込むことで、インターフェースの不一致や通信エラーを排除し、攻撃的クライント制御下でもコンパイラが動作を保持することを形式的に証明する。

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.

研究の動機と目的

  • スマートコントラクトとクライアントロジックの分離によって生じる分散型アプリケーション(dApp)開発におけるセキュリティおよび正しさの課題に対処すること。
  • DAOの脆弱性のような攻撃が引き起こされるような、コントラクトとクライアント間のインターフェースの不一致を排除すること。
  • スマートコントラクトとクライアントロジックを同じ言語およびプログラム単位で記述できる統一されたプログラミングモデルを提供し、複雑さとボイラープレートを低減すること。
  • 制御フローに直接的にプロトコルを埋め込むことで、正しくない相互作用プロトコルをコンパイル時に不可能にする。
  • 複雑な型の体系(例:セッション型)を避けても、単純な型システムで十分にセキュリティが保証されることを示すこと。

提案手法

  • Prisma は、スマートコントラクトとクライアントロジックが1つのプログラムユニット内で定義される、グローバルで階層のないプログラミングモデルを使用する。
  • 1つの参加者が実行すると送信として動作し、別の参加者が実行すると受信として動作する直接スタイルの通信操作を導入する。
  • 通信が制御フローにカプセル化されているため、操作の順序が自然にプロトコルを定義し、明示的なプロトコル仕様の必要性を排除する。
  • 言語は、セッション型や線形論理のような複雑な型体系を避ける、標準の System-F スタイルの型システムを使用する。
  • 形式的意味論と、攻撃的クライント制御下でも動作を保持する正しく構築されたコンパイラを定義する。
  • コンパイラは、不要な操作や高コストの操作を避けることで、トランザクション手数料を最小限に抑えた効率的なブロックチェーンコードを生成する。

実験結果

リサーチクエスチョン

  • RQ1dApp のための統一されたプログラミングモデルは、コントラクトとクライアント間のインターフェースの不一致を排除できるか?
  • RQ2複雑な型システムに依存せずに、直接スタイルの通信操作が正しいプロトコルフローを強制できるか?
  • RQ3制御フローに基づくプロトコルを備えた階層のない言語は、通信の不一致を悪用するプロトコル違反や攻撃を防げるか?
  • RQ4単純な型システムで十分なセキュリティ保証が得られ、高度な型の体系を必要としないか?
  • RQ5そのようなモデルは、実世界のdAppのデプロイに実用的であるほど効率的なコンパイラを生成できるか?

主な発見

  • Prisma は、スマートコントラクトとクライアントロジックを1つのプログラムに統合し、別々の言語スタックの必要性を排除し、開発の複雑さを低減する。
  • 直接スタイルの通信モデルは、制御フローにプロトコルを埋め込むことで、実行時における不一致やプロトコル違反を不可能にする。
  • コンパイラは、攻撃者がクライントを制御してもプログラムの動作を保持することを形式的に証明しており、設計段階からセキュリティを確保する。
  • 実験的評価では、Prisma が生成するコードがブロックチェーン上で効率的で、高コストや冗長な操作を生成するアプローチよりも優れた実行コストを示している。
  • Prisma のアプローチはスマートコントラクトにとどまらず、強い通信保証を必要とするその他の分散システムにも一般化可能である。
  • 事例研究により、Prisma は金融およびクラウドファンディングワークロードを含む実世界のdAppパターンを表現可能でありながら、セキュリティと正しさを維持できることを示している。

より良い研究を、今すぐ始めましょう

論文設計から論文執筆まで、研究時間を劇的に削減しましょう。

クレジットカード登録不要

このレビューはAIが作成し、人間の編集者が確認しました。