Skip to content

Commit

Permalink
feat(tee): add error handling for unstable_getTeeProofs API endpoint
Browse files Browse the repository at this point in the history
Currently, the TEE verifier – the tool for continuous SGX attestation
and batch signature verification – is stuck on batches that failed to be
proven and are marked as `permanently_ignored`. The tool should be able
to distinguish between batches that are permanently ignored (and should
be skipped) and batches that have failed but will be retried. This PR
enables that distinction.

[1]: https://github.com/matter-labs/teepot/blob/main/bin/verify-era-proof-attestation/src/main.rs
  • Loading branch information
pbeza committed Nov 22, 2024
1 parent a10c4ba commit c6c92f2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 30 deletions.

This file was deleted.

1 change: 1 addition & 0 deletions core/lib/dal/src/models/storage_tee_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct StorageTeeProof {
pub signature: Option<Vec<u8>>,
pub proof: Option<Vec<u8>>,
pub updated_at: NaiveDateTime,
pub status: String,
pub attestation: Option<Vec<u8>>,
}

Expand Down
8 changes: 3 additions & 5 deletions core/lib/dal/src/tee_proof_generation_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,21 @@ impl TeeProofGenerationDal<'_, '_> {
tp.signature,
tp.proof,
tp.updated_at,
tp.status,
ta.attestation
FROM
tee_proof_generation_details tp
LEFT JOIN
tee_attestations ta ON tp.pubkey = ta.pubkey
WHERE
tp.l1_batch_number = $1
AND tp.status = $2
{}
ORDER BY tp.l1_batch_number ASC, tp.tee_type ASC
"#,
tee_type.map_or_else(String::new, |_| "AND tp.tee_type = $3".to_string())
tee_type.map_or_else(String::new, |_| "AND tp.tee_type = $2".to_string())
);

let mut query = sqlx::query_as(&query)
.bind(i64::from(batch_number.0))
.bind(TeeProofGenerationJobStatus::Generated.to_string());
let mut query = sqlx::query_as(&query).bind(i64::from(batch_number.0));

if let Some(tee_type) = tee_type {
query = query.bind(tee_type.to_string());
Expand Down
1 change: 1 addition & 0 deletions core/lib/types/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ pub struct TeeProof {
#[serde_as(as = "Option<Hex>")]
pub proof: Option<Vec<u8>>,
pub proved_at: DateTime<Utc>,
pub status: String,
#[serde_as(as = "Option<Hex>")]
pub attestation: Option<Vec<u8>>,
}
Expand Down
11 changes: 9 additions & 2 deletions core/node/api_server/src/web3/namespaces/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl UnstableNamespace {
tee_type: Option<TeeType>,
) -> Result<Vec<TeeProof>, Web3Error> {
let mut storage = self.state.acquire_connection().await?;
Ok(storage
let proofs = storage
.tee_proof_generation_dal()
.get_tee_proofs(l1_batch_number, tee_type)
.await
Expand All @@ -55,8 +55,15 @@ impl UnstableNamespace {
signature: proof.signature,
proof: proof.proof,
proved_at: DateTime::<Utc>::from_naive_utc_and_offset(proof.updated_at, Utc),
status: proof.status,
attestation: proof.attestation,
})
.collect::<Vec<_>>())
.collect::<Vec<_>>();

if proofs.is_empty() {
return Err(Web3Error::NoBlock);
}

Ok(proofs)
}
}

0 comments on commit c6c92f2

Please sign in to comment.