Warning
All smart contracts provided in this repo is for research, experiments and demostrations only. They have not been audited for security. Deloying them to mainnet may cause loss of funds.
This repository contains proof-of-concept implementations of a bridge between Sui and Bitcoin SV and a bridge between Ethereum and Bitcoin SV.
For Sui:
- In cli: a client written in Rust to interact with the Sui contracts and a python script sui_demo.py for demos.
- move: The Move code for the smart contracts to be published on Sui.
For Ethereum:
- cli: a python script evm_demo.py to semi-automate a demo.
- evm: the solidity smart contracts and javascripts to deploy and interact with the Ethereum contracts.
For ZKP used by both Sui and Ethereum bridges:
- zk_engine: The zero-knowledge component of the bridges.
- zkscript_package: A git submodule that is used to build complex Bitcoin Scripts (zkSNARK verifiers).
The repository requires
- Python >= 3.12.
- Rust (with Cargo >= 1.86).
- Sui for Sui. If you want to use the Sui localnet, you might want to install the Sui explorer.
- Hardhat for Ehtereum.
- wild-bit-lab for Bitcoin SV regtest.
To initialise the repository, execute the following commands:
git clone https://github.com/nchain-innovation/tcpBridge.git
cd tcpBridge
git submodule update --init --recursive
git submodule update --remote
cd zkscript_package
pip install -r requirements.txt
cd ../cli
pip install -r requirements.txt
To setup the zk engine, i.e., generating proving and verification keys, execute the following commands.
The repository already contains example setup files required for the setup
command.
cd zk_engine
cargo run --release -- setup
Note that this is only needed once for both bridges. The proof system is designed such that the same verification key and proving key can be used for all bridges and bridged tokens.
See also docs/zk_engine.
-
Locate bitcoin.conf for your Regest and update bsv_config.toml to make sure that the port number is the same as rpcport. If you are using wild bit lab, then it is under
./wild-bit-lab/data/
-
Add the following line to bitcoin.conf if they do not exist.
maxscriptsizepolicy=100000000
-
Start or restart Regtest and make sure at least 100 blocks are mined.
Note
If you are using a testnet
you can get funding from the sCrypt Faucet.
Note
You can print to screen the information contained in your wallet using the following command python3 -m wallet_manager_ui --network <NETWORK>
, where <NETWORK>
can be either regtest
, testnet
, or mainnet
.
you can follow the link in Requirement 3 or the steps below to setup Sui.
-
Install Sui and a local explorer.
brew install sui brew install sui-explorer-local
-
Initialise Sui. You can just press ENTER following the prompts.
sui client
-
Start Sui with facucet.
RUST_LOG="off,sui_node=info" sui start --with-faucet --force-regenesis
-
Run the following command to use localnet.
sui client new-env --alias local --rpc http://127.0.0.1:9000 sui client switch --env local
-
Start a local explorer.
sui-explorer-local start
To stop Sui, press "Control + C". To stop the local explorer, sui-explorer-local stop
.
-
The following command will setup example wallets, publish Oracle contract, publish Bridge contract, and build a client to interact with the contracts.
cd ./cli python -m sui_demo setup --network regtest
-
Now you can use sui_demo.py to do pegin, transfer, burn, and pegout. For examples:
python -m sui_demo pegin --user alice --pegin-amount 32000000000 --network regtest python -m sui_demo transfer --sender alice --receiver bob --token-index 0 --network regtest python -m sui_demo burn --user bob --token-index 0 --network regtest python3 -m sui_demo pegout --user bob --token-index 0 --network regtest --update
-
After "pegout", you should be able to see that the user Bob has received 32 sui from a Sui explorer by search his Sui address.
You can always restart from the begining at any time.
To check out Ethereum bridge on local networks, click here README.
The code is released under the attached LICENSE. If you would like to use it for commercial purposes, please contact [email protected].