Skip to content

Commit 4d0bc15

Browse files
updated negate_proof to return Result for better error handling
1 parent 20b7577 commit 4d0bc15

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/api/method/get_validity_proof/prover/gnark.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::api::method::get_validity_proof::prover::structs::{CompressedProof, ProofABC};
22
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, Compress, Validate};
33
use std::ops::Neg;
4+
use crate::api::error::PhotonApiError;
45

56
type G1 = ark_bn254::g1::G1Affine;
67

@@ -70,32 +71,33 @@ fn change_endianness(bytes: &[u8]) -> Vec<u8> {
7071
///
7172
/// The function assumes that the `ProofABC` structure contains its `a`, `b`, and `c` components in valid formats
7273
/// necessary for transformation and compression.
73-
pub fn negate_proof(proof: ProofABC) -> CompressedProof {
74+
pub fn negate_proof(proof: ProofABC) -> Result<CompressedProof, PhotonApiError> {
7475
let mut proof_a_neg = [0u8; 65];
7576

7677
let proof_a: G1 = G1::deserialize_with_mode(
7778
&*[&change_endianness(&proof.a), &[0u8][..]].concat(),
7879
Compress::No,
7980
Validate::No,
80-
)
81-
.unwrap();
81+
).map_err(|e| PhotonApiError::UnexpectedError(format!("Failed to deserialize G1 point: {}", e)))?;
8282

8383
proof_a
8484
.neg()
8585
.x
8686
.serialize_with_mode(&mut proof_a_neg[..32], Compress::No)
87-
.unwrap();
87+
.map_err(|e| PhotonApiError::UnexpectedError(format!("Failed to serialize x coordinate: {}", e)))?;
88+
8889
proof_a
8990
.neg()
9091
.y
9192
.serialize_with_mode(&mut proof_a_neg[32..], Compress::No)
92-
.unwrap();
93+
.map_err(|e| PhotonApiError::UnexpectedError(format!("Failed to serialize y coordinate: {}", e)))?;
9394

9495
let compressed_proof = CompressedProof {
9596
a: proof_a_neg[0..32].to_vec(),
9697
b: proof.b[0..64].to_vec(),
9798
c: proof.c[0..32].to_vec(),
9899
};
99100

100-
compressed_proof
101+
Ok(compressed_proof)
101102
}
103+

src/api/method/get_validity_proof/prover/prove.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub(crate) async fn generate_proof(
180180
}
181181

182182
Ok(ProverResult {
183-
compressed_proof: compressed_gnark_proof,
183+
compressed_proof: compressed_gnark_proof?,
184184
account_proof_details: account_details,
185185
address_proof_details: address_details,
186186
})

0 commit comments

Comments
 (0)