@@ -105,156 +105,99 @@ pub fn eth_dos_pod_builder(
105105
106106 // Include Alice and Bob's keys as public statements. We don't
107107 // want to reveal the middleman.
108- let alice_pubkey_copy = alice_bob_ethdos. pub_op ( Operation (
109- OperationType :: Native ( NativeOperation :: NewEntry ) ,
110- vec ! [ OperationArg :: Entry (
111- "Alice" . to_string( ) ,
112- alice_pubkey. into( ) ,
113- ) ] ,
114- ) ) ?;
115- let bob_pubkey_copy = alice_bob_ethdos. pub_op ( Operation (
116- OperationType :: Native ( NativeOperation :: NewEntry ) ,
117- vec ! [ OperationArg :: Entry ( "Bob" . to_string( ) , bob_pubkey. clone( ) ) ] ,
118- ) ) ?;
119- let charlie_pubkey = alice_bob_ethdos. priv_op ( Operation (
120- OperationType :: Native ( NativeOperation :: NewEntry ) ,
121- vec ! [ OperationArg :: Entry (
122- "Charlie" . to_string( ) ,
123- charlie_pubkey. into( ) ,
124- ) ] ,
125- ) ) ?;
108+ let alice_pubkey_copy = alice_bob_ethdos. pub_op ( op ! ( new_entry, ( "Alice" , alice_pubkey) ) ) ?;
109+ let bob_pubkey_copy = alice_bob_ethdos. pub_op ( op ! ( new_entry, ( "Bob" , bob_pubkey. clone( ) ) ) ) ?;
110+ let charlie_pubkey = alice_bob_ethdos. priv_op ( op ! ( new_entry, ( "Charlie" , charlie_pubkey) ) ) ?;
126111
127112 // The ETHDoS distance from Alice to Alice is 0.
128- let zero = alice_bob_ethdos. priv_op ( Operation (
129- OperationType :: Native ( NativeOperation :: NewEntry ) ,
130- vec ! [ OperationArg :: Entry ( "ZERO" . to_string( ) , Value :: from( 0i64 ) ) ] ,
131- ) ) ?;
132- let alice_equals_alice = alice_bob_ethdos. priv_op ( Operation (
133- OperationType :: Native ( NativeOperation :: EqualFromEntries ) ,
134- vec ! [
135- ( alice_attestation, KEY_SIGNER ) . into( ) ,
136- OperationArg :: Statement ( alice_pubkey_copy. clone( ) ) ,
137- ] ,
113+ let zero = alice_bob_ethdos. priv_literal ( & 0 ) ?;
114+ let alice_equals_alice = alice_bob_ethdos. priv_op ( op ! (
115+ eq,
116+ ( alice_attestation, KEY_SIGNER ) ,
117+ alice_pubkey_copy. clone( )
138118 ) ) ?;
139- let ethdos_alice_alice_is_zero_base = alice_bob_ethdos. priv_op ( Operation (
140- OperationType :: Custom ( eth_dos_base. clone ( ) ) ,
141- vec ! [
142- OperationArg :: Statement ( alice_equals_alice) ,
143- OperationArg :: Statement ( zero. clone( ) ) ,
144- ] ,
119+ let ethdos_alice_alice_is_zero_base = alice_bob_ethdos. priv_op ( op ! (
120+ custom,
121+ eth_dos_base. clone( ) ,
122+ alice_equals_alice,
123+ zero. clone( )
145124 ) ) ?;
146- let ethdos_alice_alice_is_zero = alice_bob_ethdos. priv_op ( Operation (
147- OperationType :: Custom ( eth_dos. clone ( ) ) ,
148- vec ! [ OperationArg :: Statement ( ethdos_alice_alice_is_zero_base) ] ,
125+ let ethdos_alice_alice_is_zero = alice_bob_ethdos. priv_op ( op ! (
126+ custom,
127+ eth_dos. clone( ) ,
128+ ethdos_alice_alice_is_zero_base
149129 ) ) ?;
150130
151131 // Alice and Charlie are ETH friends.
152132 let attestation_is_signed_pod = Statement :: from ( ( alice_attestation, KEY_TYPE ) ) ;
153- let attestation_signed_by_alice = alice_bob_ethdos. priv_op ( Operation (
154- OperationType :: Native ( NativeOperation :: EqualFromEntries ) ,
155- vec ! [
156- OperationArg :: from( ( alice_attestation, KEY_SIGNER ) ) ,
157- OperationArg :: Statement ( alice_pubkey_copy) ,
158- ] ,
159- ) ) ?;
160- let alice_attests_to_charlie = alice_bob_ethdos. priv_op ( Operation (
161- OperationType :: Native ( NativeOperation :: EqualFromEntries ) ,
162- vec ! [
163- OperationArg :: from( ( alice_attestation, "attestation" ) ) ,
164- OperationArg :: Statement ( charlie_pubkey. clone( ) ) ,
165- ] ,
133+ let attestation_signed_by_alice =
134+ alice_bob_ethdos. priv_op ( op ! ( eq, ( alice_attestation, KEY_SIGNER ) , alice_pubkey_copy) ) ?;
135+ let alice_attests_to_charlie = alice_bob_ethdos. priv_op ( op ! (
136+ eq,
137+ ( alice_attestation, "attestation" ) ,
138+ charlie_pubkey. clone( )
166139 ) ) ?;
167- let ethfriends_alice_charlie = alice_bob_ethdos. priv_op ( Operation (
168- OperationType :: Custom ( eth_friend. clone ( ) ) ,
169- vec ! [
170- OperationArg :: Statement ( attestation_is_signed_pod) ,
171- OperationArg :: Statement ( attestation_signed_by_alice) ,
172- OperationArg :: Statement ( alice_attests_to_charlie) ,
173- ] ,
140+ let ethfriends_alice_charlie = alice_bob_ethdos. priv_op ( op ! (
141+ custom,
142+ eth_friend. clone( ) ,
143+ attestation_is_signed_pod,
144+ attestation_signed_by_alice,
145+ alice_attests_to_charlie
174146 ) ) ?;
175147
176148 // ...and so are Chuck and Bob.
177149 let attestation_is_signed_pod = Statement :: from ( ( charlie_attestation, KEY_TYPE ) ) ;
178- let attestation_signed_by_charlie = alice_bob_ethdos. priv_op ( Operation (
179- OperationType :: Native ( NativeOperation :: EqualFromEntries ) ,
180- vec ! [
181- OperationArg :: from( ( charlie_attestation, KEY_SIGNER ) ) ,
182- OperationArg :: Statement ( charlie_pubkey) ,
183- ] ,
184- ) ) ?;
185- let charlie_attests_to_bob = alice_bob_ethdos. priv_op ( Operation (
186- OperationType :: Native ( NativeOperation :: EqualFromEntries ) ,
187- vec ! [
188- OperationArg :: from( ( charlie_attestation, "attestation" ) ) ,
189- OperationArg :: Statement ( bob_pubkey_copy) ,
190- ] ,
150+ let attestation_signed_by_charlie =
151+ alice_bob_ethdos. priv_op ( op ! ( eq, ( charlie_attestation, KEY_SIGNER ) , charlie_pubkey) ) ?;
152+ let charlie_attests_to_bob = alice_bob_ethdos. priv_op ( op ! (
153+ eq,
154+ ( charlie_attestation, "attestation" ) ,
155+ bob_pubkey_copy
191156 ) ) ?;
192- let ethfriends_charlie_bob = alice_bob_ethdos. priv_op ( Operation (
193- OperationType :: Custom ( eth_friend. clone ( ) ) ,
194- vec ! [
195- OperationArg :: Statement ( attestation_is_signed_pod) ,
196- OperationArg :: Statement ( attestation_signed_by_charlie) ,
197- OperationArg :: Statement ( charlie_attests_to_bob) ,
198- ] ,
157+ let ethfriends_charlie_bob = alice_bob_ethdos. priv_op ( op ! (
158+ custom,
159+ eth_friend. clone( ) ,
160+ attestation_is_signed_pod,
161+ attestation_signed_by_charlie,
162+ charlie_attests_to_bob
199163 ) ) ?;
200164
201165 // The ETHDoS distance from Alice to Charlie is 1.
202- let one = alice_bob_ethdos. priv_op ( Operation (
203- OperationType :: Native ( NativeOperation :: NewEntry ) ,
204- vec ! [ OperationArg :: Entry ( "ONE" . to_string( ) , Value :: from( 1i64 ) ) ] ,
205- ) ) ?;
166+ let one = alice_bob_ethdos. priv_literal ( & 1 ) ?;
206167 // 1 = 0 + 1
207- let ethdos_sum = alice_bob_ethdos. priv_op ( Operation (
208- OperationType :: Native ( NativeOperation :: SumOf ) ,
209- vec ! [
210- OperationArg :: Statement ( one. clone( ) ) ,
211- OperationArg :: Statement ( zero. clone( ) ) ,
212- OperationArg :: Statement ( one. clone( ) ) ,
213- ] ,
168+ let ethdos_sum =
169+ alice_bob_ethdos. priv_op ( op ! ( sum_of, one. clone( ) , zero. clone( ) , one. clone( ) ) ) ?;
170+ let ethdos_alice_charlie_is_one_ind = alice_bob_ethdos. priv_op ( op ! (
171+ custom,
172+ eth_dos_ind. clone( ) ,
173+ ethdos_alice_alice_is_zero,
174+ one. clone( ) ,
175+ ethdos_sum,
176+ ethfriends_alice_charlie
214177 ) ) ?;
215- let ethdos_alice_charlie_is_one_ind = alice_bob_ethdos. priv_op ( Operation (
216- OperationType :: Custom ( eth_dos_ind. clone ( ) ) ,
217- vec ! [
218- OperationArg :: Statement ( ethdos_alice_alice_is_zero) ,
219- OperationArg :: Statement ( one. clone( ) ) ,
220- OperationArg :: Statement ( ethdos_sum) ,
221- OperationArg :: Statement ( ethfriends_alice_charlie) ,
222- ] ,
223- ) ) ?;
224- let ethdos_alice_charlie_is_one = alice_bob_ethdos. priv_op ( Operation (
225- OperationType :: Custom ( eth_dos. clone ( ) ) ,
226- vec ! [ OperationArg :: Statement ( ethdos_alice_charlie_is_one_ind) ] ,
178+ let ethdos_alice_charlie_is_one = alice_bob_ethdos. priv_op ( op ! (
179+ custom,
180+ eth_dos. clone( ) ,
181+ ethdos_alice_charlie_is_one_ind
227182 ) ) ?;
228183
229184 // The ETHDoS distance from Alice to Bob is 2.
230185 // The constant "TWO" and the final statement are both to be
231186 // public.
232- let two = alice_bob_ethdos. pub_op ( Operation (
233- OperationType :: Native ( NativeOperation :: NewEntry ) ,
234- vec ! [ OperationArg :: Entry ( "TWO" . to_string( ) , Value :: from( 2i64 ) ) ] ,
235- ) ) ?;
187+ let two = alice_bob_ethdos. pub_literal ( & 2 ) ?;
236188 // 2 = 1 + 1
237- let ethdos_sum = alice_bob_ethdos. priv_op ( Operation (
238- OperationType :: Native ( NativeOperation :: SumOf ) ,
239- vec ! [
240- OperationArg :: Statement ( two. clone( ) ) ,
241- OperationArg :: Statement ( one. clone( ) ) ,
242- OperationArg :: Statement ( one. clone( ) ) ,
243- ] ,
244- ) ) ?;
245- let ethdos_alice_bob_is_two_ind = alice_bob_ethdos. priv_op ( Operation (
246- OperationType :: Custom ( eth_dos_ind. clone ( ) ) ,
247- vec ! [
248- OperationArg :: Statement ( ethdos_alice_charlie_is_one) ,
249- OperationArg :: Statement ( one. clone( ) ) ,
250- OperationArg :: Statement ( ethdos_sum) ,
251- OperationArg :: Statement ( ethfriends_charlie_bob) ,
252- ] ,
253- ) ) ?;
254- let _ethdos_alice_bob_is_two = alice_bob_ethdos. pub_op ( Operation (
255- OperationType :: Custom ( eth_dos. clone ( ) ) ,
256- vec ! [ OperationArg :: Statement ( ethdos_alice_bob_is_two_ind) ] ,
189+ let ethdos_sum =
190+ alice_bob_ethdos. priv_op ( op ! ( sum_of, two. clone( ) , one. clone( ) , one. clone( ) ) ) ?;
191+ let ethdos_alice_bob_is_two_ind = alice_bob_ethdos. priv_op ( op ! (
192+ custom,
193+ eth_dos_ind. clone( ) ,
194+ ethdos_alice_charlie_is_one,
195+ one. clone( ) ,
196+ ethdos_sum,
197+ ethfriends_charlie_bob
257198 ) ) ?;
199+ let _ethdos_alice_bob_is_two =
200+ alice_bob_ethdos. pub_op ( op ! ( custom, eth_dos. clone( ) , ethdos_alice_bob_is_two_ind) ) ?;
258201
259202 Ok ( alice_bob_ethdos)
260203}
0 commit comments