Skip to content

Commit

Permalink
Track invalid proofs (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmantica11 authored Oct 15, 2024
1 parent 20ddfaf commit f21cdf2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/api/method/get_validity_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,15 @@ pub async fn get_validity_proof(

let inclusion_proof_url = format!("{}/prove", prover_url);
let json_body = serde_json::to_string(&batch_inputs).map_err(|e| {
PhotonApiError::UnexpectedError(format!(
"Got an error while serializing the request {}",
e
))
PhotonApiError::UnexpectedError(format!("Got an error while serializing the request {}", e))
})?;
let res = client
.post(&inclusion_proof_url)
.body(json_body.clone())
.header("Content-Type", "application/json")
.send()
.await
.map_err(|e| {
PhotonApiError::UnexpectedError(format!("Error fetching proof {}", e))
})?;
.map_err(|e| PhotonApiError::UnexpectedError(format!("Error fetching proof {}", e)))?;

if !res.status().is_success() {
return Err(PhotonApiError::UnexpectedError(format!(
Expand All @@ -347,9 +342,10 @@ pub async fn get_validity_proof(
)));
}

let text = res.text().await.map_err(|e| {
PhotonApiError::UnexpectedError(format!("Error fetching proof {}", e))
})?;
let text = res
.text()
.await
.map_err(|e| PhotonApiError::UnexpectedError(format!("Error fetching proof {}", e)))?;

let proof: GnarkProofJson = serde_json::from_str(&text).map_err(|e| {
PhotonApiError::UnexpectedError(format!(
Expand Down
5 changes: 5 additions & 0 deletions src/ingester/persist/persisted_state_tree.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{cmp::max, collections::HashMap};

use cadence_macros::statsd_count;
use itertools::Itertools;
use sea_orm::{
sea_query::OnConflict, ColumnTrait, ConnectionTrait, DatabaseTransaction, DbErr, EntityTrait,
Expand All @@ -13,6 +14,7 @@ use crate::{
common::typedefs::{account::Account, hash::Hash, serializable_pubkey::SerializablePubkey},
dao::generated::state_trees,
ingester::{error::IngesterError, parser::state_update::LeafNullification},
metric,
};

use super::{compute_parent_hash, get_node_direct_ancestors};
Expand Down Expand Up @@ -359,6 +361,9 @@ pub fn validate_proof(proof: &MerkleProofWithContext) -> Result<(), PhotonApiErr
}

if computed_root != proof.root.to_vec() {
metric! {
statsd_count!("invalid_proof", 1);
}
return Err(PhotonApiError::UnexpectedError(format!(
"Computed root does not match the provided root. Proof; {:?}",
proof
Expand Down

0 comments on commit f21cdf2

Please sign in to comment.