Skip to content

Best practice to convert sfix comparison results to sbit for "Free XOR" logic? #1756

@Fannxy

Description

@Fannxy

Hi,

I am implementing a logic to determine which interval a secret value x belongs to (One-hot encoding based on thresholds).

Here is my current implementation using sfix:

# x is an sfix, test is a list of plain integers/floats
x = sfix(0.5)
test=[1, 2, 3] # for example
comp = [x >= i for i in test]

# Detecting the edge to get the one-hot vector
# Logical goal: (comp[i] XOR comp[i-1])
xor_comp = [comp[i] ^ comp[i-1] for i in range(1, len(comp))] + [comp[-1]]

Since sfix comparisons return sintbit (0 or 1 in the field), the ^ operator in the list comprehension is evaluated as Arithmetic XOR (a+b−2ab). This introduces 1 multiplication (communication round) for every interval check.

I would like to utilize the "Free XOR" (or local operation) property usually associated with binary types.
Is there an efficient way (or intrinsic) to obtain the comparison result directly as sbit (or a bit-decomposed form) to avoid the arithmetic multiplication overhead during the XOR step?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions