Skip to content

Commit 514a64b

Browse files
committed
fix: make curcuit code less panicy
1 parent 2456cc7 commit 514a64b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

storage-proofs/src/circuit/create_label.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ where
4444
let fr = if alloc_bits[0].get_value().is_some() {
4545
let be_bits = alloc_bits
4646
.iter()
47-
.map(|v| v.get_value().unwrap())
48-
.collect::<Vec<bool>>();
47+
.map(|v| v.get_value().ok_or(SynthesisError::AssignmentMissing))
48+
.collect::<Result<Vec<bool>, SynthesisError>>()?;
4949

5050
let le_bits = be_bits
5151
.chunks(8)

storage-proofs/src/circuit/variables.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::fmt;
22

3+
use anyhow::Result;
4+
35
use bellperson::gadgets::num::AllocatedNum;
46
use bellperson::{ConstraintSystem, SynthesisError};
57
use paired::Engine;
@@ -39,8 +41,8 @@ impl<E: Engine> Root<E> {
3941
}
4042
}
4143

42-
pub fn var<CS: ConstraintSystem<E>>(cs: CS, fr: E::Fr) -> Self {
43-
Root::Var(AllocatedNum::alloc(cs, || Ok(fr)).unwrap())
44+
pub fn var<CS: ConstraintSystem<E>>(cs: CS, fr: E::Fr) -> Result<Self> {
45+
Ok(Root::Var(AllocatedNum::alloc(cs, || Ok(fr))?))
4446
}
4547

4648
pub fn is_some(&self) -> bool {

0 commit comments

Comments
 (0)