Perun CKB contracts
This repository contains the smart contracts that implement Perun payment channels on Nervos CKB, enabling secure and efficient off-chain transactions backed by CKB’s UTXO architecture.
The design follows the same encoding and verification semantics used in the Perun Ethereum contract.
By applying an Ethereum-style binary encoding format for channel identification, and signed updates, the CKB implementation can validate the same off-chain messages recognized by Ethereum. This ensures:
- a compatible state representation across chains
- cross-chain verifiability of signed updates
- interoperability with Ethereum-based Perun backends
- support for multi-chain Perun channels and swaps
This shared data model allows Perun channels on CKB combined with Perun channels on Ethereum.
Controls access rights to the live Perun channel cell.
Only channel participants can consume or update the channel.
Implements the on-chain state machine for Perun channels.
It validates channel state transitions and enforces correct dispute handling.
Functionally similar to a stateful NFT script with Perun-specific logic.
Manages the channel’s locked assets (CKB or SUDT).
Ensures that only the channel’s participants can withdraw or move funds.
Update the rustc version to 1.85.0 and install the following:
sudo apt install gcc-riscv64-unknown-elf binutils-riscv64-unknown-elf \
libc6-dev-riscv64-cross libc6-riscv64-cross linux-libc-dev-riscv64-cross
wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 18 && rm llvm.sh
cargo install cargo-generate
Add the target:
rustup target add riscv64imac-unknown-none-elf
Build contracts:
chmod +x ./setup_env.shmake preparesource ./setup_env.sh build && make buildRun tests:
source ./setup_env.sh test && make testor run them using the IDE
Additionally, to the available contracts we extracted common functionality into
its own perun-common crate which gives some additional helpers and
convenience functions when interacting with types used in Perun contracts.
A common issue when compiling for RISC-V is the missing file: gnu/stubs-lp64.h
If the necessary packages are already installed, the file /usr/riscv64-linux-gnu/include/gnu/stubs-lp64d.h
should exist instead. This is due to the toolchain using the lp64d ABI (which includes double-precision floating point support) rather than plain lp64.
To resolve this, simply create a symbolic link:
sudo ln -s /usr/riscv64-linux-gnu/include/gnu/stubs-lp64d.h /usr/riscv64-linux-gnu/include/gnu/stubs-lp64.h
Then try compiling again.
