Partisia Blockchain Foundation provides the following reviewed smart contracts, as examples of real world problems with a blockchain solution. The easiest way of getting started coding smart contracts is to learn from concrete examples showing smart contracts solving problems similar to the one you need to solve.
Smart Contracts are written in the Rust programming language, using the Paritisa Blockchain Contract SDK. Tests of contract functionality is written in Java, and uses the Junit contract testing framework.
Contracts of this repository demonstrate the four following feature sets:
- Basic Smart Contracts: These demonstrate how to develop a standard smart contract in Rust for deployment to Partisia Blockchain.
- ZK (Multi-Party Computation): These demonstrate how to use Partisia Blockchain's unique Multi-party computations capability to enhance privacy on Web3, while retaining full auditability.
- Upgradable: These show how to upgrade contracts on Partisia Blockchain, and demonstrate possible governance models.
- Off-Chain: These demonstrate the unique Off-Chain feature, which allows you to implement off-chain servers directly in your on-chain contract, and enables easy versioning of both on-chain and off-chain systems.
The Basic contracts are:
petition
: Implements a petition that users can sign.voting
: Implements majority open ballot vote.ping
: Demonstrates contract-to-contract interaction with a contract that sends a lot of interactions around.dns
: Implements a simplified DNS, which allows users to name individual contract addresses, much like the world-wide DNS system names IP addresses.dns-voting-client
: Example contract using the DNS contract to route invocations to contracts by using the domain name of the wanted contract.nickname
: An even more simplified DNS.access-control
: Showcases how access control systems can be implemented in smart contracts.
The ZK (Multi-Party Computation) contracts are:
zk-average-salary
: Implements an algorithm for determining the average of several users' input values in secret.zk-second-price-auction
: Implements a second-price auction, such that users can bid in secret. Only the second highest bid is revealed.mia-game
: Implements the rules of the Mia game. Demonstrates how to generate randomness on-chain.zk-classification
: Implements evaluation of a pre-trained decision tree on a user-provided input sample. Demonstrates Partisia Blockchain's applicability for machine learning while retaining confidentiality.zk-file-share
: Contract for storing uploaded files as secret-shared variables, to act as a file-sharing service of secret files.zk-statistics
: Demonstrates how to perform statistics on secret-shared data.zk-voting-simple
: Implements majority closed ballot votes, where all votes are secret. Only the vote result is published.zk-immediate-open
: Simplified contract that immediately opens any secret-shared variables uploaded. Demonstrates the life-time flow of thezk_
invocations.zk-multi-functional
: Simplified contract that demonstrates a contract can implement several multi-party computations.zk-struct-open
: Simplified contract that shows how to use Ruststruct
s in smart contracts.
The Off-Chain contracts are:
off-chain-secret-sharing
: Contract that allows user to store secret shares, distributed between a set of nodes.off-chain-publish-randomness
: Contract that automatically provides random bytes to the blockchain, created through a distributed process.
The three Upgradable contracts are examples for the upgrade process of smart contracts:
upgradable-v1
: Can be upgraded to a different contract, using a simple permission system. This contract is the first version of a smart contract.upgradable-v2
: Can be upgraded to, and can be upgraded from, using a hash verification system. This contract is an intermediate version of a smart contract.upgradable-v3
: Can be upgraded to, but does not define any way to be upgraded from. This contract implements a way to be the final version of the smart contract.
All smart contracts can be compiled using the Cargo Partisia Contract tool from the rust
directory:
cargo pbc build --release
The --release
argument ensures that contracts are minimized. Resulting
contract .pbc
files can be found in the rust/target/wasm32-unknown-unknown/release
folder, and can be
directly deployed to Partisia Blockchain.
Individual contracts can be compiled directly from the respective contract's directory.
The smart contract test suite is run by using the following script:
./run-java-tests.sh -bc
The -b
argument ensure that contracts are rebuilt, while the -c
argument
results in a coverage report, located at contract-java-test/target/coverage
.