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)|2022. 01. 01.
Blockchain Technology Applications and Security인용 수 1
한 줄 요약

Prisma는 도메인 특화된 계층 없는 언어로, 제어 흐름을 통해 직접 스타일의 전송 및 수신 연산을 사용하여 올바른 통신 프로토콜을 강제함으로써 스마트 컨트랙트와 클라이언트 로직을 하나의 프로그램에 통합한다. 프로토콜을 프로그램 구조에 직접적으로 인코딩하여 인터페이스 불일치와 통신 오류를 제거하고, 컴파일러가 악성 클라이언트 제어 하에서도 동작을 유지함을 형식적으로 증명한다.

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는 스마트 컨트랙트와 클라이언트 로직이 동일한 프로그램 단위에 정의되는 글로벌이고 계층 없는 프로그래밍 모델을 사용한다.
  • 한 당사자가 실행할 때는 전송으로 작동하고, 다른 당사자가 실행할 때는 수신으로 작용하는 직접 스타일의 통신 연산을 도입한다.
  • 통신이 제어 흐름 내부에 봉인되어 있어, 연산의 순서가 자연스럽게 프로토콜을 정의하므로 명시적인 프로토콜 사양이 필요 없어진다.
  • 언어는 복잡한 타입 체계(예: 세션 타입 또는 선형 논리)를 피하는 표준 System-F 스타일의 타입 체계를 사용한다.
  • 형식적인 의미론과 정확성에 기반한 컴파일러를 정의하여, 공격자가 클라이언트를 제어하더라도 프로그램 동작을 유지함을 보장한다.
  • 컴파일러는 블록체인 코드를 효율적으로 생성하여 중복되거나 비용이 많이 드는 연산을 방지함으로써 거래 수수료를 최소화한다.

실험 결과

연구 질문

  • RQ1dApp용 통합 프로그래밍 모델이 스마트 컨트랙트와 클라이언트 간의 인터페이스 불일치를 제거할 수 있는가?
  • RQ2복잡한 타입 체계에 의존하지 않고도 직접 스타일의 통신 연산이 정확한 프로토콜 흐름을 강제할 수 있는가?
  • RQ3제어 흐름 기반의 프로토콜을 사용하는 계층 없는 언어가 통신 불일치를 악용하는 프로토콜 위반과 공격을 방지할 수 있는가?
  • RQ4이러한 모델이 고도화된 타입 체계 대신 단순한 타입 체계로도 강력한 보장을 달성할 수 있는가?
  • RQ5결과적으로 생성된 컴파일러는 실제 dApp 배포에 실용적으로 충분히 효율한가?

주요 결과

  • Prisma는 스마트 컨트랙트와 클라이언트 로직을 하나의 프로그램에 통합하여 별도의 언어 스택이 필요 없고 개발 복잡성이 감소한다.
  • 직접 스타일의 통신 모델은 제어 흐름에 프로토콜를 인코딩함으로써 런타임 시 프로토콜 불일치나 위반이 불가능하게 하여 프로토콜 정확성을 보장한다.
  • 컴파일러는 공격자가 클라이언트를 제어하더라도 프로그램 동작을 유지함을 형식적으로 증명하여 보안을 구축함에 있어 정확한 설계를 보장한다.
  • 실험적 평가에서 Prisma가 생성한 코드는 블록체인 상에서 효율적이며 낮은 실행 비용을 유발하며, 비용이 많이 들거나 중복되는 연산을 생성하는 기존 접근 방식보다 뛰어나게 성능을 발휘한다.
  • Prisma의 접근 방식은 스마트 컨트랙트를 넘어서 강력한 통신 보장을 필요로 하는 다른 분산 시스템에도 일반화될 수 있다.
  • 사례 연구를 통해 Prisma는 금융 및 크라우드 펀딩 워크로드를 포함한 실제 dApp 패턴의 표현력을 유지하면서도 보안성과 정확성을 확보함을 입증했다.

더 나은 연구,지금 바로 시작하세요

연구 설계부터 논문 작성까지, 연구 시간을 획기적으로 줄여보세요.

카드 등록 없음 · 무료 플랜 제공

이 리뷰는 AI가 만들고, 인간 에디터가 검토했습니다.