|
1 | 1 | use crate::api::method::get_validity_proof::prover::structs::{CompressedProof, ProofABC};
|
2 | 2 | use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, Compress, Validate};
|
3 | 3 | use std::ops::Neg;
|
| 4 | +use crate::api::error::PhotonApiError; |
4 | 5 |
|
5 | 6 | type G1 = ark_bn254::g1::G1Affine;
|
6 | 7 |
|
@@ -70,32 +71,33 @@ fn change_endianness(bytes: &[u8]) -> Vec<u8> {
|
70 | 71 | ///
|
71 | 72 | /// The function assumes that the `ProofABC` structure contains its `a`, `b`, and `c` components in valid formats
|
72 | 73 | /// necessary for transformation and compression.
|
73 |
| -pub fn negate_proof(proof: ProofABC) -> CompressedProof { |
| 74 | +pub fn negate_proof(proof: ProofABC) -> Result<CompressedProof, PhotonApiError> { |
74 | 75 | let mut proof_a_neg = [0u8; 65];
|
75 | 76 |
|
76 | 77 | let proof_a: G1 = G1::deserialize_with_mode(
|
77 | 78 | &*[&change_endianness(&proof.a), &[0u8][..]].concat(),
|
78 | 79 | Compress::No,
|
79 | 80 | Validate::No,
|
80 |
| - ) |
81 |
| - .unwrap(); |
| 81 | + ).map_err(|e| PhotonApiError::UnexpectedError(format!("Failed to deserialize G1 point: {}", e)))?; |
82 | 82 |
|
83 | 83 | proof_a
|
84 | 84 | .neg()
|
85 | 85 | .x
|
86 | 86 | .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 | + |
88 | 89 | proof_a
|
89 | 90 | .neg()
|
90 | 91 | .y
|
91 | 92 | .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)))?; |
93 | 94 |
|
94 | 95 | let compressed_proof = CompressedProof {
|
95 | 96 | a: proof_a_neg[0..32].to_vec(),
|
96 | 97 | b: proof.b[0..64].to_vec(),
|
97 | 98 | c: proof.c[0..32].to_vec(),
|
98 | 99 | };
|
99 | 100 |
|
100 |
| - compressed_proof |
| 101 | + Ok(compressed_proof) |
101 | 102 | }
|
| 103 | + |
0 commit comments