Structured Contracts in the EUTxO Ledger Model

Polina Vinogradova, Orestis Melkonian, Philip Wadler, Manuel M. T. Chakravarty, Jacco Krijnen, Michael Peyton Jones, James Chapman, Tudor FerariuFMBC@CAV 2024 · OpenReview

TL;DR

This paper introduces the Structured Contract Framework (SCF) to formally define and verify stateful smart contracts on EUTxO blockchains like Cardano. SCF bridges the gap between abstract contract specifications and low-level ledger transitions, enabling rigorous proofs of correctness and allowing for the comparison of different implementations of the same contract.

What Problem Does This Paper Address?

Modern blockchains, particularly those using the Extended UTxO (EUTxO) model (like Cardano and Ergo), support powerful smart contracts. However, the EUTxO model's stateless nature, where transactions explicitly define all state changes, presents a challenge for implementing and verifying stateful programs. While account-based models have established ways to manage state, EUTxO contracts are inherently stateless predicates. This paper addresses the need for a standardized, formal approach to define what it means for a stateful program to be "correctly implemented" on an EUTxO ledger, moving beyond ad-hoc methods and enabling robust verification.

Methods

The authors propose the Structured Contract Framework (SCF). At its core, SCF leverages small-step semantics to define a simulation relation between a high-level transition system representing the abstract smart contract and the low-level transition system of the EUTxO ledger. This simulation relation ensures that the ledger's state transitions accurately reflect the intended state transitions of the smart contract. Key components include:

  • Formalizing EUTxO Semantics: The paper provides a detailed small-step operational semantics for a simplified EUTxO ledger model, defining types like Value, UTXO set, Slot, and Transactions.
  • Simulation Relation: A general definition of a simulation relation between two labeled transition systems is presented.
  • Structured Contract Definition: SCF specializes this simulation for EUTxO ledgers, requiring projection functions that map ledger states (UTXO set) and transactions to abstract contract states and inputs. This ensures that the contract's state is observable from the ledger state and that ledger updates correspond to contract state updates.
  • Mechanization: The framework and its meta-theoretical results have been mechanized using the Agda proof assistant, enabling formal verification.

Datasets

Not discussed in the paper. The paper focuses on formal framework development and case studies rather than empirical evaluation on large datasets.

Key Insights and Ideas

  • Bridging Abstract and Concrete: SCF provides a principled way to connect abstract, high-level specifications of stateful programs with their concrete, low-level implementations on EUTxO ledgers. This is crucial for formal verification.
  • Versatility of EUTxO: The framework demonstrates that EUTxO, despite its stateless nature, can effectively support complex stateful contracts through careful design and verification.
  • Proving Implementation Equivalence: SCF allows for proving that different concrete implementations of the same abstract specification are indeed equivalent, which is valuable for optimization and comparison.
  • Formalizing "Correctness": The paper formalizes what it means for a smart contract to be "correctly implemented" on the ledger, moving beyond informal notions.
  • Mechanization for Trust: Mechanizing the framework in Agda significantly increases confidence in the soundness of the approach.

Key Results

  • Structured Contract Framework (SCF): A novel framework for specifying and verifying stateful smart contracts on EUTxO ledgers.
  • Formalization of EUTxO Semantics: A rigorous small-step semantics for a simplified EUTxO ledger.
  • Case Studies:
    • NFT Minting Policy: Expressing and verifying the property that at most one NFT of a specific policy can exist on the ledger. This highlights how SCF can formalize properties naturally expressed in account-based models.
  • Toggle Contract: Demonstrating two distinct implementations (naive consolidated and distributed) of a single specification, proving their equivalence using SCF. This showcases the framework's ability to compare different implementation strategies.
  • Agda Mechanization: The core results have been mechanized in Agda, providing a verifiable foundation.

Limitations and Future Work

  • Proof Automation: The current approach lacks significant proof automation, which is a challenge due to the potential complexity of user-defined projection functions. Future work aims to improve this.
  • General Contract State Computation: The paper acknowledges that guaranteeing a valid UTXO state update corresponding to a contract update is not always straightforward and is left for future work.
  • Trace-Based Properties: A full formalization of structured contract behavior in terms of trace-based properties is needed.
  • Broader Applicability: The authors suggest extending the framework to more complex contract examples, such as DEXs or account simulations, and applying it to existing contracts for formal verification.
  • Integration with Existing Ledgers: Integrating the framework into existing formal specifications of ledgers like Cardano's is a future goal.

Summary updated

Abstract

Blockchain ledgers based on the extended UTxO model support fully expressive smart contracts to specify permissions for performing certain actions, such as spending transaction outputs or minting assets. There have been some attempts to standardize the implementation of stateful programs using this infrastructure, with varying degrees of success. To remedy this, we introduce the framework of structured contracts to formalize what it means for a stateful program to be correctly implemented on the ledger. Using small-step semantics, our approach relates low-level ledger transitions to high-level transitions of the smart contract being specified, thus allowing users to prove that their abstract specification is adequately realized on the blockchain. We argue that the framework is versatile enough to cover a range of examples, in particular proving the equivalence of multiple concrete implementations of the same abstract specification. Building upon prior meta-theoretical results, our results have been mechanized in the Agda proof assistant, paving the way to rigorous verification of smart contracts.
BibTeX
@inproceedings{vinogradova2024structured,
  author = {Polina Vinogradova and Orestis Melkonian and Philip Wadler and Manuel M. T. Chakravarty and Jacco Krijnen and Michael Peyton Jones and James Chapman and Tudor Ferariu},
  title = {{Structured Contracts in the EUTxO Ledger Model}},
  booktitle = {FMBC@CAV},
  year = {2024},
  url = {https://openreview.net/forum?id=joDEdTxGAW},
}

Loading related content...

Figure