Skip to content

Commit

Permalink
tidy up rpc; remove unused
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltea committed Dec 11, 2023
1 parent db95204 commit c22bccc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 66 deletions.
16 changes: 3 additions & 13 deletions prover/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ use lightclient_circuits::{
};
use preprocessor::{rotation_args_from_update, step_args_from_finality_update};
use snark_verifier_sdk::{evm::evm_verify, halo2::aggregation::AggregationCircuit, Snark};
use std::io::Write;
use std::path::{Path, PathBuf};
use std::sync::Arc;

pub type JsonRpcServerState = Arc<JsonRpcServer<JsonRpcMapRouter>>;

use crate::rpc_api::{
AggregatedEvmProofResult, EvmProofResult, GenProofRotationWithWitnessParams,
GenProofStepWithWitnessParams, EVM_PROOF_ROTATION_CIRCUIT_WITH_WITNESS,
EVM_PROOF_STEP_CIRCUIT_WITH_WITNESS,
GenProofStepWithWitnessParams, RPC_EVM_PROOF_ROTATION_CIRCUIT, RPC_EVM_PROOF_STEP_CIRCUIT,
};

fn gen_committee_update_snark<S: eth_types::Spec>(
Expand Down Expand Up @@ -61,11 +59,9 @@ fn gen_evm_proof<C: AppCircuit>(
let (proof, instances) = C::gen_evm_proof_shplonk(&params, &pk, &config_path, None, &witness)
.map_err(|e| eyre::eyre!("Failed to generate calldata: {}", e))?;

println!("Proof size: {}", proof.len());
if let Some(deployment_code_path) = yul_path_if_verify {
let deployment_code =
C::gen_evm_verifier_shplonk(&params, &pk, Some(deployment_code_path), &witness)?;
println!("Deployment code size: {}", deployment_code.len());
evm_verify(deployment_code, instances.clone(), proof.clone());
}
Ok((proof, instances))
Expand Down Expand Up @@ -158,12 +154,6 @@ pub(crate) async fn gen_evm_proof_rotation_circuit_with_witness_handler(
public_inputs,
};

// Write proof to file for debugging
std::fs::File::create("proof.json")
.unwrap()
.write_all(serde_json::to_string(&res).unwrap().as_bytes())
.unwrap();

Ok(res)
}

Expand Down Expand Up @@ -230,11 +220,11 @@ pub(crate) async fn gen_evm_proof_step_circuit_with_witness_handler(
pub(crate) fn jsonrpc_server() -> JsonRpcServer<JsonRpcMapRouter> {
JsonRpcServer::new()
.with_method(
EVM_PROOF_ROTATION_CIRCUIT_WITH_WITNESS,
RPC_EVM_PROOF_ROTATION_CIRCUIT,
gen_evm_proof_rotation_circuit_with_witness_handler,
)
.with_method(
EVM_PROOF_STEP_CIRCUIT_WITH_WITNESS,
RPC_EVM_PROOF_STEP_CIRCUIT,
gen_evm_proof_step_circuit_with_witness_handler,
)
.finish_unwrapped()
Expand Down
14 changes: 3 additions & 11 deletions prover/src/rpc_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use crate::args;
use primitive_types::U256;
use serde::{Deserialize, Serialize};

pub const RPC_EVM_PROOF_STEP_CIRCUIT: &str = "genEvmProof_SyncStep";
pub const RPC_EVM_PROOF_ROTATION_CIRCUIT: &str = "genEvmProof_CommitteeUpdate";

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenProofRotationParams {
pub spec: args::Spec,
Expand Down Expand Up @@ -64,14 +67,3 @@ pub struct SyncCommitteePoseidonResult {
fn default_beacon_api() -> String {
String::from("http://127.0.0.1:5052")
}

pub const EVM_PROOF_STEP_CIRCUIT: &str = "genEvmProofAndInstancesStepSyncCircuit";
pub const EVM_PROOF_ROTATION_CIRCUIT: &str = "genEvmProofAndInstancesRotationCircuit";

pub const EVM_PROOF_STEP_CIRCUIT_WITH_WITNESS: &str =
"genEvmProofAndInstancesStepSyncCircuitWithWitness";
pub const EVM_PROOF_ROTATION_CIRCUIT_WITH_WITNESS: &str =
"genEvmProofAndInstancesRotationCircuitWithWitness";

pub const SYNC_COMMITTEE_POSEIDON_COMPRESSED: &str = "syncCommitteePoseidonCompressed";
pub const SYNC_COMMITTEE_POSEIDON_UNCOMPRESSED: &str = "syncCommitteePoseidonUncompressed";
49 changes: 7 additions & 42 deletions prover/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
use url::Url;

use crate::rpc_api::{
EvmProofResult, GenProofRotationParams, GenProofRotationWithWitnessParams, GenProofStepParams,
GenProofStepWithWitnessParams, SyncCommitteePoseidonParams, SyncCommitteePoseidonResult,
EVM_PROOF_ROTATION_CIRCUIT, EVM_PROOF_ROTATION_CIRCUIT_WITH_WITNESS, EVM_PROOF_STEP_CIRCUIT,
EVM_PROOF_STEP_CIRCUIT_WITH_WITNESS, SYNC_COMMITTEE_POSEIDON_COMPRESSED,
SYNC_COMMITTEE_POSEIDON_UNCOMPRESSED,
EvmProofResult, GenProofRotationParams, GenProofStepParams, RPC_EVM_PROOF_ROTATION_CIRCUIT,
RPC_EVM_PROOF_STEP_CIRCUIT,
};

/// Error object in a response
Expand Down Expand Up @@ -48,51 +45,19 @@ impl Client {
}
}
/// Generates a proof along with instance values for committee Rotation circuit
pub async fn gen_evm_proof_rotation_circuit(
pub async fn gen_evm_proof_committee_update(
&self,
params: GenProofRotationParams,
) -> Result<EvmProofResult, Error> {
self.call(EVM_PROOF_ROTATION_CIRCUIT, params).await
self.call(RPC_EVM_PROOF_ROTATION_CIRCUIT, params).await
}

/// Generates a proof along with instance values for Step circuit
pub async fn gen_evm_proof_step_circuit(
pub async fn gen_evm_proof_step(
&self,
params: GenProofStepParams,
) -> Result<EvmProofResult, Error> {
self.call(EVM_PROOF_STEP_CIRCUIT, params).await
}

/// Generates a proof along with instance values for committee Rotation circuit
pub async fn gen_evm_proof_rotation_circuit_with_witness(
&self,
params: GenProofRotationWithWitnessParams,
) -> Result<EvmProofResult, Error> {
self.call(EVM_PROOF_ROTATION_CIRCUIT_WITH_WITNESS, params)
.await
}

/// Generates a proof along with instance values for Step circuit
pub async fn gen_evm_proof_step_circuit_with_witness(
&self,
params: GenProofStepWithWitnessParams,
) -> Result<EvmProofResult, Error> {
self.call(EVM_PROOF_STEP_CIRCUIT_WITH_WITNESS, params).await
}

pub async fn sync_committee_poseidon_compressed(
&self,
params: SyncCommitteePoseidonParams,
) -> Result<SyncCommitteePoseidonResult, Error> {
self.call(SYNC_COMMITTEE_POSEIDON_COMPRESSED, params).await
}

pub async fn sync_committee_poseidon_uncompressed(
&self,
params: SyncCommitteePoseidonParams,
) -> Result<SyncCommitteePoseidonResult, Error> {
self.call(SYNC_COMMITTEE_POSEIDON_UNCOMPRESSED, params)
.await
self.call(RPC_EVM_PROOF_STEP_CIRCUIT, params).await
}

/// Utility method for sending RPC requests over HTTP
Expand Down Expand Up @@ -137,7 +102,7 @@ mod test {
beacon_api: String::from("http://65.109.55.120:9596"),
};

let r = client.gen_evm_proof_step_circuit(p).await;
let r = client.gen_evm_proof_step(p).await;

match r {
Ok(r) => {
Expand Down

0 comments on commit c22bccc

Please sign in to comment.