README.md
October 6, 2021 · View on GitHub
Perun CosmWasm: Contract
This repository contains an implementation of the Perun smart contract for CosmWasm.
Repo structure
src/contract.rs,msg.rs,storage.rscore logictypes.rscustom typeserrors.rscustom errorscrypto.rssignature helperstests/tests
examples/schema.rsschema generation
schema/generated JSON schemataCargo.tomlrust project configurationMakefile.tomlbuild commands
Development Workflow
Ensure rustup is installed with target wasm32-unknown-unknown and cargo is available.
Consult the CosmWasm documentation for guidance.
This project uses cargo-make to run dev related tasks. Install it with:
cargo install cargo-make
You can then use the following command to run all CI checks:
cargo make ci
Protocol
A channel is opened by depositing funds for it into the contract by calling Deposit. The participants of the channel can then do as many off-chain channel updates as they want. When all participants come to the conclusion that the channel should be closed, they set the final flag on the channel state, and call Conclude. All of them can then withdraw the outcome by calling Withdraw.
Dispute is only needed if the particpants do not arrive at a final channel state off-chain. It allows any participant to enforce the last valid state, i.e., the mutually-signed state with the highest version number. A dispute is initiated by calling Dispute with the latest available state. A registered state can be refuted within a specified challenge period by calling Dispute with a newer state. After the challenge period, the dispute can be concluded by calling Conclude and the funds can be withdrawn.
State diagram
┌────────┐ ┌─────────────┐ ┌─────────────┐
Deposit │ │ Conclude │ │ Withdraw │ │
──────────►│ OPEN ├────────────────►│ CONCLUDED ├───────────►│ WITHDRAWN │
│ │ │ │ │ │
└───┬────┘ └─────────────┘ └─────────────┘
│ ▲
│ │
Dispute │
│ │
│ │
▼ │
┌────────┐ │
┌─────┤ │ Conclude │
Dis│pute │DISPUTED├────────────────────────┘
└────►│ │
└────────┘
Schema generation
All json schema files can be found in directory schema/.
You can generate them with:
cargo make schema
Release build
A reproducible and optimized production build can be created with:
cargo make optimize
This command requires Docker.
The compiled contract will be placed in artifacts/.
Security Disclaimer
This software is still under development. The authors take no responsibility for any loss of digital assets or other damage caused by the use of it.
Copyright
Copyright 2021 PolyCrypt GmbH.
Use of the source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
