Skip to content

feat(raiko): refine response to save network bandwidth #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion host/src/server/api/v3/proof/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,13 @@ async fn batch_handler(
// NOTE: Return the proof of the first sub-request
proof: {
if let raiko_reqpool::Status::Success { proof, .. } = &statuses[0] {
proof.clone()
// no need to return single proof, especially the quote,
// which is used internally as the input of aggregation.
Proof {
input: proof.input.clone(),
proof: proof.proof.clone(),
..Default::default()
}
} else {
Proof::default()
}
Expand Down
19 changes: 16 additions & 3 deletions host/src/server/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use raiko_lib::proof_type::ProofType;
use raiko_reqactor::Actor;
use raiko_reqpool::Status;
use raiko_tasks::TaskStatus;
use reth_primitives::keccak256;
use serde_json::Value;

pub fn to_v2_status(
Expand Down Expand Up @@ -109,6 +110,12 @@ pub async fn draw_for_zk_any_batch_request(
.ok_or(RaikoError::InvalidRequestConfig(
"Missing network".to_string(),
))?;
let l2_network =
batch_proof_request_opt["network"]
.as_str()
.ok_or(RaikoError::InvalidRequestConfig(
"Missing network".to_string(),
))?;
let batches =
batch_proof_request_opt["batches"]
.as_array()
Expand All @@ -121,7 +128,13 @@ pub async fn draw_for_zk_any_batch_request(
let l1_inclusion_block_number = first_batch["l1_inclusion_block_number"].as_u64().ok_or(
RaikoError::InvalidRequestConfig("Missing l1_inclusion_block_number".to_string()),
)?;
let (_, blockhash) =
get_task_data(&l1_network, l1_inclusion_block_number, actor.chain_specs()).await?;
Ok(actor.draw(&blockhash))
let random = keccak256(
format!(
"{}{}{}{}",
l1_network, l1_inclusion_block_number, l2_network, first_batch
)
.bytes()
.collect::<Vec<u8>>(),
);
Ok(actor.draw(&random))
}
42 changes: 24 additions & 18 deletions script/prove-batch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ parse_batch_pair() {
fi
json_array+="{\"batch_id\": $batch_id, \"l1_inclusion_block_number\": $height}"
first=0
done <<< "$pair"
done <<<"$pair"

json_array+="]"
echo "$json_array"
Expand All @@ -58,30 +58,30 @@ echo "Parsed batch request: $batch_request"

# Check the chain name and set the corresponding RPC values
if [ "$chain" == "ethereum" ]; then
l1_network="ethereum"
l1_network="ethereum"
elif [ "$chain" == "holesky" ]; then
l1_network="holesky"
l1_network="holesky"
elif [ "$chain" == "taiko_mainnet" ]; then
l1_network="ethereum"
l1_network="ethereum"
elif [ "$chain" == "taiko_a7" ]; then
l1_network="holesky"
l1_network="holesky"
elif [ "$chain" == "taiko_dev" ]; then
l1_network="taiko_dev_l1"
l1_network="taiko_dev_l1"
else
echo "Using customized chain name $1. Please double check the RPCs."
l1_network="holesky"
echo "Using customized chain name $1. Please double check the RPCs."
l1_network="holesky"
fi

if [ "$proof" == "native" ]; then
proofParam='
proofParam='
"proof_type": "NATIVE",
"blob_proof_type": "proof_of_equivalence",
"native" : {
"json_guest_input": null
}
'
elif [ "$proof" == "sp1" ]; then
proofParam='
proofParam='
"proof_type": "sp1",
"blob_proof_type": "proof_of_equivalence",
"sp1": {
Expand All @@ -91,7 +91,7 @@ elif [ "$proof" == "sp1" ]; then
}
'
elif [ "$proof" == "sp1-aggregation" ]; then
proofParam='
proofParam='
"proof_type": "sp1",
"blob_proof_type": "proof_of_equivalence",
"sp1": {
Expand All @@ -101,7 +101,7 @@ elif [ "$proof" == "sp1-aggregation" ]; then
}
'
elif [ "$proof" == "sgx" ]; then
proofParam='
proofParam='
"proof_type": "sgx",
"sgx" : {
"instance_id": 123,
Expand All @@ -123,7 +123,7 @@ elif [ "$proof" == "sgxgeth" ]; then
}
'
elif [ "$proof" == "risc0" ]; then
proofParam='
proofParam='
"proof_type": "risc0",
"blob_proof_type": "proof_of_equivalence",
"risc0": {
Expand All @@ -134,7 +134,7 @@ elif [ "$proof" == "risc0" ]; then
}
'
elif [ "$proof" == "risc0-bonsai" ]; then
proofParam='
proofParam='
"proof_type": "risc0",
"blob_proof_type": "proof_of_equivalence",
"risc0": {
Expand All @@ -150,16 +150,22 @@ else
fi

prover="0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
aggregate=${AGG:-false}
# assert aggregate is true or false
if [ "$aggregate" != "true" ] && [ "$aggregate" != "false" ]; then
echo "aggregate is either true or false, setting: '$aggregate' is invalid"
exit 1
fi

curl --location --request POST 'http://localhost:8080/v3/proof/batch' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer' \
--data-raw "{
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer' \
--data-raw "{
\"network\": \"$chain\",
\"l1_network\": \"$l1_network\",
\"batches\": $batch_request,
\"prover\": \"$prover\",
\"aggregate\": false,
\"aggregate\": $aggregate,
$proofParam
}"

Expand Down
Loading