Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Jan 16, 2025
1 parent c7fa220 commit ccda944
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
30 changes: 21 additions & 9 deletions proposer/succinct/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use op_succinct_host_utils::{
L2OutputOracle, ProgramType,
};
use op_succinct_proposer::{
AggProofRequest, ContractConfig, ProofResponse, ProofStatus, SpanProofRequest,
AggProofRequest, ProofResponse, ProofStatus, SpanProofRequest, SuccinctProposerConfig,
ValidateConfigRequest, ValidateConfigResponse,
};
use sp1_sdk::{
Expand Down Expand Up @@ -64,15 +64,27 @@ async fn main() -> Result<()> {
// [`RollupConfig`] is released from `op-alloy`.
let rollup_config_hash = hash_rollup_config(fetcher.rollup_config.as_ref().unwrap());

// Set the proof strategies based on environment variables. Default to reserved to keep existing behavior.
let range_proof_strategy = match env::var("RANGE_PROOF_STRATEGY") {
Ok(strategy) if strategy.to_lowercase() == "hosted" => FulfillmentStrategy::Hosted,
_ => FulfillmentStrategy::Reserved,
};
let agg_proof_strategy = match env::var("AGG_PROOF_STRATEGY") {
Ok(strategy) if strategy.to_lowercase() == "hosted" => FulfillmentStrategy::Hosted,
_ => FulfillmentStrategy::Reserved,
};

// Initialize global hashes.
let global_hashes = ContractConfig {
let global_hashes = SuccinctProposerConfig {
agg_vkey_hash,
range_vkey_commitment,
rollup_config_hash,
range_vk,
range_pk,
agg_vk,
agg_pk,
range_proof_strategy,
agg_proof_strategy,
};

let app = Router::new()
Expand All @@ -98,7 +110,7 @@ async fn main() -> Result<()> {

/// Validate the configuration of the L2 Output Oracle.
async fn validate_config(
State(state): State<ContractConfig>,
State(state): State<SuccinctProposerConfig>,
Json(payload): Json<ValidateConfigRequest>,
) -> Result<(StatusCode, Json<ValidateConfigResponse>), AppError> {
info!("Received validate config request: {:?}", payload);
Expand Down Expand Up @@ -127,7 +139,7 @@ async fn validate_config(

/// Request a proof for a span of blocks.
async fn request_span_proof(
State(state): State<ContractConfig>,
State(state): State<SuccinctProposerConfig>,
Json(payload): Json<SpanProofRequest>,
) -> Result<(StatusCode, Json<ProofResponse>), AppError> {
info!("Received span proof request: {:?}", payload);
Expand Down Expand Up @@ -193,7 +205,7 @@ async fn request_span_proof(
let proof_id = client
.prove(&state.range_pk, &sp1_stdin)
.compressed()
.strategy(FulfillmentStrategy::Reserved)
.strategy(state.range_proof_strategy)
.skip_simulation(true)
.cycle_limit(1_000_000_000_000)
.request_async()
Expand All @@ -213,7 +225,7 @@ async fn request_span_proof(

/// Request an aggregation proof for a set of subproofs.
async fn request_agg_proof(
State(state): State<ContractConfig>,
State(state): State<SuccinctProposerConfig>,
Json(payload): Json<AggProofRequest>,
) -> Result<(StatusCode, Json<ProofResponse>), AppError> {
info!("Received agg proof request");
Expand Down Expand Up @@ -299,10 +311,10 @@ async fn request_agg_proof(
}
};

// Use hosted proving for Groth16 as the proof is lightweight.
let proof_id = match prover
.prove(&state.agg_pk, &stdin)
.groth16()
.strategy(state.agg_proof_strategy)
.request_async()
.await
{
Expand All @@ -323,7 +335,7 @@ async fn request_agg_proof(

/// Request a mock proof for a span of blocks.
async fn request_mock_span_proof(
State(state): State<ContractConfig>,
State(state): State<SuccinctProposerConfig>,
Json(payload): Json<SpanProofRequest>,
) -> Result<(StatusCode, Json<ProofStatus>), AppError> {
info!("Received mock span proof request: {:?}", payload);
Expand Down Expand Up @@ -428,7 +440,7 @@ async fn request_mock_span_proof(

/// Request mock aggregation proof.
async fn request_mock_agg_proof(
State(state): State<ContractConfig>,
State(state): State<SuccinctProposerConfig>,
Json(payload): Json<AggProofRequest>,
) -> Result<(StatusCode, Json<ProofStatus>), AppError> {
info!("Received mock agg proof request!");
Expand Down
6 changes: 4 additions & 2 deletions proposer/succinct/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloy_primitives::B256;
use base64::{engine::general_purpose, Engine as _};
use serde::{Deserialize, Deserializer, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use sp1_sdk::{SP1ProvingKey, SP1VerifyingKey};
use sp1_sdk::{network::FulfillmentStrategy, SP1ProvingKey, SP1VerifyingKey};

#[derive(Serialize, Deserialize, Debug)]
pub struct ValidateConfigRequest {
Expand Down Expand Up @@ -75,14 +75,16 @@ pub struct ProofStatus {
/// Configuration of the L2 Output Oracle contract. Created once at server start-up, monitors if there are any changes
/// to the contract's configuration.
#[derive(Clone)]
pub struct ContractConfig {
pub struct SuccinctProposerConfig {
pub range_vk: SP1VerifyingKey,
pub range_pk: SP1ProvingKey,
pub agg_pk: SP1ProvingKey,
pub agg_vk: SP1VerifyingKey,
pub agg_vkey_hash: B256,
pub range_vkey_commitment: B256,
pub rollup_config_hash: B256,
pub range_proof_strategy: FulfillmentStrategy,
pub agg_proof_strategy: FulfillmentStrategy,
}

/// Deserialize a vector of base64 strings into a vector of vectors of bytes. Go serializes
Expand Down

0 comments on commit ccda944

Please sign in to comment.