From 9f80be559396dc1daccf3bce6f38b9b628d0a76e Mon Sep 17 00:00:00 2001 From: smtmfft <99081233+smtmfft@users.noreply.github.com> Date: Thu, 23 May 2024 20:58:20 +0800 Subject: [PATCH] feat: let user setup which network to run (#246) * feat: let user setup which network to run * refine entrypoint.sh Signed-off-by: smtmfft * update documents Signed-off-by: smtmfft --------- Signed-off-by: smtmfft --- docker/docker-compose.yml | 4 ++ docker/entrypoint.sh | 53 ++++++++++++++--- docs/README_Docker_and_RA.md | 60 +++++++++++++------- provers/sgx/prover/src/sgx_register_utils.rs | 1 + 4 files changed, 89 insertions(+), 29 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 42b9cc350..a7eab7e8b 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -72,6 +72,8 @@ services: - HOLESKY_BEACON_RPC=${HOLESKY_BEACON_RPC} - TAIKO_A7_RPC=${TAIKO_A7_RPC} - TAIKO_MAINNET_RPC=${TAIKO_MAINNET_RPC} + - L1_NETWORK=${L1_NETWORK} + - NETWORK=${NETWORK} # you can use your own PCCS host #- PCCS_HOST=host.docker.internal:8081 # use the host's network to connect to the PCCS @@ -106,6 +108,8 @@ services: - HOLESKY_BEACON_RPC=${HOLESKY_BEACON_RPC} - TAIKO_A7_RPC=${TAIKO_A7_RPC} - TAIKO_MAINNET_RPC=${TAIKO_MAINNET_RPC} + - L1_NETWORK=${L1_NETWORK} + - NETWORK=${NETWORK} # use the host's network to connect to the PCCS #extra_hosts: # - "host.docker.internal:host-gateway" diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 78f56b83f..4e2da305f 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -9,6 +9,8 @@ RAIKO_DOCKER_VOLUME_SECRETS_PATH="$RAIKO_DOCKER_VOLUME_PATH/secrets" RAIKO_DOCKER_VOLUME_PRIV_KEY_PATH="$RAIKO_DOCKER_VOLUME_SECRETS_PATH/priv.key" RAIKO_APP_DIR="/opt/raiko/bin" RAIKO_CONF_DIR="/etc/raiko" +RAIKO_CONF_BASE_CONFIG="$RAIKO_CONF_DIR/config.sgx.json" +RAIKO_CONF_CHAIN_SPECS="$RAIKO_CONF_DIR/chain_spec_list.docker.json" RAIKO_GUEST_APP_FILENAME="sgx-guest" RAIKO_GUEST_SETUP_FILENAME="raiko-setup" RAIKO_INPUT_MANIFEST_FILENAME="$RAIKO_GUEST_APP_FILENAME.docker.manifest.template" @@ -32,10 +34,10 @@ function bootstrap() { function bootstrap_with_self_register() { L1_NETWORK="${L1_NETWORK:-holesky}" - L2_NETWORK="${L2_NETWORK:-taiko_a7}" + NETWORK="${NETWORK:-taiko_a7}" mkdir -p "$RAIKO_DOCKER_VOLUME_SECRETS_PATH" cd "$RAIKO_APP_DIR" - ./$RAIKO_GUEST_SETUP_FILENAME bootstrap --l1-network $L1_NETWORK --network $L2_NETWORK + ./$RAIKO_GUEST_SETUP_FILENAME bootstrap --l1-network $L1_NETWORK --network $NETWORK cd - } @@ -54,7 +56,7 @@ function update_chain_spec_json() { } function update_docker_chain_specs() { - CONFIG_FILE="$RAIKO_CONF_DIR/chain_spec_list.docker.json" + CONFIG_FILE=$1 if [ ! -f $CONFIG_FILE ]; then echo "chain_spec_list.docker.json file not found." return 1 @@ -85,6 +87,40 @@ function update_docker_chain_specs() { fi } +function update_config_json() { + CONFIG_FILE=$1 + KEY_NAME=$2 + UPDATE_VALUE=$3 + jq \ + --arg update_value "$UPDATE_VALUE" \ + --arg key_name "$KEY_NAME" \ + '.[$key_name] = $update_value' $CONFIG_FILE \ + >/tmp/config_tmp.json && mv /tmp/config_tmp.json $CONFIG_FILE + echo "Updated $CONFIG_FILE $CHAIN_NAME.$KEY_NAME=$UPDATE_VALUE" +} + +function update_raiko_network() { + CONFIG_FILE=$1 + if [ -n "${L1_NETWORK}" ]; then + update_config_json $CONFIG_FILE "l1_network" $L1_NETWORK + fi + + if [ -n "${NETWORK}" ]; then + update_config_json $CONFIG_FILE "network" $NETWORK + fi +} + +function update_raiko_sgx_instance_id() { + CONFIG_FILE=$1 + if [[ -n $SGX_INSTANCE_ID ]]; then + jq \ + --arg update_value "$SGX_INSTANCE_ID" \ + '.sgx.instance_id = $update_value' $CONFIG_FILE \ + >/tmp/config_tmp.json && mv /tmp/config_tmp.json $CONFIG_FILE + echo "Update old sgx instance id to $SGX_INSTANCE_ID" + fi +} + if [[ -z "${PCCS_HOST}" ]]; then MY_PCCS_HOST=pccs:8081 else @@ -114,12 +150,15 @@ else exit 1 fi - if [[ ! -z $SGX_INSTANCE_ID ]]; then - echo "sed -i "s/123456/${SGX_INSTANCE_ID}/" /etc/raiko/config.sgx.json" - sed -i "s/123456/${SGX_INSTANCE_ID}/" /etc/raiko/config.sgx.json + if [ ! -f $RAIKO_CONF_BASE_CONFIG ]; then + echo "$RAIKO_CONF_BASE_CONFIG file not found." + exit 1 fi - update_docker_chain_specs + #update raiko server config + update_raiko_network $RAIKO_CONF_BASE_CONFIG + update_raiko_sgx_instance_id $RAIKO_CONF_BASE_CONFIG + update_docker_chain_specs $RAIKO_CONF_CHAIN_SPECS /opt/raiko/bin/raiko-host "$@" fi diff --git a/docs/README_Docker_and_RA.md b/docs/README_Docker_and_RA.md index 86e163678..ef21a50cf 100644 --- a/docs/README_Docker_and_RA.md +++ b/docs/README_Docker_and_RA.md @@ -361,11 +361,29 @@ emit InstanceAdded(id: 1, instance: 0xc369eedf4C69CacceDa551390576EAd2383E6f9E, ## Running Raiko -Once you've completed the above steps, you can actually run a prover. Your `SGX_INSTANCE_ID` is the one emitted in the `InstanceAdded` event above. +Once you've completed the above steps, you can actually run a prover. +Raiko now supports more configurations, which need to be carefully checked to avoid errors. + + - SGX_INSTANCE_ID: Your `SGX_INSTANCE_ID` is the one emitted in the `InstanceAdded` event above. + - ETHEREUM_RPC: ethereum node url, from which you query the ethereum data. + - ETHEREUM_CHAIN_ID: ethereum beacon node url, from which you query the ethereum data. + - HOLESKY_RPC: ethereum holesky test node url. + - HOLESKY_BEACON_RPC: ethereum holesky test beacon node url. + - TAIKO_A7_RPC: taiko hekla(a7) testnet node url. + - TAIKO_MAINNET_RPC: taiko mainnet node url. + - L1_NETWORK: specify the l1 network if exist, default is "holesky". + - NETWORK: specify the network to be proven, could be one of ["taiko_a7", "taiko_mainnet", "ethereum", "holesky"], default is "taiko_a7". make sure both L1_NETWORK & NETWORK in chain_spec_list.docker.json + +A most common setup for hekla is: ``` cd ~/raiko/docker export SGX_INSTANCE_ID={YOUR_INSTANCE_ID} +export L1_NETWORK="holesky" +export NETWORK="taiko_a7" +export HOLESKY_RPC={YOUR_FAST_HOLESKY_NODE} +export HOLESKY_BEACON_RPC={YOUR_FAST_HOLESKY_BEACON_NODE} +export TAIKO_A7_RPC={YOUR_FAST_A7_NODE} docker compose up raiko -d ``` @@ -407,34 +425,32 @@ Once your Raiko instance is running, you can verify if it was started properly a curl --location 'http://localhost:8080' \ --header 'Content-Type: application/json' \ --data '{ - "jsonrpc": "2.0", - "method": "proof", - "params": [ - { - "proof_type": "sgx", - "block_number": 31991, - "rpc": "https://rpc.hekla.taiko.xyz/", - "l1_rpc": "{HOLESKY_RPC_URL}", - "beacon_rpc": "{HOLESKY_BEACON_RPC_URL}", - "prover": "0x7b399987d24fc5951f3e94a4cb16e87414bf2229", - "graffiti": "0x0000000000000000000000000000000000000000000000000000000000000000", - "sgx": { - "setup": false, - "bootstrap": false, - "prove": true - } - } - ], - "id": 0 + "proof_type": "sgx", + "block_number": 99999, + "prover": "0x7b399987d24fc5951f3e94a4cb16e87414bf2229", + "graffiti": "0x0000000000000000000000000000000000000000000000000000000000000000", + "sgx": { + "setup": false, + "bootstrap": false, + "prove": true + } }' ``` -Replace `HOLESKY_RPC_URL` and `HOLESKY_BEACON_RPC_URL` with your Holesky RPC urls. +Or use `./script/prove-block` like `./script/prove-block.sh taiko_a7 native 99999` to check readiness. + The response should look like this: ``` -{"jsonrpc":"2.0","id":0,"result":{"proof":"0x000000149f....", "quote": "03000200000000000a"}} +{ + "data": { + "output": null, + "proof": "0x00000206c3694ecb5c....6e0e7a36546bf98caa7bb4ac2cd4f917c2102116167e42c54849f15044c032e1c", + "quote": "03000200000000000a000f00939a72....0a2d2d2d2d2d454e442043455254494649434154452d2d2d2d2d0a00" + }, + "status": "ok" +} ``` If you received this response, then at this point, your prover is up and running: you can provide the raiko_host endpoint to your taiko-client instance for SGX proving! diff --git a/provers/sgx/prover/src/sgx_register_utils.rs b/provers/sgx/prover/src/sgx_register_utils.rs index 71c5493df..b08f41a72 100644 --- a/provers/sgx/prover/src/sgx_register_utils.rs +++ b/provers/sgx/prover/src/sgx_register_utils.rs @@ -309,6 +309,7 @@ pub async fn register_sgx_instance( .get_receipt() .await?; println!("call return tx_hash: {:?}", tx_receipt.transaction_hash); + assert!(tx_receipt.status()); let log = tx_receipt.inner.as_receipt().unwrap().logs.first().unwrap(); let sgx_id: u64 = u64::from_be_bytes(log.topics()[1].0[24..].try_into().unwrap());