Skip to content
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

feat: add task image id #442

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9712749
feat(taskdb): impl Debug/Clone for TaskManager
keroro520 Jan 7, 2025
9dcc66a
feat(host): maintain task_manager instead of creating every time
keroro520 Jan 7, 2025
f5225ca
feat(taskdb): remove get_task_manager
keroro520 Jan 7, 2025
9904017
fix: resolve compilation errors and update test cases for image_id field
keroro520 Dec 30, 2024
8717a8e
feat: add image_id field to ProofRequest and ProofRequestOpt
keroro520 Dec 30, 2024
11a8f8b
feat: implement image id retrieval from environment variables
keroro520 Dec 30, 2024
3fcfc5b
feat: add image_id field to AggregationRequest and update related imp…
keroro520 Dec 30, 2024
af1df52
feat: add error handling for missing image IDs
keroro520 Dec 30, 2024
587fcee
chore: minor modification
keroro520 Dec 30, 2024
bc767e7
refactor: replace From implementation with new constructor for ProofT…
keroro520 Dec 30, 2024
95fb714
refactor: simplify ProofTaskDescriptor constructor with unified new f…
keroro520 Dec 30, 2024
c43ff1b
refactor: update ProofTaskDescriptor usage to use new constructor
keroro520 Dec 30, 2024
72104cc
refactor: simplify ProofTaskDescriptor constructor and remove From tr…
keroro520 Dec 30, 2024
1c26e95
refactor: update all ProofTaskDescriptor::from usages to use new cons…
keroro520 Dec 30, 2024
d7f2161
fix: add image_id field to AggregationOnlyRequest initialization
keroro520 Dec 30, 2024
50168fc
refactor: implement TryFrom(AggregationOnlyRequest) for AggregationTa…
keroro520 Dec 30, 2024
e56cb34
fix: throw error of missing image_id
keroro520 Dec 30, 2024
f600130
feat: add ensure_ensure_proof_request_image_id, ensure_aggregation_re…
keroro520 Dec 30, 2024
5c7dcea
feat(lib): add Prover::{current_proving_image(), current_aggregation_…
keroro520 Dec 27, 2024
76912e4
chore: fix TryInto call
keroro520 Dec 30, 2024
3220790
refactor: derive Default for ProofTaskDescriptor
keroro520 Dec 30, 2024
da7928e
feat(core): add get_proving_image/get_aggregation_image by proof_type
keroro520 Dec 27, 2024
0538053
chore: fix clippy warning
keroro520 Dec 30, 2024
89f9eab
fix: make test
keroro520 Dec 30, 2024
5994c88
feat(host): assert image_id.is_none
keroro520 Jan 6, 2025
6feefbd
chore: fix typo
keroro520 Jan 6, 2025
49944a0
chore: fix clippy
keroro520 Jan 6, 2025
8dbca97
fix(test): config redis url correctly
keroro520 Jan 7, 2025
941e104
test: run case serially
keroro520 Jan 7, 2025
7d46f5f
feat(.github): setup redis
keroro520 Jan 7, 2025
8530537
wkp
keroro520 Jan 7, 2025
3c327ba
wip
keroro520 Jan 7, 2025
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
2 changes: 2 additions & 0 deletions .github/workflows/ci-build-test-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@ jobs:
- name: Build ${{ inputs.version_name }} prover
run: make build

- name: Setup Redis service
uses: shogo82148/actions-setup-redis@v1
- name: Test ${{ inputs.version_name }} prover
run: make test
11 changes: 0 additions & 11 deletions .github/workflows/ci-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ jobs:
with:
fetch-depth: 0

- name: Check if specific file changed
id: check_file
run: |
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
if git diff --name-only origin/$BASE_BRANCH ${{ github.sha }} | grep -q "taskdb/src/redis_db.rs"; then
echo "redis changed"
echo "::set-output name=taskdb::raiko-tasks/redis-db"
else
echo "redis unchanged"
echo "::set-output name=taskdb::"
fi

build-test-native:
name: Build and test native
Expand Down
33 changes: 29 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ dirs = "5.0.1"
pathdiff = "0.2.1"
dotenv = "0.15.0"
backoff = "0.4.0"
test-log = "0.2.16"
serial_test = "3.2.0"

[patch.crates-io]
revm = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko" }
Expand Down
112 changes: 94 additions & 18 deletions core/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,58 @@ impl From<raiko_lib::mem_db::DbError> for RaikoError {

pub type RaikoResult<T> = Result<T, RaikoError>;

/// Get the proving image for a given proof type.
pub fn get_proving_image(proof_type: ProofType) -> RaikoResult<(&'static [u8], &'static [u32; 8])> {
match proof_type {
ProofType::Native => Ok(NativeProver::current_proving_image()),
ProofType::Sp1 => {
#[cfg(feature = "sp1")]
return Ok(sp1_driver::Sp1Prover::current_proving_image());
#[cfg(not(feature = "sp1"))]
Err(RaikoError::FeatureNotSupportedError(proof_type))
}
ProofType::Risc0 => {
#[cfg(feature = "risc0")]
return Ok(risc0_driver::Risc0Prover::current_proving_image());
#[cfg(not(feature = "risc0"))]
Err(RaikoError::FeatureNotSupportedError(proof_type))
}
ProofType::Sgx => {
#[cfg(feature = "sgx")]
return Ok(sgx_prover::SgxProver::current_proving_image());
#[cfg(not(feature = "sgx"))]
Err(RaikoError::FeatureNotSupportedError(proof_type))
}
}
}

/// Get the aggregation image for a given proof type.
pub fn get_aggregation_image(
proof_type: ProofType,
) -> RaikoResult<(&'static [u8], &'static [u32; 8])> {
match proof_type {
ProofType::Native => Ok(NativeProver::current_aggregation_image()),
ProofType::Sp1 => {
#[cfg(feature = "sp1")]
return Ok(sp1_driver::Sp1Prover::current_aggregation_image());
#[cfg(not(feature = "sp1"))]
Err(RaikoError::FeatureNotSupportedError(proof_type))
}
ProofType::Risc0 => {
#[cfg(feature = "risc0")]
return Ok(risc0_driver::Risc0Prover::current_aggregation_image());
#[cfg(not(feature = "risc0"))]
Err(RaikoError::FeatureNotSupportedError(proof_type))
}
ProofType::Sgx => {
#[cfg(feature = "sgx")]
return Ok(sgx_prover::SgxProver::current_aggregation_image());
#[cfg(not(feature = "sgx"))]
Err(RaikoError::FeatureNotSupportedError(proof_type))
}
}
}

/// Run the prover driver depending on the proof type.
pub async fn run_prover(
proof_type: ProofType,
Expand Down Expand Up @@ -217,6 +269,8 @@ pub struct ProofRequest {
pub proof_type: ProofType,
/// Blob proof type.
pub blob_proof_type: BlobProofType,
/// The guest image id for RISC0/SP1 provers.
pub image_id: Option<String>,
#[serde(flatten)]
/// Additional prover params.
pub prover_args: HashMap<String, Value>,
Expand Down Expand Up @@ -251,6 +305,9 @@ pub struct ProofRequestOpt {
pub proof_type: Option<String>,
/// Blob proof type.
pub blob_proof_type: Option<String>,
#[arg(long, require_equals = true)]
/// The guest image id for RISC0/SP1 provers.
pub image_id: Option<String>,
keroro520 marked this conversation as resolved.
Show resolved Hide resolved
#[command(flatten)]
#[serde(flatten)]
/// Any additional prover params in JSON format.
Expand Down Expand Up @@ -310,6 +367,24 @@ impl TryFrom<ProofRequestOpt> for ProofRequest {
type Error = RaikoError;

fn try_from(value: ProofRequestOpt) -> Result<Self, Self::Error> {
let proof_type = value
.proof_type
.as_ref()
.ok_or(RaikoError::InvalidRequestConfig(
"Missing proof_type".to_string(),
))?
.parse()
.map_err(|_| RaikoError::InvalidRequestConfig("Invalid proof_type".to_string()))?;

// Check if we need an image ID for this proof type
let image_id = match &proof_type {
ProofType::Risc0 | ProofType::Sp1 => value
.image_id
.clone()
.ok_or_else(|| RaikoError::InvalidRequestConfig("Missing image_id".to_string()))?,
_ => value.image_id.unwrap_or_default(),
};

Ok(Self {
block_number: value.block_number.ok_or(RaikoError::InvalidRequestConfig(
"Missing block number".to_string(),
Expand All @@ -335,20 +410,15 @@ impl TryFrom<ProofRequestOpt> for ProofRequest {
))?
.parse()
.map_err(|_| RaikoError::InvalidRequestConfig("Invalid prover".to_string()))?,
proof_type: value
.proof_type
.ok_or(RaikoError::InvalidRequestConfig(
"Missing proof_type".to_string(),
))?
.parse()
.map_err(|_| RaikoError::InvalidRequestConfig("Invalid proof_type".to_string()))?,
proof_type,
blob_proof_type: value
.blob_proof_type
.unwrap_or("proof_of_equivalence".to_string())
.parse()
.map_err(|_| {
RaikoError::InvalidRequestConfig("Invalid blob_proof_type".to_string())
})?,
image_id: Some(image_id),
prover_args: value.prover_args.into(),
})
}
Expand All @@ -372,6 +442,8 @@ pub struct AggregationRequest {
pub proof_type: Option<String>,
/// Blob proof type.
pub blob_proof_type: Option<String>,
/// The guest image id for RISC0/SP1 provers.
pub image_id: Option<String>,
#[serde(flatten)]
/// Any additional prover params in JSON format.
pub prover_args: ProverSpecificOpts,
Expand Down Expand Up @@ -403,6 +475,7 @@ impl From<AggregationRequest> for Vec<ProofRequestOpt> {
prover: value.prover.clone(),
proof_type: value.proof_type.clone(),
blob_proof_type: value.blob_proof_type.clone(),
image_id: value.image_id.clone(),
prover_args: value.prover_args.clone(),
},
)
Expand All @@ -426,11 +499,24 @@ impl From<ProofRequestOpt> for AggregationRequest {
prover: value.prover,
proof_type: value.proof_type,
blob_proof_type: value.blob_proof_type,
image_id: value.image_id,
prover_args: value.prover_args,
}
}
}

impl From<(AggregationRequest, Vec<Proof>)> for AggregationOnlyRequest {
fn from((request, proofs): (AggregationRequest, Vec<Proof>)) -> Self {
Self {
proofs,
aggregation_ids: request.block_numbers.iter().map(|(id, _)| *id).collect(),
proof_type: request.proof_type,
image_id: request.image_id,
prover_args: request.prover_args,
}
}
}

#[derive(Default, Clone, Serialize, Deserialize, Debug, ToSchema, PartialEq, Eq, Hash)]
#[serde(default)]
/// A request for proof aggregation of multiple proofs.
Expand All @@ -441,6 +527,7 @@ pub struct AggregationOnlyRequest {
pub proofs: Vec<Proof>,
/// The proof type.
pub proof_type: Option<String>,
pub image_id: Option<String>,
#[serde(flatten)]
/// Any additional prover params in JSON format.
pub prover_args: ProverSpecificOpts,
Expand All @@ -455,17 +542,6 @@ impl Display for AggregationOnlyRequest {
}
}

impl From<(AggregationRequest, Vec<Proof>)> for AggregationOnlyRequest {
fn from((request, proofs): (AggregationRequest, Vec<Proof>)) -> Self {
Self {
proofs,
aggregation_ids: request.block_numbers.iter().map(|(id, _)| *id).collect(),
proof_type: request.proof_type,
prover_args: request.prover_args,
}
}
}

impl AggregationOnlyRequest {
/// Merge proof request options into aggregation request options.
pub fn merge(&mut self, opts: &ProofRequestOpt) -> RaikoResult<()> {
Expand Down
5 changes: 5 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ mod tests {
proof_type,
blob_proof_type: BlobProofType::ProofOfEquivalence,
prover_args: test_proof_params(false),
image_id: None,
};
prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await;
}
Expand Down Expand Up @@ -358,6 +359,7 @@ mod tests {
proof_type,
blob_proof_type: BlobProofType::ProofOfEquivalence,
prover_args: test_proof_params(false),
image_id: None,
};
prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await;
}
Expand Down Expand Up @@ -397,6 +399,7 @@ mod tests {
proof_type,
blob_proof_type: BlobProofType::ProofOfEquivalence,
prover_args: test_proof_params(false),
image_id: None,
};
prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await;
}
Expand Down Expand Up @@ -430,6 +433,7 @@ mod tests {
proof_type,
blob_proof_type: BlobProofType::ProofOfEquivalence,
prover_args: test_proof_params(false),
image_id: None,
};
prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await;
}
Expand Down Expand Up @@ -460,6 +464,7 @@ mod tests {
proof_type,
blob_proof_type: BlobProofType::ProofOfEquivalence,
prover_args: test_proof_params(true),
image_id: None,
};
let proof = prove_block(l1_chain_spec, taiko_chain_spec, proof_request).await;

Expand Down
2 changes: 2 additions & 0 deletions host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ assert_cmd = { workspace = true }
rstest = { workspace = true }
ethers-core = { workspace = true }
rand = { workspace = true }
test-log = { workspace = true }
serial_test = { workspace = true }

[features]
default = []
Expand Down
4 changes: 3 additions & 1 deletion host/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ mod test {
blob_proof_type: BlobProofType::KzgVersionedHash,
prover_args: Default::default(),
l1_inclusion_block_number: 0,
image_id: None,
};
let raiko = Raiko::new(
l1_chain_spec.clone(),
Expand Down Expand Up @@ -137,7 +138,8 @@ mod test {
provider.provider.get_block_number().await.unwrap()
}

#[tokio::test]
#[serial_test::serial]
#[test_log::test(tokio::test)]
async fn test_generate_input_from_cache() {
let l1 = &Network::Holesky.to_string();
let l2 = &Network::TaikoA7.to_string();
Expand Down
Loading
Loading