Skip to content

Commit

Permalink
fix: Remove unwraps inside verify_gnark_proof (issue 1830) (succinc…
Browse files Browse the repository at this point in the history
  • Loading branch information
fedemagnani authored and ultraspicy committed Dec 4, 2024
1 parent e953601 commit 3c23e6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions crates/verifier/src/groth16/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ impl Groth16Verifier {
public_inputs: &[[u8; 32]],
groth16_vk: &[u8],
) -> Result<(), Groth16Error> {
let proof = load_groth16_proof_from_bytes(proof).unwrap();
let groth16_vk = load_groth16_verifying_key_from_bytes(groth16_vk).unwrap();
let proof = load_groth16_proof_from_bytes(proof)?;
let groth16_vk = load_groth16_verifying_key_from_bytes(groth16_vk)?;

let public_inputs =
public_inputs.iter().map(|input| Fr::from_slice(input).unwrap()).collect::<Vec<_>>();
let public_inputs = public_inputs
.iter()
.map(|input| Fr::from_slice(input))
.collect::<Result<Vec<_>, bn::FieldError>>()
.map_err(|_| Groth16Error::GeneralError(Error::InvalidData))?;
verify_groth16_algebraic(&groth16_vk, &proof, &public_inputs)
}
}
11 changes: 7 additions & 4 deletions crates/verifier/src/plonk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,14 @@ impl PlonkVerifier {
public_inputs: &[[u8; 32]],
plonk_vk: &[u8],
) -> Result<(), PlonkError> {
let plonk_vk = load_plonk_verifying_key_from_bytes(plonk_vk).unwrap();
let proof = load_plonk_proof_from_bytes(proof, plonk_vk.qcp.len()).unwrap();
let plonk_vk = load_plonk_verifying_key_from_bytes(plonk_vk)?;
let proof = load_plonk_proof_from_bytes(proof, plonk_vk.qcp.len())?;

let public_inputs =
public_inputs.iter().map(|input| Fr::from_slice(input).unwrap()).collect::<Vec<_>>();
let public_inputs = public_inputs
.iter()
.map(|input| Fr::from_slice(input))
.collect::<Result<Vec<_>, bn::FieldError>>()
.map_err(|_| PlonkError::GeneralError(Error::InvalidData))?;
verify_plonk_algebraic(&plonk_vk, &proof, &public_inputs)
}
}

0 comments on commit 3c23e6a

Please sign in to comment.