@@ -82,8 +82,11 @@ pub fn eth_dos_pod_builder(
8282 bob_pubkey : & Value ,
8383) -> Result < MainPodBuilder > {
8484 // Will need ETH friend and ETH DoS custom predicate batches.
85- let eth_friend_batch = eth_friend_batch ( params) ?;
85+ let eth_friend = CustomPredicateRef ( eth_friend_batch ( params) ?, 0 ) ;
8686 let eth_dos_batch = eth_dos_batch ( params) ?;
87+ let eth_dos_base = CustomPredicateRef ( eth_dos_batch. clone ( ) , 0 ) ;
88+ let eth_dos_ind = CustomPredicateRef ( eth_dos_batch. clone ( ) , 1 ) ;
89+ let eth_dos = CustomPredicateRef ( eth_dos_batch. clone ( ) , 2 ) ;
8790
8891 // ETHDoS POD builder
8992 let mut alice_bob_ethdos = MainPodBuilder :: new ( params) ;
@@ -100,15 +103,16 @@ pub fn eth_dos_pod_builder(
100103 . get ( & KEY_SIGNER . into ( ) )
101104 . ok_or ( anyhow ! ( "Could not find Charlie's public key!" ) ) ?;
102105
103- // Include Alice and Bob's keys as public statements.
106+ // Include Alice and Bob's keys as public statements. We don't
107+ // want to reveal the middleman.
104108 let alice_pubkey_copy = alice_bob_ethdos. pub_op ( Operation (
105109 OperationType :: Native ( NativeOperation :: NewEntry ) ,
106110 vec ! [ OperationArg :: Entry (
107111 "Alice" . to_string( ) ,
108112 alice_pubkey. into( ) ,
109113 ) ] ,
110114 ) ) ?;
111- let _bob_pubkey_copy = alice_bob_ethdos. pub_op ( Operation (
115+ let bob_pubkey_copy = alice_bob_ethdos. pub_op ( Operation (
112116 OperationType :: Native ( NativeOperation :: NewEntry ) ,
113117 vec ! [ OperationArg :: Entry ( "Bob" . to_string( ) , bob_pubkey. clone( ) ) ] ,
114118 ) ) ?;
@@ -132,13 +136,17 @@ pub fn eth_dos_pod_builder(
132136 OperationArg :: Statement ( alice_pubkey_copy. clone( ) ) ,
133137 ] ,
134138 ) ) ?;
135- let _ethdos_alice_alice_is_zero = alice_bob_ethdos. priv_op ( Operation (
136- OperationType :: Custom ( CustomPredicateRef ( eth_dos_batch , 0 ) ) ,
139+ let ethdos_alice_alice_is_zero_base = alice_bob_ethdos. priv_op ( Operation (
140+ OperationType :: Custom ( eth_dos_base . clone ( ) ) ,
137141 vec ! [
138142 OperationArg :: Statement ( alice_equals_alice) ,
139143 OperationArg :: Statement ( zero. clone( ) ) ,
140144 ] ,
141145 ) ) ?;
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) ] ,
149+ ) ) ?;
142150
143151 // Alice and Charlie are ETH friends.
144152 let attestation_is_signed_pod = Statement :: from ( ( alice_attestation, KEY_TYPE ) ) ;
@@ -153,35 +161,100 @@ pub fn eth_dos_pod_builder(
153161 OperationType :: Native ( NativeOperation :: EqualFromEntries ) ,
154162 vec ! [
155163 OperationArg :: from( ( alice_attestation, "attestation" ) ) ,
156- OperationArg :: Statement ( charlie_pubkey) ,
164+ OperationArg :: Statement ( charlie_pubkey. clone ( ) ) ,
157165 ] ,
158166 ) ) ?;
159- let _ethfriends_alice_charlie = alice_bob_ethdos. priv_op ( Operation (
160- OperationType :: Custom ( CustomPredicateRef ( eth_friend_batch , 0 ) ) ,
167+ let ethfriends_alice_charlie = alice_bob_ethdos. priv_op ( Operation (
168+ OperationType :: Custom ( eth_friend . clone ( ) ) ,
161169 vec ! [
162170 OperationArg :: Statement ( attestation_is_signed_pod) ,
163171 OperationArg :: Statement ( attestation_signed_by_alice) ,
164172 OperationArg :: Statement ( alice_attests_to_charlie) ,
165173 ] ,
166174 ) ) ?;
167175
176+ // ...and so are Chuck and Bob.
177+ 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+ ] ,
191+ ) ) ?;
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+ ] ,
199+ ) ) ?;
200+
168201 // The ETHDoS distance from Alice to Charlie is 1.
169- let _one = alice_bob_ethdos. priv_op ( Operation (
202+ let one = alice_bob_ethdos. priv_op ( Operation (
170203 OperationType :: Native ( NativeOperation :: NewEntry ) ,
171- vec ! [ OperationArg :: Entry ( "ZERO " . to_string( ) , Value :: from( 0i64 ) ) ] ,
204+ vec ! [ OperationArg :: Entry ( "ONE " . to_string( ) , Value :: from( 1i64 ) ) ] ,
172205 ) ) ?;
173206 // 1 = 0 + 1
174- // let ethdos_sum = alice_bob_ethdos.priv_op(
175- // Operation(
176- // OperationType::Native(NativeOperation::SumOf
177- // ),
178- // vec![
179- // OperationArg::Statement(_one.clone()),
180- // OperationArg::Statement(zero.clone()),
181- // OperationArg::Statement(zero.clone())
182- // ]
183- // )
184- // );
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+ ] ,
214+ ) ) ?;
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) ] ,
227+ ) ) ?;
228+
229+ // The ETHDoS distance from Alice to Bob is 2.
230+ // The constant "TWO" and the final statement are both to be
231+ // 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+ ) ) ?;
236+ // 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) ] ,
257+ ) ) ?;
185258
186259 Ok ( alice_bob_ethdos)
187260}
0 commit comments