obliv-c
obliv-c copied to clipboard
revealObliv usage
Continuing the discussion in https://github.com/samee/obliv-c/issues/14#issuecomment-257147636
So, sticking with simplicity lets say I have this same example from tutorial docs,
#include <stdio.h>
#include <obliv.oh>
int main()
{
int x=4,y;
obliv int z;
z=x;
revealOblivInt(&y,x,0);
return 0;
}
This would normally work, but I am getting segmentation fault (core dumped) on running this.
I have tried other ways and workarounds for the usage for revealObliv function but I get the same thing in every case. Also, I think since the doc has an empty section for this, as soon as I have understanding for its usage I can contribute this to the docs for the other people to follow.
Sorry, I should have better error handling. revealObliv functions convert from an obliv value to a regular one. So you want to reveal z, not x.
@samee I went through the docs for this and yeah I figured out the part you just mentioned. So, I already tried revealing z not x but the issue persists.
Ohh ... this is in main(). Yes, reveal only works inside a protocol, which needs to be started using execYaoProtocol()
Ahh. So, this is the main reason it was working only in the millionaire example and not otherwise.
And just to be sure, there isn't any other way to get the original values other than reveal function?
If you enter values through feedObliv, the only way you can retrieve them is through reveals. However, directly assigning obliv int x = 5 won't keep x secret, since both parties know that's equal to 5.
Hmmm, I get the point. Keeping apart the secrecy aspect, is there any mechanism built in to get the actual value other than revealObliv? What I mean is:
Lets say for brevity I have this
obliv bool testFunction(obliv int x, int y) {
return x>y;
}
and I call this from main by passing values (hardcoding them for simplicity atm). Lets say I call it like testFunction(1, 0). Now, is there any way using Obliv-C to get the non-garbled return value from the testFunction because from my understanding this would return the boolean in garbled form.
Actually, there is a way. Obliv-C, as an optimization, does constant propagation. So if you hardcode values or assign them directly without using feedObliv, even obliv types will carry plaintext values under the hood, not garbled labels. This greatly speeds up programs in real code, where a lot of garbled gates can be eliminated.
In fact Obliv-C has an undocumented function that we found very useful (and should document): __obliv_c__bitIsKnown(). You don't need to #include anything to use it in a .oc file. The way it works is this:
obliv bool result = testFunction(5,7);
bool plain_result;
if (__obliv_c__bitIsKnown(&plain_result, &result))
printf("Result is publicly known to be %d\n", plain_result);
else
printf("Result is garbled. Please use revealOblivBool()\n");
This will report that the result is known publicly. But if either 5 or 7 is changed to use feedObliv, that will change.
Edited: fixed argument type error.
@samee This is really cool seriously. This should be documented I agree.
Although it throws an error Cannot convert obliv type '_Bool obliv ' to non-obliv 'OblivBit___0 const *' and this is on the line where we are doing the comparison and consuming the oblivCBitIsKnown function.
Referring to the line if (__obliv_c__bitIsKnown(&plain_result, result))
My bad. Try &result. I think the function takes a pointer.
Aha. This is good stuff @samee Really. If we were to document this function would you prefer the google docs (the official I mean)?
Also, have you considered adding a docs section to the repo itself that has complete information about the important functions and some basic usage examples?
I think what we need is some kind of a wiki site. If you set one up, I will gladly link to it from my readme.
I would definitely love to. Do you have some sort of reference wiki site in your mind that you can share for my reference?
I personally like Airbnb docs. For reference maybe you can take a look at https://github.com/airbnb/enzyme and then they have a separate section for the detailed API reference https://github.com/airbnb/enzyme/tree/master/docs.
I'll start working on that anyways. It would be a good addition and meanwhile as I explore more would keep on adding stuff to that.
Not really. You can use anything that suits you. I'd suggest going for something simple, but has the ability to export contents in some standard format that is widely accepted by other wiki frameworks. Human-readable format is a plus (e.g. markdown). Other than that, if it preserves history like a wiki, and has talk pages like wikipedia, it should be good to get started.
I think the enzyme style for documentation connected to a github repository is great, and would be very valuable to have up-to-date and complete documentation to replace the google doc.
Thanks a bunch for taking the lead on this, @laumair!
@samee All right. I get it what you are saying. I will get started. Thanks :+1:
@evansuva Yeah, I think I am going to start with that. After that is updated and complete I really don't mind moving on to setting up other resources like a wiki site or something. I personally think it isn't bad to have multiple resources of information as long they are in the same place. So, for people who don't like leaving the repo for the docs, it would be nice to have all the information in a standardized manner in one place (here). It would be cherry on top to have the wiki site as well. Please share your thoughts as well on this. I am gonna start on this.