SP1 Blobstream

Overview

SP1 Blobstream is an implementation of Blobstream X in Rust for the SP1 zkVM.

  • /program: The SP1 Blobstream program.
  • /primitives: Libraries for types and helper functions used in the program.
  • /script: Scripts for getting the contract's genesis parameters and deploying the operator to update the light client.
  • /contracts: The contract's source code and deployment scripts. Backwards-compatible with the original BlobstreamX implementation in case we need to upgrade.

Components

An SP1 Blobstream implementation has a few key components:

  • An SP1Blobstream contract. Contains the logic for verifying SP1 Blobstream proofs, storing the latest data from the Celestia chain, including the headers and data commitments. Matches the interface of the existing BlobstreamX contract so it can be upgraded in-place.
  • An SP1Verifier contract. Verifies arbitrary SP1 programs. Most chains will have canonical deployments upon SP1's mainnet launch. Until then, users can deploy their own SP1Verifier contracts to verify SP1 programs on their chain. The SP1 Blobstream implementation will use the SP1Verifier contract to verify the proofs of the SP1 Blobstream programs.
  • The SP1 Blobstream program. An SP1 program that verifies the transition between two Tendermint headers and computes the data commitment of the intermediate blocks.
  • The operator. A Rust script that fetches the latest data from a deployed SP1Blobstream contract and a Tendermint chain, determines the block to request, requests for/generates a proof, and relays the proof to the SP1Blobstream contract.

Deploying SP1 Blobstream

  1. To deploy an SP1 Blobstream contract for a Tendermint chain do the following.

    Get the genesis parameters for the SP1Blobstream contract.

    cd script
    
    # Example with Celestia Mocha-4 Testnet.
    TENDERMINT_RPC_URL=https://rpc.lunaroasis.net/ cargo run --bin genesis --release
    
  2. Deploy the SP1Blobstream contract with genesis parameters: GENESIS_HEIGHT, GENESIS_HEADER, and SP1_BLOBSTREAM_PROGRAM_VKEY.

    cd ../contracts
    
    forge install
    
    GENESIS_HEIGHT=<GENESIS_HEIGHT> GENESIS_HEADER=<GENESIS_HEADER> SP1_BLOBSTREAM_PROGRAM_VKEY=<SP1_BLOBSTREAM_PROGRAM_VKEY> forge script script/Deploy.s.sol --rpc-url <RPC_URL> --private-key <PRIVATE_KEY> --etherscan-api-key <ETHERSCAN_API_KEY> --broadcast --verify
    

    If you see the following error, add --legacy to the command.

    Error: Failed to get EIP-1559 fees    
    
  3. Your deployed contract address will be printed to the terminal.

    == Return ==
    0: address <SP1_BLOBSTREAM_ADDRESS>
    

    This will be used when you run the operator in step 5.

  4. Export your SP1 Prover Network configuration

    # Export the PRIVATE_KEY you will use to relay proofs.
    export PRIVATE_KEY=<PRIVATE_KEY>
    
    # Optional
    # If you're using the Succinct network, set SP1_PROVER to "network". Otherwise, set it to "local" or "mock".
    export SP1_PROVER={network|local|mock}
    # Only required if SP1_PROVER is set "network".
    export SP1_PRIVATE_KEY=<SP1_PRIVATE_KEY>
    
  5. Run the SP1 Blobstream operator to update the LC continuously.

    cd ../script
    
    TENDERMINT_RPC_URL=https://rpc.celestia-mocha.com/ CHAIN_ID=11155111 RPC_URL=https://ethereum-sepolia.publicnode.com/
    CONTRACT_ADDRESS=<SP1_BLOBSTREAM_ADDRESS> cargo run --bin operator --release
    

Reproducible Builds

Overview

When deploying SP1 Blobstream in production, it's important to ensure that the program used when generating proofs is reproducible.

Prerequisites

You first need to install the cargo prove toolchain.

Ensure that you have the latest version of the toolchain by running:

sp1up

Confirm that you have the toolchain installed by running:

cargo prove --version

Verify the SP1 Blobstream binary

To build the SP1 Blobstream binary, first ensure that Docker is running.

docker ps

Then build the binaries:

cd program

# Builds the SP1 Blobstream binary using the corresponding Docker tag, output directory and ELF name.
cargo prove build --docker --tag v3.0.0 --output-directory ../script --elf-name blobstream-elf

Now, verify the binaries by confirming the output of vkey matches the vkeys on the contract. The vkey program outputs the verification key based on the ELF in /elf.

cargo run --bin vkey --release

Known Limitations

Warning: The implementation of SP1 Blobstream assumes that the number of validators is less than 256. This limitation is due to the use of a 256-bit bitmap to represent whether a validator has signed off on a header. If the number of validators exceeds 256, the validatorBitmap functionality may not work as intended, potentially leading to an incomplete validator equivocation.

On Celestia, the number of validators is currently 100, and there are no plans to increase this number significantly. If it was to be increased, the signature aggregation logic in the consensus protocol would likely change as well, which would also necessitate a change in the SP1 Blobstream implementation.