Skip to content

Commit

Permalink
feat: let user setup which network to run (#246)
Browse files Browse the repository at this point in the history
* feat: let user setup which network to run

* refine entrypoint.sh

Signed-off-by: smtmfft <[email protected]>

* update documents

Signed-off-by: smtmfft <[email protected]>

---------

Signed-off-by: smtmfft <[email protected]>
  • Loading branch information
smtmfft authored May 23, 2024
1 parent 78a633d commit 9f80be5
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 29 deletions.
4 changes: 4 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
53 changes: 46 additions & 7 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 -
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
60 changes: 38 additions & 22 deletions docs/README_Docker_and_RA.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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!
1 change: 1 addition & 0 deletions provers/sgx/prover/src/sgx_register_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 9f80be5

Please sign in to comment.