I need your help in structuring data in zokrates.
I have two data let's say Attr(Public) and Res(Private).
Res data is something like this (Not fixed, keys can vary but will be same as Attr).
{
age: "21",
income: "1000",
gender: "male"
...
}
Attr also has similar keys and also some data with comparisons like Smaller Than, Greater Than or Equals. For example, age is greater than 18 but smaller than 25 (18<age<25), income is higher than 500 etc (income>500).
What would be the best way to structure Attr so that I can compare them with Res. These two data will be passed in private and public input in zokrates script.
Brief information about the Project.
Basically, I am trying to generate ZKP proof of two data public(Attr) and private(Res). Where public data will be compared with private data and if private data satisfies the requirement of public data a ZKP proof should be generated.
Thank you!
EDIT:
Please check the following structs in zokrates.
struct PrivateData {
u8 age;
field monthlySpends;
field userGender;
}
//Contains values which will be compared with private data using the equals operator
struct Eq {
u8 age;
field monthlySpends;
field userGender;
}
//Contains values which will be compared with private data using less than operator
struct Lt{
u8 age;
field monthlySpends;
}
//Contains values which will be compared with private data using greater than operator
struct Gt{
u8 age;
field monthlySpends;
}
struct PublicData {
Lt lessThan;
Eq equalsTo;
Gt greaterThan;
}
Now I want to compare its value accordingly, a static code would look something like this (Its not correct but it might help to clear what I want to achieve)
def main(PrivateData x, PublicData y) {
log("Checkin if privateData age is {}, is greater than required template data age is {}", x.age, y.greaterThan.age);
assert(x.age > y.greaterThan.age);
log("Checkin if privateData monthlySpends is {}, is greater than required template data monthlySpends is {}", x.monthlySpends, y.greaterThan.monthlySpends);
assert(x.monthlySpends > y.greaterThan.monthlySpends);
log("Checkin if privateData age is {}, is less than required template data age is {}", x.age, y.lessThan.age);
assert(x.age < y.lessThan.age);
log("Checkin if privateData monthlySpends is {}, is less than required template data monthlySpends is {}", x.monthlySpends, y.lessThan.monthlySpends);
assert(x.monthlySpends < y.lessThan.monthlySpends);
log("Checkin if privateData age is {}, is equals to required template data age is {}", x.age, y.equalsTo.age);
assert(x.age == y.equalsTo.age);
log("Checkin if privateData monthlySpends is {}, is equals to required template data monthlySpends is {}", x.monthlySpends, y.equalsTo.monthlySpends);
assert(x.monthlySpends == y.equalsTo.monthlySpends);
log("Checking if privateData gender {}, is equals to required template data gender {}", x.userGender, y.equalsTo.userGender);
assert(x.userGender == y.equalsTo.userGender);
return;
}
Can you guide the correct and optimal way to structure and compare this type of code? Struct attributes might have up to 25 values so need a dynamic solution. If you could even provide a hint like which data structure should I use for this like some kind of tree? Struct data is fixed but some attributes might be null so we need to check that too, currently using "0" to denote null values as couldn't find a way to use null in zokrates.
Here is the input JSON
[
{
"age":"26",
"monthlySpends":"0",
"userGender":"0"
},
{
"lessThan":{
"age": "25",
"monthlySpends": "0"
},
"equalsTo":{
"age": "0",
"monthlySpends": "0",
"userGender": "0"
},
"greaterThan":{
"age":"0",
"monthlySpends":"0"
}
}
]