If-then-else issue in Rust

18 views
Skip to first unread message

Julen Bernabé

unread,
Feb 2, 2022, 9:52:37 AM2/2/22
to SPDZ/SCALE-MAMBA Discussion Group
Hi all,

I'm trying to compare two SecretI64 numbers and want to do some computations if the first number is greater than the second one. Algorithmically my code can be expressed as follows:

let a = SecretI64::from(5);
let b = SecretI64::from(4);
if a.gt(b) {
       println!("Hello World!");
}

I know that SecretI64 comparisons output a SecretBit, and if-then-else branches can only be expressed with conditions involving i64 numbers. For that reason, I considered the following variable changes:

let sbit = SecretBit::from(true);   // This would be replaced by a.gt(b)
let s_i64_bit = SecretI64::from(sbit);
let s_mp_bit = SecretModp::from(s_i64_bit);
let c_mp_bit = s_mp_bit.reveal();
let i_64_bit = i64::from(c_mp_bit);

As a consequence, I have turned the SecretBit into an i64 integer with value 0 (false) or 1 (true). Then I only have to write the following to branch my code:

if i_64_bit == 1 {
      // code if true
}

The issue is that the compilation of this program does not output any error, but ends without generating the needed .bc and .sch files. I attach a screenshot of the compilation. What can be wrong?

Thanks beforehand! Regards,

Julen
Captura de pantalla de 2022-02-02 15-48-34.jpg

Nigel Smart

unread,
Feb 15, 2022, 7:46:28 AM2/15/22
to sp...@googlegroups.com
Hi

Sorry for taking so long to get back to you.

Try this...

let sbit = SecretBit::from(true); // This would be replaced by
a.gt(b)
let ibit = sbit.reveal();

if ibit {
println!("This is true");
}
else {
println!("This is false");
}

No idea why you get the weird compilation behaviour
on your code

Nigel

On 02/02/2022 15:52, Julen Bernabé wrote:
> Hi all,
>
> I'm trying to compare two SecretI64 numbers and want to do some
> computations if the first number is greater than the second one.
> Algorithmically my code can be expressed as follows:
>
> *let a = SecretI64::from(5);*
> *let b = SecretI64::from(4);*
> *if a.gt(b) {*
> *println!("Hello World!");*
> *}*
> *
> *
> I know that SecretI64 comparisons output a SecretBit, and if-then-else
> branches can only be expressed with conditions involving i64 numbers.
> For that reason, I considered the following variable changes:
>
> *let sbit = SecretBit::from(true);   // This would be replaced by a.gt(b)*
> *let s_i64_bit = SecretI64::from(sbit);*
> *let s_mp_bit = SecretModp::from(s_i64_bit);*
> *let c_mp_bit = s_mp_bit.reveal();*
> *let i_64_bit = i64::from(c_mp_bit);*
> *
> *
> As a consequence, I have turned the SecretBit into an i64 integer with
> value 0 (false) or 1 (true). Then I only have to write the following to
> branch my code:
>
> *if i_64_bit == 1 {*
> *      // code if true*
> *}*
> *
> *
> The issue is that the compilation of this program does not output any
> error, but ends without generating the needed .bc and .sch files. I
> attach a screenshot of the compilation. What can be wrong?
>
> Thanks beforehand! Regards,
>
> Julen
>
> --
> You received this message because you are subscribed to the Google
> Groups "SPDZ/SCALE-MAMBA Discussion Group" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to spdz+uns...@googlegroups.com
> <mailto:spdz+uns...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/spdz/fed8e793-21aa-46f1-a759-75331ab92e05n%40googlegroups.com
> <https://groups.google.com/d/msgid/spdz/fed8e793-21aa-46f1-a759-75331ab92e05n%40googlegroups.com?utm_medium=email&utm_source=footer>.
OpenPGP_signature
Reply all
Reply to author
Forward
0 new messages