Skip to content

Commit

Permalink
error when dividing by zero; adding capacity to vector of bits
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpaulino committed Aug 17, 2023
1 parent 66e953d commit 357791e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/circuit/gadgets/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub(crate) fn implies_u64<F: LurkField, CS: ConstraintSystem<F>>(
) -> Result<(), SynthesisError> {
let mut a_u64 = a.get_value().and_then(|a| a.to_u64()).unwrap_or(0);

let mut bits: Vec<Boolean> = vec![];
let mut bits: Vec<Boolean> = Vec::with_capacity(64);
for i in 0..64 {
let b = a_u64 & 1;
let b_bool = Boolean::Is(AllocatedBit::alloc(
Expand Down
3 changes: 3 additions & 0 deletions src/lem/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ impl Block {
let b = bindings.get(b)?;
let c = match (a, b) {
(Ptr::Leaf(_, f), Ptr::Leaf(_, g)) => {
if g == &F::ZERO {
bail!("Can't divide by zero")
}
Ptr::Leaf(Tag::Expr(Num), *f * g.invert().unwrap())
}
_ => bail!("Division only works on numbers"),
Expand Down

0 comments on commit 357791e

Please sign in to comment.