Skip to content

Commit

Permalink
Remove 'skip proof generation' feature from the TEE prover
Browse files Browse the repository at this point in the history
  • Loading branch information
pbeza committed Jun 11, 2024
1 parent 6c1c448 commit eb145f4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 93 deletions.
40 changes: 2 additions & 38 deletions core/lib/dal/src/tee_proof_generation_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,42 +154,6 @@ impl TeeProofGenerationDal<'_, '_> {
Ok(())
}

pub async fn mark_proof_generation_job_as_skipped(
&mut self,
block_number: L1BatchNumber,
) -> DalResult<()> {
let status = TeeProofGenerationJobStatus::Skipped.to_string();
let l1_batch_number = i64::from(block_number.0);
let query = sqlx::query!(
r#"
UPDATE tee_proof_generation_details
SET
status = $1,
updated_at = NOW()
WHERE
l1_batch_number = $2
"#,
status,
l1_batch_number
);
let instrumentation = Instrumented::new("mark_proof_generation_job_as_skipped")
.with_arg("status", &status)
.with_arg("l1_batch_number", &l1_batch_number);
let result = instrumentation
.clone()
.with(query)
.execute(self.storage)
.await?;
if result.rows_affected() == 0 {
let err = instrumentation.constraint_error(anyhow::anyhow!(
"Cannot mark TEE proof as skipped for a batch number that does not exist"
));
return Err(err);
}

Ok(())
}

pub async fn get_oldest_unpicked_batch(&mut self) -> DalResult<Option<L1BatchNumber>> {
let result: Option<L1BatchNumber> = sqlx::query!(
r#"
Expand Down Expand Up @@ -227,7 +191,7 @@ impl TeeProofGenerationDal<'_, '_> {
pubkey,
attestation
);
let instrumentation = Instrumented::new("mark_proof_generation_job_as_skipped")
let instrumentation = Instrumented::new("save_attestation")
.with_arg("pubkey", &pubkey)
.with_arg("attestation", &attestation);
let result = instrumentation
Expand All @@ -237,7 +201,7 @@ impl TeeProofGenerationDal<'_, '_> {
.await?;
if result.rows_affected() == 0 {
let err = instrumentation.constraint_error(anyhow::anyhow!(
"Unable to insert TEE attestation for a non-existent batch number"
"Unable to insert TEE attestation: given pubkey already has an attestation assigned"
));
return Err(err);
}
Expand Down
10 changes: 5 additions & 5 deletions core/lib/prover_interface/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ pub struct ProofGenerationDataRequest {}

pub type TeeProofGenerationDataRequest = ProofGenerationDataRequest;

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub enum GenericSubmitProofRequest<T> {
Proof(Box<T>),
#[derive(Debug, Serialize, Deserialize)]
pub enum SubmitProofRequest {
Proof(Box<L1BatchProofForL1>),
// The proof generation was skipped due to sampling
SkippedProofGeneration,
}

pub type SubmitProofRequest = GenericSubmitProofRequest<L1BatchProofForL1>;
pub type SubmitTeeProofRequest = GenericSubmitProofRequest<L1BatchTeeProofForL1>;
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct SubmitTeeProofRequest(pub Box<L1BatchTeeProofForL1>);

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct RegisterTeeAttestationRequest {
Expand Down
10 changes: 4 additions & 6 deletions core/lib/prover_interface/tests/job_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,12 @@ fn test_proof_request_serialization() {
#[test]
fn test_tee_proof_request_serialization() {
let tee_proof_str = r#"{
"Proof": {
"signature": [ 0, 1, 2, 3, 4 ],
"pubkey": [ 5, 6, 7, 8, 9 ],
"proof": [ 10, 11, 12, 13, 14 ]
}
"signature": [ 0, 1, 2, 3, 4 ],
"pubkey": [ 5, 6, 7, 8, 9 ],
"proof": [ 10, 11, 12, 13, 14 ]
}"#;
let tee_proof_result = serde_json::from_str::<SubmitTeeProofRequest>(tee_proof_str).unwrap();
let tee_proof_expected = SubmitTeeProofRequest::Proof(Box::new(L1BatchTeeProofForL1 {
let tee_proof_expected = SubmitTeeProofRequest(Box::new(L1BatchTeeProofForL1 {
signature: vec![0, 1, 2, 3, 4],
pubkey: vec![5, 6, 7, 8, 9],
proof: vec![10, 11, 12, 13, 14],
Expand Down
43 changes: 15 additions & 28 deletions core/node/proof_data_handler/src/tee_request_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl TeeRequestProcessor {
pub(crate) async fn submit_proof(
&self,
Path(l1_batch_number): Path<u32>,
Json(payload): Json<SubmitTeeProofRequest>,
Json(proof): Json<SubmitTeeProofRequest>,
) -> Result<Json<SubmitProofResponse>, RequestProcessorError> {
let l1_batch_number = L1BatchNumber(l1_batch_number);
let mut connection = self
Expand All @@ -82,33 +82,20 @@ impl TeeRequestProcessor {
.map_err(RequestProcessorError::Dal)?;
let mut dal = connection.tee_proof_generation_dal();

match payload {
SubmitTeeProofRequest::Proof(proof) => {
tracing::info!(
"Received proof {:?} for block number: {:?}",
proof,
l1_batch_number
);
dal.save_proof_artifacts_metadata(
l1_batch_number,
&proof.signature,
&proof.pubkey,
&proof.proof,
TeeType::Sgx,
)
.await
.map_err(RequestProcessorError::Dal)?;
}
SubmitTeeProofRequest::SkippedProofGeneration => {
tracing::info!(
"Received request to skip proof generation for block number: {:?}",
l1_batch_number
);
dal.mark_proof_generation_job_as_skipped(l1_batch_number)
.await
.map_err(RequestProcessorError::Dal)?;
}
}
tracing::info!(
"Received proof {:?} for block number: {:?}",
proof,
l1_batch_number
);
dal.save_proof_artifacts_metadata(
l1_batch_number,
&proof.0.signature,
&proof.0.pubkey,
&proof.0.proof,
TeeType::Sgx,
)
.await
.map_err(RequestProcessorError::Dal)?;

Ok(Json(SubmitProofResponse::Success))
}
Expand Down
26 changes: 10 additions & 16 deletions core/node/proof_data_handler/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,9 @@ async fn submit_tee_proof() {
// send a request to the /tee/submit_proofs endpoint, using a mocked TEE proof

let tee_proof_request_str = r#"{
"Proof": {
"signature": [ 0, 1, 2, 3, 4 ],
"pubkey": [ 5, 6, 7, 8, 9 ],
"proof": [ 10, 11, 12, 13, 14 ]
}
"signature": [ 0, 1, 2, 3, 4 ],
"pubkey": [ 5, 6, 7, 8, 9 ],
"proof": [ 10, 11, 12, 13, 14 ]
}"#;
let tee_proof_request =
serde_json::from_str::<SubmitTeeProofRequest>(tee_proof_request_str).unwrap();
Expand All @@ -158,17 +156,13 @@ async fn submit_tee_proof() {

// save the attestation for the pubkey

if let SubmitTeeProofRequest::Proof(ref proof) = tee_proof_request {
let attestation = [15, 16, 17, 18, 19];
let mut proof_dal = db_conn_pool.connection().await.unwrap();
proof_dal
.tee_proof_generation_dal()
.save_attestation(&proof.pubkey, &attestation)
.await
.expect("Failed to save attestation");
} else {
panic!("Expected Proof, got {:?}", tee_proof_request);
}
let attestation = [15, 16, 17, 18, 19];
let mut proof_dal = db_conn_pool.connection().await.unwrap();
proof_dal
.tee_proof_generation_dal()
.save_attestation(&tee_proof_request.0.pubkey, &attestation)
.await
.expect("Failed to save attestation");

// resend the same request; this time, it should be successful.

Expand Down

0 comments on commit eb145f4

Please sign in to comment.