aboutsummaryrefslogtreecommitdiff
path: root/gp-scripts/firstPrice.gp
diff options
context:
space:
mode:
Diffstat (limited to 'gp-scripts/firstPrice.gp')
-rw-r--r--gp-scripts/firstPrice.gp186
1 files changed, 186 insertions, 0 deletions
diff --git a/gp-scripts/firstPrice.gp b/gp-scripts/firstPrice.gp
new file mode 100644
index 0000000..5642fa0
--- /dev/null
+++ b/gp-scripts/firstPrice.gp
@@ -0,0 +1,186 @@
1\\ From: "How to obtain full privacy in auctions" (2006) by Felix Brandt pages 19-20
2
3
4\\\\\\\\\\\\
5\\ Adapt the following values to your needs
6\\\\\\\\\\\\
7
8\\ amount of bidders
9n = 3
10\\ amount of possible prices
11k = 2^2
12\\ randomize bids (change to something static, if you like)
13bid = vector(n,i,random(k)+1)
14\\bid = vector(n,i,n-i+1) \\ first bidder wins
15\\bid = vector(n,i,i) \\ last bidder wins
16\\bid = vector(n,i,(i+1)%2) \\ second bidder wins (with ties)
17
18\\\\\\\\\\\\
19\\ SETUP
20\\\\\\\\\\\\
21
22read(group)
23read(zkp)
24
25\\\\\\\\\\\\
26\\ PROLOG
27\\\\\\\\\\\\
28
29\\ private keys of agents
30x = vector(n,i,random(q))
31\\ first index level = owning agent id (additive share)
32\\ second index level = agent id, price id
33m = vector(n,i,matrix(n,k,a,b,random(q)))
34
35\\ zkp
36proofs1 = vector(n,i,zkp1_proof(G, x[i]))
37
38\\ public keyshares of agents
39yshares = vector(n,i,proofs1[i][4])
40\\yshares = vector(n,i,G^x[i])
41
42\\ for performance evaluations we need to check the proofs for every bidder
43\\ i := checking bidder (0 == seller)
44\\ h := bidder to check
45{
46for(i=0,n,
47 for(h=1,n,
48 if(1 != zkp1_check(proofs1[h]),
49 error("zkp1 failure in round0")
50 )
51 )
52)
53}
54
55\\ shared public key
56y = prod(X=1,n,yshares[X])
57
58\\\\\\\\\\\\
59\\ ROUND1
60\\\\\\\\\\\\
61
62\\ bid matrix
63b = matrix(n,k,i,j,G^(bid[i]==j))
64
65\\ zkp
66proofs3 = matrix(n,k,i,j, zkp3_proof(G,y,G^(bid[i]==j)))
67
68\\ index = owning agent id, price id
69r = matrix(n,k,i,j,proofs3[i,j][13])
70\\r = matrix(n,k,i,j,random(q))
71
72\\ encrypted bids
73Alpha = matrix(n,k,i,j, proofs3[i,j][3])
74Beta = matrix(n,k,i,j, proofs3[i,j][4])
75\\Alpha = matrix(n,k,i,j, b[i,j]*y^r[i,j])
76\\Beta = matrix(n,k,i,j, G^r[i,j])
77
78proofs2 = vector(n,i, zkp2_proof(y,G,sum(j=1,k, r[i,j])))
79\\ i := checking bidder (0 == seller)
80\\ h := bidder to check
81\\ j := price index to check
82{
83for(i=0,n,
84 for(h=1,n,
85 for(j=1,k,
86 if(1 != zkp3_check(proofs3[h,j]),
87 error("zkp3 failure in round1")
88 )
89 );
90 if((prod(j=1,k,Alpha[h,j])/G) != proofs2[h][6],
91 error("alpha product doesn't match")
92 );
93 if(prod(j=1,k,Beta[h,j]) != proofs2[h][7],
94 error("beta product doesn't match")
95 );
96 if(1 != zkp2_check(proofs2[h]),
97 error("zkp2 failure in round1")
98 )
99 )
100)
101}
102
103\\\\\\\\\\\\
104\\ ROUND2
105\\\\\\\\\\\\
106
107\\ multiplicative shares
108\\ first index level = owning agent id (multiplicative share)
109\\ second index level = agent id, price id
110Gamma = vector(n,a,matrix(n,k,i,j, prod(h=1,n,prod(d=j+1,k,Alpha[h,d])) * prod(d=1,j-1,Alpha[i,d]) * prod(h=1,i-1,Alpha[h,j]) ))
111Delta = vector(n,a,matrix(n,k,i,j, prod(h=1,n,prod(d=j+1,k, Beta[h,d])) * prod(d=1,j-1, Beta[i,d]) * prod(h=1,i-1, Beta[h,j]) ))
112\\Gamma = vector(n,a,matrix(n,k,i,j, ( prod(h=1,n,prod(d=j+1,k,Alpha[h,d])) * prod(d=1,j-1,Alpha[i,d]) * prod(h=1,i-1,Alpha[h,j]) )^m[a][i,j] ))
113\\Delta = vector(n,a,matrix(n,k,i,j, ( prod(h=1,n,prod(d=j+1,k, Beta[h,d])) * prod(d=1,j-1, Beta[i,d]) * prod(h=1,i-1, Beta[h,j]) )^m[a][i,j] ))
114
115\\ random masking and zkp
116proofs2 = vector(n,a,matrix(n,k,i,j, zkp2_proof(Gamma[a][i,j], Delta[a][i,j], random(q)) ))
117
118\\ for performance evaluations we need to check the proofs for every bidder
119\\ i := checking bidder (0 == seller)
120\\ h := bidder to check
121\\ t := target bidder (creator of the proof)
122\\ j := price
123{
124for(t=1,n,
125 for(h=1,n,
126 for(j=1,k,
127 for(i=0,n,
128 if(1 != zkp2_check(proofs2[t][h,j]),
129 error("zkp2 failure in round2")
130 )
131 );
132 \\ use masked values generated during the zkp
133 Gamma[t][h,j] = proofs2[t][h,j][6];
134 Delta[t][h,j] = proofs2[t][h,j][7];
135 )
136 )
137)
138}
139
140
141\\\\\\\\\\\\
142\\ ROUND3
143\\\\\\\\\\\\
144
145\\ multiplicative shares (decryption)
146\\ first index level = owning agent id (multiplicative share)
147\\ second index level = agent id, price id
148Phi = vector(n,a,matrix(n,k,i,j, prod(h=1,n,Delta[h][i,j]) ))
149\\Phi = vector(n,a,matrix(n,k,i,j, prod(h=1,n,Delta[h][i,j])^x[a] ))
150
151proofs2 = vector(n,a,matrix(n,k,i,j, zkp2_proof(Phi[a][i,j], G, x[a]) ))
152
153\\ for performance evaluations we need to check the proofs for every bidder
154\\ i := checking bidder (0 == seller)
155\\ h := bidder to check
156\\ t := target bidder (creator of the proof)
157\\ j := price
158{
159for(t=1,n,
160 for(h=1,n,
161 for(j=1,k,
162 for(i=0,n,
163 if(1 != zkp2_check(proofs2[t][h,j]),
164 error("zkp2 failure in round2")
165 )
166 );
167 \\ use masked values generated during the zkp
168 Phi[t][h,j] = proofs2[t][h,j][6];
169 )
170 )
171)
172}
173
174
175\\\\\\\\\\\\
176\\ EPILOG
177\\\\\\\\\\\\
178
179\\ winner matrix
180v = matrix(n,k,a,j, prod(i=1,n,Gamma[i][a,j]) / prod(i=1,n,Phi[i][a,j]) )
181vi = lift(v)
182
183print("bids are: ", bid)
184for(X=1,n, if(vecmin(vi[X,])==1, print("And the winner is ", X) ))
185
186;