End-to-end in detail

Detailed steps for the end-to-end process of verifying Celestia data inside a Mina smart contract

You can review the scripts/blobstream_example/e2e_blobstream_inclusion.sh script to understand the end-to-end process in the example, but here it is broken down:

Preliminaries

Start by building the project.

cd contracts
npm install
npm run build
cd ..

Next, navigate to the scripts directory and create a new directory inside it where the end-to-end process will run.

cd scripts
mkdir run-e2e

Set environment variables for WORK_DIR as a relative path within the scripts directory to the directory for the end-to-end process, and set RUN_DIR as the fully-qualified path to the same directory. SetBLOB_DIR as the fully-qualified path to the blob-stream-inclusion repo directory where your SP1 proofs were generated.

export WORK_DIR=run-e2e
export RUN_DIR=$(pwd)/$WORK_DIR
export BLOB_DIR=<FULLY-QUALIFIED-PATH-TO-DIRECTORY>/blob-stream-inclusion

Convert the SP1 blobstream proof

To prove the verification of the SP1 blobstream proof in o1js, we start by setting up the environment with the verification keys and public inputs of the SP1 blobstream proof. This can be done with the contracts/src/blobstream/sp1_to_env.ts script.

node "../contracts/build/src/blobstream/sp1_to_env.js" \
    $BLOB_DIR/blobstream/script/proof-with-pis.json \
    $RUN_DIR \
    $WORK_DIR \
    blobstream

This script does the following to set environment variables inside the $RUN_DIR/env.blobstream file:

  • gets the public values from the SP1 proof, converts them to hex, and puts the result inHEX_PI

  • gets the program verifier key from the first public input in the SP1 proof and puts it in PROGRAM_VK

  • gets the hex-encoded SP1 proof, prepends it with 8 bytes of 0s and puts it in HEX_PROOF

  • setsWORK_DIR and CACHE_DIR to be used when we execute the proofs in the next step.

Now we're ready to run the PLONK proof:

./e2e_plonk.sh $RUN_DIR/env.blobstream

This can take ~15 minutes. The output should look something like this:

...
Compiling recursion vks...
(node:15995) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Recursion vks compiled successfully
Computing ZKPs 0-23...
valid zkp23?:  true
valid zkp6?:  true
valid zkp16?:  true
valid zkp12?:  true
valid zkp18?:  true
valid zkp8?:  true
valid zkp3?:  true
valid zkp13?:  true
valid zkp14?:  true
valid zkp0?:  true
valid zkp17?:  true
valid zkp21?:  true
valid zkp4?:  true
valid zkp20?:  true
valid zkp1?:  true
valid zkp15?:  true
valid zkp22?:  true
valid zkp9?:  true
valid zkp19?:  true
valid zkp10?:  true
valid zkp11?:  true
valid zkp2?:  true
valid zkp5?:  true
valid zkp7?:  true
Computed ZKPs 0-23...
Compressing layer 1...
layer: 1 node: 6 written
layer: 1 node: 10 written
layer: 1 node: 4 written
layer: 1 node: 1 written
layer: 1 node: 8 written
layer: 1 node: 5 written
layer: 1 node: 3 written
layer: 1 node: 9 written
layer: 1 node: 2 written
layer: 1 node: 0 written
layer: 1 node: 11 written
layer: 1 node: 14 written
layer: 1 node: 7 written
layer: 1 node: 13 written
layer: 1 node: 12 written
layer: 1 node: 15 written
Compressed layer 1...
Compressing layer 2...
layer: 2 node: 5 written
layer: 2 node: 4 written
layer: 2 node: 0 written
layer: 2 node: 1 written
layer: 2 node: 2 written
layer: 2 node: 6 written
layer: 2 node: 3 written
layer: 2 node: 7 written
Compressed layer 2...
Compressing layer 3...
layer: 3 node: 0 written
layer: 3 node: 3 written
layer: 3 node: 2 written
layer: 3 node: 1 written
Compressed layer 3...
Compressing layer 4...
layer: 4 node: 0 written
layer: 4 node: 1 written
Compressed layer 4...
Compressing layer 5...
layer: 5 node: 0 written
Compressed layer 5...
Done!

All of the execution data is saved in a new directory in $RUN_DIR/blobstream. The final proof is found at $RUN_DIR/blobstream/e2e_plonk/plonk/recursion/proofs/layer5/p0.json.

Convert the SP1 blob inclusion proof

For converting the blob inclusion proof, we'll follow the same environment setup process as above with slightly modified parameters.

node "../contracts/build/src/blobstream/sp1_to_env.js" \
    $BLOB_DIR/blob_inclusion/script/proof-with-pis.json \
    $RUN_DIR \
    $WORK_DIR \
    blobInclusion

With the env.blobInclusion file created, we can run the Plonk proof to convert our SP1 blob inclusion proof:

./e2e_plonk.sh  $RUN_DIR/env.blobInclusion

This can take ~15 minutes. The output should look the same as the blobstream proof conversion from the previous section.

All of the execution data is saved in a new directory in $RUN_DIR/blobInclusion. The final proof is found at $RUN_DIR/blobInclusion/e2e_plonk/plonk/recursion/proofs/layer5/p0.json.

Run the rollup contract example

Set up the environment

In order to prove the verification of the o1js proofs that verified the SP1 proofs in the previous step, the verifier keys for both SP1 programs are needed. The verifier key for the final compressed proof from the o1js proof & compression process above is also required. It's obtained from the public outputs of the layer 5 proof. (See the explanation of this flow for more detail about the proof compression.)

The verification scripts contracts/src/blobstream/verify_blobstream.ts and contracts/src/blobstream/verify_blob_inclusion.ts get these values from environment variables which can be set as follows:

source $RUN_DIR/env.blobstream
export BLOBSTREAM_ENABLED=true
export BLOBSTREAM_WORK_DIR=$WORK_DIR
export BLOBSTREAM_PROGRAM_VK=$PROGRAM_VK

source $RUN_DIR/env.blobInclusion
export BLOB_INCLUSION_ENABLED=true
export BLOB_INCLUSION_WORK_DIR=$WORK_DIR
export BLOB_INCLUSION_PROGRAM_VK=$PROGRAM_VK

Prove the verification of the blobstream proof

source $RUN_DIR/env.blobstream
node "../contracts/build/src/blobstream/prove_zkps.js" \
    blobstream \
    $WORK_DIR/plonk/recursion/proofs/layer5/p0.json \
    $BLOB_DIR/blobstream/script/proof-with-pis.json \
    $RUN_DIR/blobstreamProof.json \
    $CACHE_DIR

This should only take about a minute. Expected output:

valid blobstream proof?:  true

Prove the verification of the blob inclusion proof

source $RUN_DIR/env.blobInclusion
node "../contracts/build/src/blobstream/prove_zkps.js" \
    blob_inclusion \
    $WORK_DIR/plonk/recursion/proofs/layer5/p0.json \
    $BLOB_DIR/blob_inclusion/script/proof-with-pis.json \
    $RUN_DIR/blobInclusionProof.json \
    $CACHE_DIR

This should only take about a minute. Expected output:

1d0000000000000000000000000000000000000000000000000000000000000019352000002000000000000000736f6d65206461746120746f2073746f7265206f6e20626c6f636b636861696ec6aa975f310a75219253598fb5baba4b42eba4d5cf7f9d09abffda73f50c38df
valid blob inclusion proof?:  true

Prove the correct execution of a batch

node "../contracts/build/src/blobstream/prove_zkps.js" \
    batcher \
    $RUN_DIR/blobInclusionProof.json \
    $BLOB_DIR/blob_inclusion/script/proof-with-pis.json \
    $RUN_DIR/batcherProof.json \
    $CACHE_DIR

Expected output:

valid batcher proof4?:  true

Run the example rollup contract

node "../contracts/build/src/blobstream/prove_zkps.js" \
    rollup_contract \
    ${RUN_DIR}/blobstreamProof.json \
    ${RUN_DIR}/batcherProof.json \
    ${CACHE_DIR}

This should only take ~1 minute. Expected output:

Deploying Blobstream Processor...
Deploying Rollup...
Setting Blobstream address...
updating blobstream state
Successfully updated the rollup state while showing blob inclusion!

Last updated