emp-sh2pc icon indicating copy to clipboard operation
emp-sh2pc copied to clipboard

shift operation will change a secure negative integer from signed to unsigned

Open zyl2016 opened this issue 2 years ago • 0 comments

Hello, sorry for disturbing you. I have observed that shift operations can be conducted on secure integers successfully on bit-representation. However, it will turn a negative signed integer into an unsigned one. Here is an example.

Integer a(32, -44, ALICE);
cout<< "a:	"<< a.reveal<int32_t>()<<endl;
a = (a >> 2);
cout<< "a:	"<< a.reveal<int32_t>()<<endl;

The output is:

a:        -44
a:        1073741813

From the view of bit representation, the 11111111 11111111 11111111 11010100 is shifted by 2 bits to 11111111 11111111 11111111 11110101 successfully. However, it is now converted to an unsigned form. In comparison, if the operation is conducted on a public variable

int a = -44;
cout<< "a:	"<< a<<endl;
a = a >> 2;
cout<< "a:	"<< a<<endl;

The output is:

a:        -44
a:        -11

I am curious whether this is caused by my misuse of shift or if I did not define the type of variable correctly. Or maybe, this behavior is special in the MPC scenario so I should avoid using it. May you help me by explaining this?

zyl2016 avatar Sep 13 '23 09:09 zyl2016