Skip to content

Commit

Permalink
feat: use spec in setup (#236)
Browse files Browse the repository at this point in the history
* feat: use spec in setup

* refactor: update docker-compose.yml to use correct file paths
  • Loading branch information
johntaiko authored May 22, 2024
1 parent 8f21a69 commit cd097a5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
18 changes: 8 additions & 10 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ services:
- ${HOME}/.config/gramine:/root/.config/gramine
- ${HOME}/.config/raiko:/root/.config/raiko
# environment:
# you can use your own PCCS host
#- PCCS_HOST=host.docker.internal:8081
# you can use your own PCCS host
#- PCCS_HOST=host.docker.internal:8081
depends_on:
- pccs
init-self-register:
Expand All @@ -34,12 +34,10 @@ services:
- /var/log/raiko:/var/log/raiko
- ${HOME}/.config/gramine:/root/.config/gramine
- ${HOME}/.config/raiko:/root/.config/raiko
- ${HOME}/.config/raiko/config/config.sgx.json:/etc/raiko/config.sgx.json
- ${HOME}/.config/raiko/config/config.sgx.json:/root/.config/raiko/config/config.sgx.json
- ${HOME}/.config/raiko/config/chain_spec_list.docker.json:/root/.config/raiko/config/chain_spec_list.docker.json
environment:
- SENDER_PRIV_KEY=${SENDER_PRIV_KEY}
- L1_RPC=${L1_RPC}
- L1_CHAIN_ID=${L1_CHAIN_ID}
- SGX_VERIFIER_ADDRESS=${SGX_VERIFIER_ADDRESS}
- HOLESKY_RPC=${HOLESKY_RPC}
- HOLESKY_BEACON_RPC=${HOLESKY_BEACON_RPC}
- TAIKO_A7_RPC=${TAIKO_A7_RPC}
Expand All @@ -52,7 +50,7 @@ services:
dockerfile: Dockerfile
image: gcr.io/evmchain/raiko:latest
container_name: raiko
command: --config-path=/etc/raiko/config.sgx.json --chain-spec-path=/etc/raiko/chain_spec_list.docker.json
command: --config-path=/root/.config/raiko/config/config.sgx.json --chain-spec-path=/root/.config/raiko/config/chain_spec_list.docker.json
devices:
- "/dev/sgx_enclave:/dev/sgx_enclave"
- "/dev/sgx_provision:/dev/sgx_provision"
Expand Down Expand Up @@ -85,16 +83,16 @@ services:
dockerfile: Dockerfile
image: gcr.io/evmchain/raiko:latest
container_name: raiko-self-register
command: --config-path=/etc/raiko/config.sgx.json --chain-spec-path=/etc/raiko/chain_spec_list.docker.json
command: --config-path=/root/.config/raiko/config/config.sgx.json --chain-spec-path=/root/.config/raiko/config/chain_spec_list.docker.json
devices:
- "/dev/sgx_enclave:/dev/sgx_enclave"
- "/dev/sgx_provision:/dev/sgx_provision"
volumes:
- /var/log/raiko:/var/log/raiko
- ${HOME}/.config/gramine:/root/.config/gramine
- ${HOME}/.config/raiko:/root/.config/raiko
- ${HOME}/.config/raiko/config/config.sgx.json:/etc/raiko/config.sgx.json
- ${HOME}/.config/raiko/config/chain_spec_list.docker.json:/etc/raiko/chain_spec_list.docker.json
- ${HOME}/.config/raiko/config/config.sgx.json:/root/.config/raiko/config/config.sgx.json
- ${HOME}/.config/raiko/config/chain_spec_list.docker.json:/root/.config/raiko/config/chain_spec_list.docker.json
ports:
- "8080:8080"
environment:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl SupportedChainSpecs {
self.0.keys().cloned().collect()
}

pub fn get_chain_spec(&self, network: &String) -> Option<ChainSpec> {
pub fn get_chain_spec(&self, network: &str) -> Option<ChainSpec> {
self.0.get(network).cloned()
}

Expand Down
13 changes: 7 additions & 6 deletions provers/sgx/setup/src/app_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ pub enum Command {

#[derive(Debug, Args)]
pub struct BootstrapArgs {
#[clap(long, default_value = "http://localhost:8545")]
pub l1_rpc: String,
#[clap(long, default_value = "31337")]
pub l1_chain_id: u64,
#[clap(long, default_value = "0x4826533B4897376654Bb4d4AD88B7faFD0C98528")]
pub sgx_verifier_address: String,
#[clap(long, default_value = "config.sgx.json")]
/// Path to a config file that includes sufficient json args to request
/// a proof of specified type. Curl json-rpc overrides its contents
pub config_filename: String,

#[arg(long, default_value = "chain_spec_list_default.json")]
/// Path to a chain spec file that includes supported chain list
pub chain_spec_filename: String,

#[arg(long, default_value = "holesky")]
pub l1_network: String,
}

fn get_default_raiko_user_config_path(subdir: &str) -> PathBuf {
Expand Down
15 changes: 11 additions & 4 deletions provers/sgx/setup/src/setup_bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use std::{

use crate::app_args::BootstrapArgs;
use alloy_primitives::Address;
use anyhow::{Context, Result};
use anyhow::{anyhow, Context, Result};
use raiko_lib::consts::SupportedChainSpecs;
use serde_json::{Number, Value};
use sgx_prover::{
bootstrap, check_bootstrap, get_instance_id, register_sgx_instance, remove_instance_id,
Expand All @@ -22,6 +23,12 @@ pub(crate) async fn setup_bootstrap(
config_dir: PathBuf,
bootstrap_args: &BootstrapArgs,
) -> Result<()> {
let cs_path = config_dir.join(&bootstrap_args.chain_spec_filename);
let chain_specs = SupportedChainSpecs::merge_from_file(cs_path.clone())?;
let l1_chain_spec = chain_specs
.get_chain_spec(&bootstrap_args.l1_network)
.ok_or_else(|| anyhow!("Unsupported l1 network: {}", bootstrap_args.l1_network))?;

let cur_dir = env::current_exe()
.expect("Fail to get current directory")
.parent()
Expand Down Expand Up @@ -56,9 +63,9 @@ pub(crate) async fn setup_bootstrap(
}?;
let register_id = register_sgx_instance(
&bootstrap_proof.quote,
&bootstrap_args.l1_rpc,
bootstrap_args.l1_chain_id,
Address::from_str(&bootstrap_args.sgx_verifier_address).unwrap(),
&l1_chain_spec.rpc,
l1_chain_spec.chain_id,
l1_chain_spec.sgx_verifier_address.unwrap(),
)
.await
.map_err(|e| anyhow::Error::msg(e.to_string()))?;
Expand Down

0 comments on commit cd097a5

Please sign in to comment.