Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: verifiable binaries #146

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
- [Configuration](./getting-started/configuration.md)
- [Cost Estimator CLI Tool](./cost-estimator.md)
- [L2 Node Setup](./node-setup.md)
- [Appendix](./advanced/intro.md)
54 changes: 54 additions & 0 deletions book/advanced/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Advanced

When deploying OP Succinct in production, it's important to ensure that the SP1 programs used when generating proofs are reproducible.

## Verify the OP Succinct binaries

### Introduction

There are two programs used in OP Succinct:
- `range`: Proves the correctness of an OP Stack derivation + STF for a range of blocks.
- `aggregation`: Aggregates multiple range proofs into a single proof. This is the proof that lands on-chain. The aggregation proof ensures that all `range` proofs in a given block range are linked and use the `rangeVkeyCommitment` from the `L2OutputOracleProxy` as the verification key.

### Prerequisites

To reproduce the OP Succinct program binaries, you first need to install the [cargo prove](https://docs.succinct.xyz/getting-started/install.html#option-1-prebuilt-binaries-recommended) toolchain.

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

```bash
sp1up
```

Confirm that you have the toolchain installed by running:

```bash
cargo prove --version
```

### Verify the SP1 binaries

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

```bash
docker ps
```

Then build the binaries:

```bash
cd programs/range
# Build the range-elf
cargo prove build --elf range-elf --docker

cd ../aggregation
# Build the aggregation-elf
cargo prove build --elf aggregation-elf --docker
```

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

```bash
cargo run --bin vkey --release
```
Binary file modified elf/range-elf
Binary file not shown.
22 changes: 7 additions & 15 deletions scripts/utils/bin/vkey.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use alloy::sol;
use alloy_primitives::{hex, keccak256, B256};
use alloy_primitives::B256;
use anyhow::Result;
use log::info;
use op_succinct_client_utils::types::u32_to_u8;
use sp1_sdk::{utils, HashableKey, ProverClient};

Expand Down Expand Up @@ -38,24 +37,17 @@ async fn main() -> Result<()> {

let prover = ProverClient::new();

let (_, vkey) = prover.setup(MULTI_BLOCK_ELF);

let program_hash = keccak256(MULTI_BLOCK_ELF);
info!("Program Hash [view on Explorer]:");
info!("0x{}", hex::encode(program_hash));

println!(
"Range ELF Verification Key U32 Hash: {:?}",
vkey.vk.hash_u32()
);
let (_, range_vk) = prover.setup(MULTI_BLOCK_ELF);

// Get the 32 byte commitment to the vkey from vkey.vk.hash_u32()
let multi_block_vkey_u8 = u32_to_u8(vkey.vk.hash_u32());
let multi_block_vkey_u8 = u32_to_u8(range_vk.vk.hash_u32());
let multi_block_vkey_b256 = B256::from(multi_block_vkey_u8);
println!("Range ELF Verification Key B256: {}", multi_block_vkey_b256);
println!(
"Range ELF Verification Key Commitment: {}",
multi_block_vkey_b256
);

let (_, agg_vk) = prover.setup(AGG_ELF);
info!("Aggregation ELF Verification Key: {}", agg_vk.bytes32());
println!("Aggregation ELF Verification Key: {}", agg_vk.bytes32());

Ok(())
Expand Down
Loading