Last updated 2 months ago
The PlutusTx, Plutarch and even some Aiken standard libraries are very inefficient. Hence, most production DApps prefer to have their own in-house standard libraries to address performance issues.
This is the total amount allocated to XSY - High-performance on-chain standard library for Plutarch and Aiken. 0 out of 5 milestones are completed.
1/5
Analysis & Library architecture
Cost: ₳ 48,000
Delivery: Month 2 - Oct 2024
2/5
Library Implementation
Cost: ₳ 48,000
Delivery: Month 5 - Jan 2025
3/5
Iterative Improvement
Cost: ₳ 48,000
Delivery: Month 7 - Mar 2025
4/5
Suite of compiled UPLC of the library
Cost: ₳ 26,000
Delivery: Month 9 - May 2025
5/5
Close-out report and video
Cost: ₳ 30,000
Delivery: Month 10 - Jun 2025
NB: Monthly reporting was deprecated from January 2024 and replaced fully by the Milestones Program framework. Learn more here
We propose a production grade performant and secure on-chain standard library for Plutarch, with potential bindings to Aiken. These will enable developers in building efficient smart contracts.
No dependencies.
All outputs will be open sourced under the Apache 2 license.
The code will be published to the following repository:
We propose the development of a high-performance, secure on-chain standard library for Plutarch, aiming to empower developers to create more efficient and robust smart contracts. This initiative seeks to provide access to curated Plutarch libraries and Aiken bindings with improved execution performance and appropriate abstractions, thus significantly enhancing the development experience within the Cardano ecosystem. Our solution focuses on security, performance, accessibility, and comprehensive documentation, setting a foundational layer for production projects.
Core Principles:
The Cardano ecosystem has seen remarkable growth in tooling and resources, lowering entry barriers for DApp and smart contract development. Despite these advancements, due to computational constraints around on-chain smart contracts, the need for low-level control to optimize performance remains a critical challenge. Plutarch stands out by offering granular control over contract logic. However, lower-level control introduces a trade-off: on one hand, experienced developers are able to craft highly optimized contracts, reducing resource usage and operational costs. On the other hand, the complexity of working with these tools can deter less experienced developers, thus creating barriers to adoption. As a result, many projects develop their own performant libraries, adding to the ecosystem's fragmentation. Our proposed on-chain standard library aims to bridge this gap by offering a robust performance-oriented foundation on top of Plutarch and providing accessible abstractions/utilities to a wider audience. Note that the targeted audience is not limited to Plutarch developers as we will also provide Aiken bindings. However, compiled UPLC code can in theory be imported and used within any on-chain framework. By centralizing and optimizing the library, we reduce redundancy across projects and streamline development processes within the ecosystem.
The subsequent sections outline common performance challenges and new features to be included in the library:
High Assurance
Given the current state of the ecosystem, there is great burden upon DApp developers to ensure the assurance of their smart contracts. However, underlying standard library functions in many cases, are not extensively tested or formally verified. The proposed standard library will be designed with great attention to security and ease of use. The library will be comprehensively tested using property-based testing and formal verification techniques to assert robustness of all library functionalities.
Unrolling recursive calls
Due to the absence of native support for recursion in UPLC, all recursive functions (e.g. pall, pelemAt, etc) rely on the Y-combinator to facilitate recursion. While this method is theoretically robust, it is inefficient in practice as recursive functions are passed repeatedly along the recursion chain. Most of the time, the required number of recursive calls are predictable according to the application context. We therefore propose to unroll recursive calls prior to the UPLC generation. This approach enables a strategic balance between script size (e.g. unrolling of tail calls when traversing a list) and execution unit consumption (i.e., recursion expansion at runtime), potentially yielding substantial performance improvements.
Converting between Scott and Builtin Data
A significant opportunity for performance enhancement lies in the trade-off between using Scott-encoded data versus builtin data structures in smart contract logic. Scott encoding generally offers efficiency advantages when handling complex data structures. However, this efficiency comes with a cost: serializing and de-serializing data into Scott encoding can incur substantial performance penalties. PlutusTx adopts this approach by default, i.e., encoding all builtin structures into Scott encoding. In contrast, tools like Aiken exclusively operate over builtin structures, which might appear to optimize performance by avoiding data structure conversions. However, solely using builtin structures carries drawbacks especially when they are fully traversed or manipulated multiple times. Plutarch provides developers with granular control over these two operating levels, but this can be challenging for those with limited experience in profiling on-chain scripts. To aid developers in making informed choices regarding the appropriate level of abstraction, the standard library will include both utilities and comprehensive documentation.
Early failure
Haskell developers commonly use sum-type data structures such as Maybe and Either to represent function return types that might fail or result in unexpected states. While these patterns are considered idiomatic in Haskell development, they are often viewed as anti-patterns in the development of on-chain smart contracts for two primary reasons:
As an example, consider the `pfind` function below:
This function searches for an element in a list that satisfies a specific predicate f. In practice, pfind might be used to locate an input within a transaction that contains a certain NFT, triggering additional logic. Therefore, it would be more efficient to immediately terminate the execution if the condition is not met. In doing so, this will save on execution units and reduce potential security vulnerabilities that may follow from not adequately addressing the PNothing case.
Also note that the recursive function accepts an argument f, which remains constant throughout the entire recursive execution. In such cases, it would be more efficient to move f to an outer lambda such that it only gets applied once instead of being applied at each recursive call. This is all to illustrate that the current standard library is not sufficient for production use-cases.
Our team consists of highly skilled developers with experience developing open-source tooling (Convex) in the ecosystem. Our developers are extremely experienced in all stages of DApp development on Cardano from design and architecture all the way to mainnet releases. They are intimately familiar with the requirements of DApp protocols, and the nuances of smart contract development on Cardano. We are uniquely positioned to deliver this critical infrastructure to the Cardano ecosystem.
Historically a number of promising well intentioned tools and libraries in the ecosystem did not see much traction upon release. Often this can be the result of the tooling being developed in a vacuum without feedback from production use-cases.
In order to make sure that the proposed framework is well-equipped for production use, we will develop and revise it with feedback from a live mainnet protocol.
Analysis & Library architecture
Library Implementation
Iterative Improvement
Suite of compiled UPLC of the library:
Close-out Video and Report
The video will walk through the entire repository. It will demonstrate how developers can import the library and use it in their own projects. The report will detail the development process of the library along with the future roadmap.
Jean-Frédéric Etienne has more than 15 years of experience in safety and threat analysis and is an expert in several formal verification techniques. He is currently the architecture and technical lead for the Djed implementation on Cardano and has put in place a property-based testing methodology to extensively assess the correctness and robustness of Plutus smart contracts against all potential attacks. He has also specified and proved the adaptation of the Djed protocol on the EUTxO model and has developed a set of Plutus libraries to produce optimized on-chain code.
Jean-Frédéric will be working on security analysis and testing.
Jann Müller is a Haskell programmer with years of experience in writing scalable, mission-critical systems. He has been working with Plutus since its inception and is the maintainer of the sc-tools library for Cardano apps. He is the lead developer of Djed and will be working on the off-chain parts of the framework.
Philip DiSarro is an expert in the field of Compiler Development & Programming Language Theory. He has made significant open-source contributions to the Cardano developer ecosystem. As a co-chair of the IOHK developer experience working group he worked to identify and resolve pain points that DApp developers experience in Cardano. He has a vast wealth of professional experience in smart contract security and auditing on Cardano; and was responsible for the identification and resolution of a large number of critical exploits in production open-source smart contracts. Recently, Philip has concentrated his efforts on designing and deploying effective zero-knowledge proof applications within the Cardano ecosystem. Philip is a senior Haskell developer on the XSY team, a consultant and lecturer for Emurgo, and the CEO and co-founder of Anastasia Labs.
Philip will be contributing to the implementation of the efficient library functions for Plutarch.
Amir H. Meyssami Rad is a Haskell developer and a member of the XSY development team with over two years of experience in developing on Cardano. His expertise spans wallet integration tools, off-chain transaction library development, DApp and on-chain development using Plutus across various projects. His focus will be on implementation, testing and performance benchmarking of the standard library.
Konstantinos Lambrou-Latreille is a Haskell programmer with more than 5 years of relevant experience. He worked for 3 years in IOG on Plutus off-chain tooling such as a node emulator for testing Plutus applications, a transaction building library, and a chain-indexer. He will also be working on the off-chain part of the framework.
2 Engineers total:
On-chain Engineer
Engineer
The absence of a standard library that is sufficiently optimized for production use has resulted in a situation where each product independently develops and maintains their own libraries. This is a huge redundant waste of development time and money. This library aims to resolve that by completely removing the need for developers to reinvent the wheel for every project.