From 357791e67b480502db15890718041e67bbf63bb7 Mon Sep 17 00:00:00 2001 From: Arthur Paulino Date: Thu, 17 Aug 2023 11:54:14 -0300 Subject: [PATCH] error when dividing by zero; adding capacity to vector of bits --- src/circuit/gadgets/constraints.rs | 2 +- src/lem/interpreter.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/circuit/gadgets/constraints.rs b/src/circuit/gadgets/constraints.rs index 1b55595d1b..9c385d3370 100644 --- a/src/circuit/gadgets/constraints.rs +++ b/src/circuit/gadgets/constraints.rs @@ -159,7 +159,7 @@ pub(crate) fn implies_u64>( ) -> Result<(), SynthesisError> { let mut a_u64 = a.get_value().and_then(|a| a.to_u64()).unwrap_or(0); - let mut bits: Vec = vec![]; + let mut bits: Vec = Vec::with_capacity(64); for i in 0..64 { let b = a_u64 & 1; let b_bool = Boolean::Is(AllocatedBit::alloc( diff --git a/src/lem/interpreter.rs b/src/lem/interpreter.rs index 0d3938f31d..d5b5a1dd0a 100644 --- a/src/lem/interpreter.rs +++ b/src/lem/interpreter.rs @@ -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"),