Skip to content

Commit

Permalink
feat: dummy range program (#283)
Browse files Browse the repository at this point in the history
* feat: add dummy range program

* add

* add

* add

* Add

* fix

* fix

---------

Co-authored-by: Ubuntu <[email protected]>
  • Loading branch information
ratankaliani and Ubuntu authored Dec 16, 2024
1 parent a931117 commit ea89646
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 424 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/compile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Compile the fault proof program
run: cargo build --profile release-client-lto
working-directory: programs/fault-proof
- name: Compile the range program
run: cargo build --profile release-client-lto
working-directory: programs/range
Expand All @@ -37,9 +34,6 @@ jobs:
~/.sp1/bin/sp1up
~/.sp1/bin/cargo-prove prove --version
source ~/.bashrc
- name: Compile the fault proof program
run: ~/.sp1/bin/cargo-prove prove build --binary fault-proof
working-directory: programs/fault-proof
- name: Compile the range program
run: ~/.sp1/bin/cargo-prove prove build --binary range
working-directory: programs/range
Expand Down
27 changes: 8 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added elf/dummy-range-elf
Binary file not shown.
51 changes: 0 additions & 51 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,57 +33,6 @@ cost-estimator start end:
#!/usr/bin/env bash
cargo run --bin cost-estimator --release -- --start {{start}} --end {{end}}
# Runs the client program in native execution mode. Modified version of Kona Native Client execution:
# https://github.com/ethereum-optimism/kona/blob/ae71b9df103c941c06b0dc5400223c4f13fe5717/bin/client/justfile#L65-L108
run-client-native l2_block_num l1_rpc='${L1_RPC}' l1_beacon_rpc='${L1_BEACON_RPC}' l2_rpc='${L2_RPC}' verbosity="-vvvv":
#!/usr/bin/env bash
L1_NODE_ADDRESS="{{l1_rpc}}"
L1_BEACON_ADDRESS="{{l1_beacon_rpc}}"
L2_NODE_ADDRESS="{{l2_rpc}}"
echo "L1 Node Address: $L1_NODE_ADDRESS"
echo "L1 Beacon Address: $L1_BEACON_ADDRESS"
echo "L2 Node Address: $L2_NODE_ADDRESS"
HOST_BIN_PATH="./kona-host"
CLIENT_BIN_PATH="$(pwd)/target/release-client-lto/fault-proof"
L2_BLOCK_NUMBER="{{l2_block_num}}"
L2_BLOCK_SAFE_HEAD=$((L2_BLOCK_NUMBER - 1))
L2_OUTPUT_STATE_ROOT=$(cast block --rpc-url $L2_NODE_ADDRESS --field stateRoot $L2_BLOCK_SAFE_HEAD)
L2_HEAD=$(cast block --rpc-url $L2_NODE_ADDRESS --field hash $L2_BLOCK_SAFE_HEAD)
L2_OUTPUT_STORAGE_HASH=$(cast proof --rpc-url $L2_NODE_ADDRESS --block $L2_BLOCK_SAFE_HEAD 0x4200000000000000000000000000000000000016 | jq -r '.storageHash')
L2_OUTPUT_ENCODED=$(cast abi-encode "x(uint256,bytes32,bytes32,bytes32)" 0 $L2_OUTPUT_STATE_ROOT $L2_OUTPUT_STORAGE_HASH $L2_HEAD)
L2_OUTPUT_ROOT=$(cast keccak $L2_OUTPUT_ENCODED)
echo "L2 Safe Head: $L2_BLOCK_SAFE_HEAD"
echo "Safe Head Output Root: $L2_OUTPUT_ROOT"
L2_CLAIM_STATE_ROOT=$(cast block --rpc-url $L2_NODE_ADDRESS --field stateRoot $L2_BLOCK_NUMBER)
L2_CLAIM_HASH=$(cast block --rpc-url $L2_NODE_ADDRESS --field hash $L2_BLOCK_NUMBER)
L2_CLAIM_STORAGE_HASH=$(cast proof --rpc-url $L2_NODE_ADDRESS --block $L2_BLOCK_NUMBER 0x4200000000000000000000000000000000000016 | jq -r '.storageHash')
L2_CLAIM_ENCODED=$(cast abi-encode "x(uint256,bytes32,bytes32,bytes32)" 0 $L2_CLAIM_STATE_ROOT $L2_CLAIM_STORAGE_HASH $L2_CLAIM_HASH)
L2_CLAIM=$(cast keccak $L2_CLAIM_ENCODED)
echo "L2 Block Number: $L2_BLOCK_NUMBER"
echo "L2 Claim Root: $L2_CLAIM"
L2_BLOCK_TIMESTAMP=$(cast block --rpc-url $L2_NODE_ADDRESS $L2_BLOCK_NUMBER -j | jq -r .timestamp)
L1_HEAD=$(cast block --rpc-url $L1_NODE_ADDRESS $(cast find-block --rpc-url $L1_NODE_ADDRESS $(($(cast 2d $L2_BLOCK_TIMESTAMP) + 300))) -j | jq -r .hash)
echo "L1 Head: $L1_HEAD"
L2_CHAIN_ID=10
DATA_DIRECTORY="./data/$L2_BLOCK_NUMBER"
echo "Saving Data to $DATA_DIRECTORY"
echo "Building client program..."
cargo build --bin fault-proof --profile release-client-lto
echo "Running host program with native client program..."
cargo run --bin op-succinct-witnessgen --release -- \
--l1-head $L1_HEAD \
--l2-head $L2_HEAD \
--l2-claim $L2_CLAIM \
--l2-output-root $L2_OUTPUT_ROOT \
--l2-block-number $L2_BLOCK_NUMBER \
--l2-chain-id $L2_CHAIN_ID \
--l1-node-address $L1_NODE_ADDRESS \
--l1-beacon-address $L1_BEACON_ADDRESS \
--l2-node-address $L2_NODE_ADDRESS \
--exec $CLIENT_BIN_PATH \
--data-dir $DATA_DIRECTORY \
{{verbosity}}
# Output the data required for the ZKVM execution.
echo "$L1_HEAD $L2_OUTPUT_ROOT $L2_CLAIM $L2_BLOCK_NUMBER $L2_CHAIN_ID"

Expand Down
15 changes: 15 additions & 0 deletions programs/dummy-range/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "dummy-range"
version = "0.1.0"
license.workspace = true
edition.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
# sp1
sp1-zkvm.workspace = true

# op-succinct
op-succinct-client-utils.workspace = true
19 changes: 19 additions & 0 deletions programs/dummy-range/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! A dummy replica of the `range` program.
//!
//! SAFETY: Does not perform any verification of the rollup state transition.
#![no_main]
sp1_zkvm::entrypoint!(main);

use op_succinct_client_utils::boot::BootInfoStruct;
use op_succinct_client_utils::BootInfoWithBytesConfig;

pub fn main() {
let boot_info_with_bytes_config = sp1_zkvm::io::read::<BootInfoWithBytesConfig>();

// BootInfoStruct is identical to BootInfoWithBytesConfig, except it replaces
// the rollup_config_bytes with a hash of those bytes (rollupConfigHash). Securely
// hashes the rollup config bytes.
let boot_info_struct = BootInfoStruct::from(boot_info_with_bytes_config.clone());
sp1_zkvm::io::commit::<BootInfoStruct>(&boot_info_struct);
}
38 changes: 0 additions & 38 deletions programs/fault-proof/Cargo.toml

This file was deleted.

149 changes: 0 additions & 149 deletions programs/fault-proof/src/main.rs

This file was deleted.

2 changes: 0 additions & 2 deletions proposer/succinct/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ RUN --mount=type=ssh \
--mount=type=cache,target=/build/target \
cargo build --bin server --release && \
cp target/release/server /build/server && \
cp target/release-client-lto/fault-proof /build/fault_proof && \
cp target/release-client-lto/range /build/range && \
cp target/native_host_runner/release/native_host_runner /build/native_host_runner

Expand Down Expand Up @@ -73,7 +72,6 @@ RUN curl -L https://sp1.succinct.xyz | bash && \

# Copy only the built binaries from builder
COPY --from=builder /build/server /usr/local/bin/server
COPY --from=builder /build/fault_proof /usr/local/bin/fault_proof
COPY --from=builder /build/range /usr/local/bin/range
COPY --from=builder /build/native_host_runner /usr/local/bin/native_host_runner

Expand Down
9 changes: 3 additions & 6 deletions proposer/succinct/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use sp1_sdk::{
use std::{env, str::FromStr, time::Duration};
use tower_http::limit::RequestBodyLimitLayer;

pub const MULTI_BLOCK_ELF: &[u8] = include_bytes!("../../../elf/range-elf");
pub const RANGE_ELF: &[u8] = include_bytes!("../../../elf/range-elf");
pub const AGG_ELF: &[u8] = include_bytes!("../../../elf/aggregation-elf");

#[tokio::main]
Expand All @@ -42,7 +42,7 @@ async fn main() -> Result<()> {
dotenv::dotenv().ok();

let prover = ProverClient::new();
let (range_pk, range_vk) = prover.setup(MULTI_BLOCK_ELF);
let (range_pk, range_vk) = prover.setup(RANGE_ELF);
let (agg_pk, agg_vk) = prover.setup(AGG_ELF);
let multi_block_vkey_u8 = u32_to_u8(range_vk.vk.hash_u32());
let range_vkey_commitment = B256::from(multi_block_vkey_u8);
Expand Down Expand Up @@ -205,10 +205,7 @@ async fn request_span_proof(

// Set simulation to false on range proofs as they're large.
env::set_var("SKIP_SIMULATION", "true");
let vk_hash = match prover
.register_program(&state.range_vk, MULTI_BLOCK_ELF)
.await
{
let vk_hash = match prover.register_program(&state.range_vk, RANGE_ELF).await {
Ok(vk_hash) => vk_hash,
Err(e) => {
error!("Failed to register program: {}", e);
Expand Down
Loading

0 comments on commit ea89646

Please sign in to comment.