data61 / MP-SPDZ

Versatile framework for multi-party computation
Other
869 stars 272 forks source link

the output of 'get_secure_shuffle' #1430

Open yimingqincs opened 1 week ago

yimingqincs commented 1 week ago

G = Matrix(4, 4, sfix)
G[0][0] = 1
G[0][1] = 4
G[0][2] = 3
G[0][3] = 10

G[1][0] = 2
G[1][1] = 5
G[1][2] = 1
G[1][3] = 11

G[2][0] = 3
G[2][1] = 6
G[2][2] = 2
G[2][3] = 12.1

G[3][0] = 0
G[3][1] = 0
G[3][2] = 0
G[3][3] = 0
permutation = sint.get_secure_shuffle(len(G))
print_ln('permutation: %s', permutation.reveal())
  1. when I print the permutation of the matrix, I get permutation: 0. How do I get the correct output of the permutation?
  2. G.secure_permute(permutation, reverse=False, n_threads=None), the value of permutation has to be used by output of sint.get_secure_shuffle ? How can I change it?
mkskeller commented 1 week ago
  1. The returned value is just a handle. There is no facility to output the permutation itself.
  2. Yes. What do you mean by changing it? If you want to change the permutation protocol itself, you would have to do that in the C++ code.
yimingqincs commented 1 week ago

When I use permutation = sint.get_secure_shuffle(len(G)), I want to sort the permutation to get a new one. I can use the new permutation to perform G.secure_permute(permutation, reverse=False, n_threads=None) to get a new matrix

mkskeller commented 1 week ago

You can convert the internal representation to a secret vector representation as follows: k = sint(regint.inc(n)).secure_permute(permutation). k can then be used in sorting.reveal_sort() to permute arrays and matrices.

yimingqincs commented 1 week ago

Thanks for your quick reply! This is helpful for me.

yimingqincs commented 1 week ago

if I perform k = sint(regint.inc(len(G))) to get the k. then I use the k in reveal_sort(k,b) to permute a matrix b = sfix.Matrix(4,4). But I fail to run. Could I perform this?

I want to use the permutation of sorting matrix G to sort other matrix b.

Could you please give me some advice?

yimingqincs commented 1 week ago
G = Matrix(4, 4, sfix)
G[0][0] = 1
G[0][1] = 4
G[0][2] = 3
G[0][3] = 10

G[1][0] = 2
G[1][1] = 5
G[1][2] = 1
G[1][3] = 11

G[2][0] = 3
G[2][1] = 6
G[2][2] = 2
G[2][3] = 12.1

G[3][0] = 0
G[3][1] = 0
G[3][2] = 0
G[3][3] = 0

permutation = sint.get_secure_shuffle(len(G))
G.sort((0,))
k = sint(regint.inc(len(G))).secure_permute(permutation, reverse=True)

when I run above the code, can I get k is the permutaion of sorting G? And then we set the value of matrix b is the same as the value of matrix G.

when I perform reveal_sort(k,b) , I can't get the same permutation between b with G.

mkskeller commented 1 week ago

This is currently not implemented.