@@ -18,7 +18,8 @@ use ibc_union_msg::{
18
18
msg:: {
19
19
ExecuteMsg , InitMsg , MsgBatchAcks , MsgBatchSend , MsgChannelCloseConfirm ,
20
20
MsgChannelCloseInit , MsgChannelOpenAck , MsgChannelOpenConfirm , MsgChannelOpenInit ,
21
- MsgChannelOpenTry , MsgConnectionOpenAck , MsgConnectionOpenConfirm , MsgConnectionOpenInit ,
21
+ MsgChannelOpenTry , MsgCommitMembershipProof , MsgCommitNonMembershipProof ,
22
+ MsgConnectionOpenAck , MsgConnectionOpenConfirm , MsgConnectionOpenInit ,
22
23
MsgConnectionOpenTry , MsgCreateClient , MsgForceUpdateClient , MsgIntentPacketRecv ,
23
24
MsgMigrateState , MsgPacketAcknowledgement , MsgPacketRecv , MsgPacketTimeout ,
24
25
MsgRegisterClient , MsgSendPacket , MsgUpdateClient , MsgWriteAcknowledgement ,
@@ -28,7 +29,8 @@ use ibc_union_msg::{
28
29
use ibc_union_spec:: {
29
30
path:: {
30
31
commit_packets, BatchPacketsPath , BatchReceiptsPath , ChannelPath , ClientStatePath ,
31
- ConnectionPath , ConsensusStatePath , COMMITMENT_MAGIC , COMMITMENT_MAGIC_ACK ,
32
+ ConnectionPath , ConsensusStatePath , MembershipProofPath , NonMembershipProofPath ,
33
+ COMMITMENT_MAGIC , COMMITMENT_MAGIC_ACK , NON_MEMBERSHIP_COMMITMENT_VALUE ,
32
34
} ,
33
35
Channel , ChannelId , ChannelState , ClientId , Connection , ConnectionId , ConnectionState ,
34
36
MustBeZero , Packet , Status , Timestamp ,
@@ -80,6 +82,10 @@ pub mod events {
80
82
pub const BATCH_ACKS : & str = "batch_acks" ;
81
83
pub const WRITE_ACK : & str = "write_ack" ;
82
84
}
85
+ pub mod proof {
86
+ pub const COMMIT_MEMBERSHIP : & str = "commit_membership_proof" ;
87
+ pub const COMMIT_NON_MEMBERSHIP : & str = "commit_non_membership_proof" ;
88
+ }
83
89
pub mod attribute {
84
90
pub const CLIENT_ID : & str = "client_id" ;
85
91
pub const CONNECTION_ID : & str = "connection_id" ;
@@ -105,6 +111,9 @@ pub mod events {
105
111
pub const PORT_ID : & str = "port_id" ;
106
112
pub const COUNTERPARTY_PORT_ID : & str = "counterparty_port_id" ;
107
113
pub const VERSION : & str = "version" ;
114
+ pub const PATH : & str = "path" ;
115
+ pub const VALUE : & str = "value" ;
116
+ pub const PROOF_HEIGHT : & str = "proof_height" ;
108
117
}
109
118
}
110
119
@@ -623,6 +632,25 @@ pub fn execute(
623
632
. add_attribute ( "relayer" , relayer) ,
624
633
) )
625
634
}
635
+ ExecuteMsg :: CommitMembershipProof ( MsgCommitMembershipProof {
636
+ client_id,
637
+ proof_height,
638
+ proof,
639
+ path,
640
+ value,
641
+ } ) => {
642
+ ensure_relayer ( deps. storage , & info. sender ) ?;
643
+ commit_membership_proof ( deps, client_id, proof_height, proof, path, value)
644
+ }
645
+ ExecuteMsg :: CommitNonMembershipProof ( MsgCommitNonMembershipProof {
646
+ client_id,
647
+ proof_height,
648
+ proof,
649
+ path,
650
+ } ) => {
651
+ ensure_relayer ( deps. storage , & info. sender ) ?;
652
+ commit_non_membership_proof ( deps, client_id, proof_height, proof, path)
653
+ }
626
654
}
627
655
}
628
656
@@ -2206,6 +2234,45 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractErr
2206
2234
let commit = read_commit ( deps, & BatchReceiptsPath { batch_hash } . key ( ) ) ;
2207
2235
Ok ( to_json_binary ( & commit) ?)
2208
2236
}
2237
+ QueryMsg :: GetCommittedMembershipProof {
2238
+ client_id,
2239
+ proof_height,
2240
+ path,
2241
+ } => {
2242
+ let commit = read_commit (
2243
+ deps,
2244
+ & MembershipProofPath {
2245
+ client_id,
2246
+ proof_height,
2247
+ path,
2248
+ }
2249
+ . key ( ) ,
2250
+ ) ;
2251
+ Ok ( to_json_binary ( & commit) ?)
2252
+ }
2253
+ QueryMsg :: GetCommittedNonMembershipProof {
2254
+ client_id,
2255
+ proof_height,
2256
+ path,
2257
+ } => {
2258
+ let commit = read_commit (
2259
+ deps,
2260
+ & NonMembershipProofPath {
2261
+ client_id,
2262
+ proof_height,
2263
+ path,
2264
+ }
2265
+ . key ( ) ,
2266
+ ) ;
2267
+
2268
+ if commit. is_none ( ) {
2269
+ Ok ( to_json_binary ( & false ) ?)
2270
+ } else if commit == Some ( NON_MEMBERSHIP_COMMITMENT_VALUE ) {
2271
+ Ok ( to_json_binary ( & true ) ?)
2272
+ } else {
2273
+ unreachable ! ( )
2274
+ }
2275
+ }
2209
2276
}
2210
2277
}
2211
2278
@@ -2238,6 +2305,87 @@ fn make_verify_creation_event(client_id: ClientId, event: VerifyCreationResponse
2238
2305
}
2239
2306
}
2240
2307
2308
+ fn commit_membership_proof (
2309
+ deps : DepsMut ,
2310
+ client_id : ClientId ,
2311
+ proof_height : u64 ,
2312
+ proof : Bytes ,
2313
+ path : Bytes ,
2314
+ value : Bytes ,
2315
+ ) -> Result < Response , ContractError > {
2316
+ let client_impl = client_impl ( deps. as_ref ( ) , client_id) ?;
2317
+
2318
+ query_light_client :: < ( ) > (
2319
+ deps. as_ref ( ) ,
2320
+ client_impl,
2321
+ LightClientQuery :: VerifyMembership {
2322
+ client_id,
2323
+ height : proof_height,
2324
+ proof : proof. to_vec ( ) . into ( ) ,
2325
+ path : path. clone ( ) ,
2326
+ value : value. clone ( ) ,
2327
+ } ,
2328
+ ) ?;
2329
+
2330
+ store_commit (
2331
+ deps,
2332
+ & MembershipProofPath {
2333
+ client_id,
2334
+ proof_height,
2335
+ path : path. clone ( ) ,
2336
+ }
2337
+ . key ( ) ,
2338
+ & commit ( & value) ,
2339
+ ) ;
2340
+
2341
+ Ok ( Response :: new ( ) . add_event (
2342
+ Event :: new ( events:: proof:: COMMIT_MEMBERSHIP )
2343
+ . add_attribute ( events:: attribute:: CLIENT_ID , client_id. to_string ( ) )
2344
+ . add_attribute ( events:: attribute:: PROOF_HEIGHT , proof_height. to_string ( ) )
2345
+ . add_attribute ( events:: attribute:: PATH , path. to_string ( ) )
2346
+ . add_attribute ( events:: attribute:: VALUE , value. to_string ( ) ) ,
2347
+ ) )
2348
+ }
2349
+
2350
+ fn commit_non_membership_proof (
2351
+ deps : DepsMut ,
2352
+ client_id : ClientId ,
2353
+ proof_height : u64 ,
2354
+ proof : Bytes ,
2355
+ path : Bytes ,
2356
+ ) -> Result < Response , ContractError > {
2357
+ let client_impl = client_impl ( deps. as_ref ( ) , client_id) ?;
2358
+
2359
+ query_light_client :: < ( ) > (
2360
+ deps. as_ref ( ) ,
2361
+ client_impl,
2362
+ LightClientQuery :: VerifyNonMembership {
2363
+ client_id,
2364
+ height : proof_height,
2365
+ proof : proof. to_vec ( ) . into ( ) ,
2366
+ path : path. clone ( ) ,
2367
+ } ,
2368
+ ) ?;
2369
+
2370
+ store_commit (
2371
+ deps,
2372
+ & NonMembershipProofPath {
2373
+ client_id,
2374
+ proof_height,
2375
+ path : path. clone ( ) ,
2376
+ }
2377
+ . key ( ) ,
2378
+ & commit ( NON_MEMBERSHIP_COMMITMENT_VALUE ) ,
2379
+ ) ;
2380
+
2381
+ Ok ( Response :: new ( ) . add_event (
2382
+ Event :: new ( events:: proof:: COMMIT_NON_MEMBERSHIP )
2383
+ . add_attribute ( events:: attribute:: CLIENT_ID , client_id. to_string ( ) )
2384
+ . add_attribute ( events:: attribute:: PROOF_HEIGHT , proof_height. to_string ( ) )
2385
+ . add_attribute ( events:: attribute:: PATH , path. to_string ( ) ) ,
2386
+ ) )
2387
+ }
2388
+
2241
2389
#[ cfg( test) ]
2242
2390
mod tests {
2243
2391
use hex_literal:: hex;
0 commit comments