Skip to content

Bitcoin data-availability adapter written in Rust, allowing Madara to interact with Bitcoin as a data-availability layer. πŸ¦€πŸ§™β€β™‚οΈ

License

Notifications You must be signed in to change notification settings

KasarLabs/bitcoin-da

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ§™β€β™‚οΈ Bitcoin-da-rs

This crate allows Bitcoin to function as a data availability layer, supporting both write and read operations. It's been developed with Rust sequencers in mind, particularly for integration with Madara. It's modeled after rollkit's bitcoin-da.

⚠️ Disclaimer: The code is currently in its experimental phase and is not recommended for production use.

Prerequisites

Before you can proceed with using or testing this crate, there are a few setup steps you need to follow:

  • Installation: Ensure bitcoind & bitcoin-cli are installed.

  • Setting up a Bitcoin Daemon:

    • Start a bitcoin daemon with:

      bitcoind -conf=path_to/bitcoin.conf
    • If you're setting up for the first time and don't have a wallet yet:

      bitcoin-cli createwallet test
    • Mine some blocks (especially useful for regtest):

      bitcoin-cli -regtest -generate 150

Note: These steps are for both manual and automatic testing. For both cases you will still need to start bitcoind separately. Additionally, automated tests will only handle some bitcoin-cli operations such as loadwallet and setting the test label for the wallet in use.

Building the Library

git clone git@github.com:KasarLabs/bitcoin-da.git
cd da
cargo build

For more detailed instructions on building Rust projects, refer to the cargo documentation.

Example Usage

Here's a simple example to demonstrate how to use the library:

fn test_write() {
        let embedded_data = b"Hello, world!";
        let relayer = Relayer::new(&Config::new(
            "localhost:8332".to_owned(),
            "rpcuser".to_owned(),
            "rpcpass".to_owned(),
        ))
        .unwrap();
        // get network, should be regtest
        let blockchain_info = relayer.client.get_blockchain_info().unwrap();
        let network_name = &blockchain_info.chain;
        let network = Network::from_core_arg(network_name)
            .map_err(|_| BitcoinError::InvalidNetwork)
            .unwrap();
        match relayer.write(&embedded_data) {
            Ok(txid) => {
                println!("Txid: {}", txid);
                println!("Successful write");
            }
            Err(e) => panic!("Write failed with error: {:?}", e),
        }
    }

Automated Testing with the Provided Script

This repo comes with an automation script (run_tests.sh) which simplifies the testing process by handling node operations and test configurations. The script assumes a bitcoin node is already running.

Preparations:

  • Grant the script execute permissions:
    chmod +x run_tests.sh
  1. Setup: Ensure a Bitcoin node is running on the desired network (regtest or signet), and modify the RPC URL in your configuration as necessary. Depending on the test, you might also need to comment/uncomment the required network in the test function.

  2. Command Usage:

./run_tests.sh -l [log level] -b [backtrace] -t [test name] -L --signet|--regtest
  • -l or --log-level: Specify the log level. Valid options are info, debug, or none.
  • -b or --backtrace: Enable (1) or Disable (0) backtrace.
  • -t or --test-name: Specify a test name (optional).
  • -L or --long-tests: Include tests that take a long time to complete in signet due to the time it takes to complete a block. These tests run fast in regtest.
  • --signet: Use the signet network.
  • --regtest: Use the regtest network.

Note: there should be no quotations on any of the argument flags when used.

Examples:

Run all tests with debug logs and backtrace:

./run_tests.sh -l debug -b 1

Run the test_example with info logs:

./run_tests.sh -l info -t test_example

Manual Tests

If you prefer manual testing:

  1. Setup: Ensure a Bitcoin node is running on the desired network (regtest or signet), and modify the RPC URL in your configuration as necessary. Depending on the test, you might also need to comment/uncomment the required network in the test function.

  2. Running Tests:

  • regtest:

    cargo test --features regtest
  • Signet:

    cargo test --features signet
  • With Logs:

    RUST_LOG=debug cargo test
  • Logs + Backtrace:

    RUST_LOG=debug RUST_BACKTRACE=1 cargo test --features regtest
  • Logs + Backtrace + long tests: RUST_LOG=debug RUST_BACKTRACE=1 cargo test --features regtest,long_tests

License

This project is under the Apache 2.0 license. Detailed information can be found in LICENSE.

Contributors ✨

Collaborative work by Kasar and Taproot Wizards πŸ§™β€β™‚οΈ.

Antoine
Antoine

πŸ’»
Antiyro
Antiyro

πŸ’»
Betacod
Betacod

πŸ’»
Sparqet
Sparqet

πŸ’»
Axel Izsak
Axel Izsak

πŸ’»
Zarboq
Zarboq

πŸ’»

About

Bitcoin data-availability adapter written in Rust, allowing Madara to interact with Bitcoin as a data-availability layer. πŸ¦€πŸ§™β€β™‚οΈ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published