Skip to content

Type compatibility issue with if_else #68

@manel1874

Description

@manel1874

Bug description

There is a type compatibility issue with if_else depending on the origin of the boolean used. Consider b.if_else(a, c). If b is derived from a comparison between nada dsl base types (Integer, SecretInteger, PublicInteger, etc) and a and c are rational types, the operation b.if_else(a, c) throws the following error:

     raise TypeError(f"Invalid operation: {self}.IfElse({arg_0}, {arg_1})")
TypeError: Invalid operation: SecretBoolean(inner=<nada_dsl.operations.GreaterThan object at 0x7f8df2fd18d0>).IfElse(<nada_numpy.types.SecretRational object at 0x7f8df2fd1480>, <nada_numpy.types.SecretRational object at 0x7f8df2fd1600>)

Desired behaviour: SecretBoolean should be used independently from how it was generated.

How to reproduce

In the program below, option 1 throws the above error when running nada build. Option 2 works fine.

from nada_dsl import Output, SecretInteger, Input
import nada_numpy as na

def nada_main():

    parties = na.parties(3)

    a = na.secret_rational("A", parties[0])
    b = na.secret_rational("B", parties[1])
    c = SecretInteger(Input("C", parties[0]))
    
    # Option 1: throws the above error
    out_0 = (c > Integer(1)).if_else(a, b)
    # Option 2
    # out_0 = (a > b).if_else(a, b)

    return [Output(out_0.value, "my_output_0", parties[0])]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions