Skip to content

Commit

Permalink
feat: mock proof from pv (#318)
Browse files Browse the repository at this point in the history
* feat: mock proof from pv

* add

* add

* feat: compiles
  • Loading branch information
ratankaliani authored Jan 9, 2025
1 parent b5ec09a commit d234c4f
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 84 deletions.
69 changes: 35 additions & 34 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ op-alloy-rpc-types-engine = { version = "0.6.8", default-features = false }
op-alloy-network = { version = "0.6.8", default-features = false }

# sp1
sp1-lib = { version = "4.0.0-rc.8", features = ["verify"] }
sp1-sdk = { version = "4.0.0-rc.8" }
sp1-zkvm = { version = "4.0.0-rc.8", features = ["verify"] }
sp1-build = { version = "4.0.0-rc.8" }
sp1-lib = { version = "4.0.0-rc.9", features = ["verify"] }
sp1-sdk = { version = "4.0.0-rc.9" }
sp1-zkvm = { version = "4.0.0-rc.9", features = ["verify"] }
sp1-build = { version = "4.0.0-rc.9" }

[profile.release-client-lto]
inherits = "release"
Expand Down
2 changes: 1 addition & 1 deletion configs/480/rollup.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
"batch_inbox_address": "0xff00000000000000000000000000000000000480",
"deposit_contract_address": "0xd5ec14a83b7d95be1e2ac12523e2dee12cbeea6c",
"l1_system_config_address": "0x6ab0777fd0e609ce58f939a7f70fe41f5aa6300a",
"protocol_versions_address": "0x0000000000000000000000000000000000000000"
"protocol_versions_address": "0x8062abc286f5e7d9428a0ccb9abd71e50d93b935"
}
24 changes: 12 additions & 12 deletions contracts/opsuccinctl2ooconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"challenger": "0xDEd0000E32f8F40414d3ab3a830f735a3553E18e",
"challenger": "0x788c45CafaB3ea427b9079889BE43D7d3cd7500C",
"finalizationPeriod": 3600,
"l2BlockTime": 10,
"owner": "0xDEd0000E32f8F40414d3ab3a830f735a3553E18e",
"proposer": "0xDEd0000E32f8F40414d3ab3a830f735a3553E18e",
"rollupConfigHash": "0x71241d0f92749d7365aaaf6a015de550816632a4e4e84e273f865f582e8190aa",
"startingBlockNumber": 349460,
"startingOutputRoot": "0x976350d8d672a46ffa14faefac53827df68cebcb86305b5042b9f9cc963107d1",
"startingTimestamp": 1735613204,
"submissionInterval": 1200,
"verifier": "0x397A5f7f3dBd538f23DE225B51f532c34448dA9B",
"aggregationVkey": "0x00d4e72bc998d0528b0722a53bedd9c6f0143c9157af194ad4bb2502e37a496f",
"rangeVkeyCommitment": "0x33e3678015df481724af3aac49d000923caeec277027610b1490f857769f9459"
"l2BlockTime": 2,
"owner": "0x788c45CafaB3ea427b9079889BE43D7d3cd7500C",
"proposer": "0x788c45CafaB3ea427b9079889BE43D7d3cd7500C",
"rollupConfigHash": "0x78e77d3560e6cfb84e49b62ce66ccce1a8c347b1f3e7c6353a590dcb373a6a4e",
"startingBlockNumber": 8430302,
"startingOutputRoot": "0x38a9f55b8cc21415c16e34a7e6e89e2503a3254f4ff0f4cd368aad5a43320fb7",
"startingTimestamp": 1736196243,
"submissionInterval": 86400,
"verifier": "0xda10a9199d56ad03ee1c832758fb02341db66a32",
"aggregationVkey": "0x0015c534b62fd88189fc2f517db5fe3b15d2e8795372d68d09d1239ca3c6066e",
"rangeVkeyCommitment": "0x46f107804e8eb6b6173bd94e15049b1006b9862b020463f76cfde6284b24f91a"
}
10 changes: 4 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,17 @@ deploy-mock-verifier env_file=".env":
echo "PRIVATE_KEY not set in {{env_file}}"
exit 1
fi
VERIFY_FLAGS=""
if [ ! -z "$ETHERSCAN_API_KEY" ]; then
VERIFY_FLAGS="--verify --verifier etherscan --etherscan-api-key $ETHERSCAN_API_KEY"
fi
cd contracts

forge script script/DeployMockVerifier.s.sol:DeployMockVerifier \
--rpc-url $L1_RPC \
--private-key $PRIVATE_KEY \
--broadcast \
$VERIFY_FLAGS
--verify \
--verifier etherscan \
--etherscan-api-key $ETHERSCAN_API_KEY

# Deploy the OPSuccinct L2 Output Oracle
deploy-oracle env_file=".env":
#!/usr/bin/env bash
Expand Down
2 changes: 1 addition & 1 deletion proposer/succinct/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dotenv.workspace = true
op-succinct-client-utils.workspace = true
serde = { workspace = true }
serde_json.workspace = true

csv.workspace = true
# server
axum = "0.7.4"
bincode.workspace = true
Expand Down
54 changes: 46 additions & 8 deletions proposer/succinct/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use op_succinct_client_utils::{
use op_succinct_host_utils::{
fetcher::{CacheMode, OPSuccinctDataFetcher, RunContext},
get_agg_proof_stdin, get_proof_stdin,
stats::ExecutionStats,
witnessgen::{WitnessGenExecutor, WITNESSGEN_TIMEOUT},
L2OutputOracle, ProgramType,
};
Expand All @@ -27,9 +28,14 @@ use sp1_sdk::{
proto::network::{ExecutionStatus, FulfillmentStatus},
FulfillmentStrategy,
},
utils, HashableKey, Prover, ProverClient, SP1Proof, SP1ProofWithPublicValues,
utils, HashableKey, Prover, ProverClient, SP1Proof, SP1ProofMode, SP1ProofWithPublicValues,
SP1_CIRCUIT_VERSION,
};
use std::{
env, fs,
str::FromStr,
time::{Duration, Instant},
};
use std::{env, str::FromStr, time::Duration};
use tower_http::limit::RequestBodyLimitLayer;

pub const RANGE_ELF: &[u8] = include_bytes!("../../../elf/range-elf");
Expand All @@ -45,7 +51,7 @@ async fn main() -> Result<()> {

dotenv::dotenv().ok();

let prover = ProverClient::builder().mock().build();
let prover = ProverClient::builder().cpu().build();
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());
Expand Down Expand Up @@ -348,6 +354,7 @@ async fn request_mock_span_proof(
// Start the server and native client with a timeout.
// Note: Ideally, the server should call out to a separate process that executes the native
// host, and return an ID that the client can poll on to check if the proof was submitted.
let start_time = Instant::now();
let mut witnessgen_executor = WitnessGenExecutor::new(WITNESSGEN_TIMEOUT, RunContext::Docker);
if let Err(e) = witnessgen_executor.spawn_witnessgen(&host_cli).await {
error!("Failed to spawn witness generator: {}", e);
Expand All @@ -361,6 +368,7 @@ async fn request_mock_span_proof(
e
)));
}
let witness_generation_time_sec = start_time.elapsed();

let sp1_stdin = match get_proof_stdin(&host_cli) {
Ok(stdin) => stdin,
Expand All @@ -370,11 +378,41 @@ async fn request_mock_span_proof(
}
};

let prover = ProverClient::builder().mock().build();
let proof = prover
.prove(&state.range_pk, &sp1_stdin)
.compressed()
.run()?;
let start_time = Instant::now();
let prover = ProverClient::builder().cpu().build();
let (pv, report) = prover.execute(RANGE_ELF, &sp1_stdin).run().unwrap();
let execution_duration = start_time.elapsed();

let block_data = fetcher
.get_l2_block_data_range(payload.start, payload.end)
.await?;

let stats = ExecutionStats::new(
&block_data,
&report,
witness_generation_time_sec.as_secs(),
execution_duration.as_secs(),
);

let l2_chain_id = fetcher.get_l2_chain_id().await?;
// Save the report to disk.
let report_dir = format!("execution-reports/{}", l2_chain_id);
if !std::path::Path::new(&report_dir).exists() {
fs::create_dir_all(&report_dir)?;
}

let report_path = format!("{}/{}-{}.json", report_dir, payload.start, payload.end);
// Write to CSV.
let mut csv_writer = csv::Writer::from_path(report_path)?;
csv_writer.serialize(&stats)?;
csv_writer.flush()?;

let proof = SP1ProofWithPublicValues::create_mock_proof(
&state.range_pk,
pv.clone(),
SP1ProofMode::Compressed,
SP1_CIRCUIT_VERSION,
);

let proof_bytes = bincode::serialize(&proof).unwrap();

Expand Down
Loading

0 comments on commit d234c4f

Please sign in to comment.