mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-24 07:48:04 +03:00
add mul pseudocode
This commit is contained in:
parent
7405a6284a
commit
6f9db500c7
@ -1,7 +1,7 @@
|
||||
use snarkos_models::gadgets::utilities::boolean::Boolean;
|
||||
|
||||
/// Sign extends an array of bits to the desired length.
|
||||
/// Least significant bit first
|
||||
/// Expects least significant bit first
|
||||
pub trait SignExtend
|
||||
where
|
||||
Self: std::marker::Sized,
|
||||
|
@ -23,10 +23,25 @@ use snarkos_models::{
|
||||
|
||||
macro_rules! mul_int_impl {
|
||||
($($gadget: ident)*) => ($(
|
||||
/// Bitwise multiplication of two signed integer objects.
|
||||
impl<F: PrimeField> Mul<F> for $gadget {
|
||||
|
||||
type ErrorType = SignedIntegerError;
|
||||
|
||||
fn mul<CS: ConstraintSystem<F>>(&self, mut cs: CS, other: &Self) -> Result<Self, Self::ErrorType> {
|
||||
// pseudocode:
|
||||
//
|
||||
// res = 0;
|
||||
// for (i, bit) in other.bits.enumerate() {
|
||||
// shifted_self = self << i;
|
||||
//
|
||||
// if bit {
|
||||
// res += shifted_self;
|
||||
// }
|
||||
// }
|
||||
// return res
|
||||
|
||||
|
||||
// Conditionally select constant result
|
||||
let is_constant = Boolean::constant(Self::result_is_constant(&self, &other));
|
||||
let allocated_false = Boolean::from(AllocatedBit::alloc(&mut cs.ns(|| "false"), || Ok(false)).unwrap());
|
||||
|
Loading…
Reference in New Issue
Block a user