Slide 1

Slide 1 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. Demo: Interoperability with Hyperledger Lab YUI
 Datachain, Inc Software Engineer Koji Matsumiya

Slide 2

Slide 2 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. 2 Agenda ● What is YUI ● IBC Overview ● How YUI Works ● Comparison of Interoperability Methods ● Demo: Token Transfer between Hyperledger Fabric and Cosmos ● Current Work: LCP

Slide 3

Slide 3 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. 3 What is YUI ● YUI is a Hyperledger Lab project to facilitate interoperability between multiple heterogeneous blockchains ● YUI provides modules and middleware for cross-chain communication ● YUI follows on Inter Blockchain Communication (IBC) protocol by Cosmos ● Core concepts ○ Do not require additional trust by on-chain verification ○ Support arbitrary data transfer and computation ○ Enable developers to develop chain-independent yui-fabric-ibc yui-ibc-solidity yui-corda-ibc YUI A Project to Achieve Interoperability Between Multiple Heterogeneous Ledgers Application Module IBC Module Development Tools Explorer etc. Modules to support the development of cross-chain contracts Client (on-chain) modules to support various ledgers in align with the design principles To be included in YUI Relayer Available in YUI a middleware to relay packets between sets of various ledgers. See also hyperledger-labs/yui-docs at the below link for more details https://github.com/hyperledger-labs/yui-docs To be included in YUI

Slide 4

Slide 4 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. Host Machine IBC Module 4 IBC Overview ● IBC is an implementation as the inter-blockchain communication protocol (ICS) by Interchain Foundation ● IBC is a layered protocol for interoperability between different ledgers ● IBC is the core piece of Cosmos ○ Cosmos provides Cosmos SDK to develop a blockchain ○ Enable Cosmos SDK-based blockchains interoperability ○ Cosmos Hub is a well-known network App Module Routing Module Handler Module Client Module Connection Module Channel Module Port Module App Module App Module B depends on A A B Module layout

Slide 5

Slide 5 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. IBC Modules 5 How YUI Works ● YUI enables interoperability with the IBC-based Light Client method ● Light clients are a core component to trace and verify counterparty states at local ○ Light clients require a block header for verification ○ One side needs to implement a light client of the other side ● Relayer has a role in the physical connection of IBC ○ Relayer detects and transmits packets from one to the other ○ Relayer is an off-chain process but is permissionless and trustless App Module Hyperledger Fabric App Module Cosmos yui-relayer off-chain process IBC Modules Fabric Client in yui-fabric-ibc 6. Send a packet 5. Verify a header & update 8. Call a function 2. Detect a packet 1. Create a packet Flow: Cosmos send a packet to Hyperledger Fabric 3. Get a latest header 4. Submit a header 7. Verify a packet Tendermint Client in ibc-go

Slide 6

Slide 6 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. 6 Comparison of Interoperability Methods ● Pros for Light Client method ○ More secure External Validators method Trusted Third Party Verified by third party outside of both sides HTLC method Protocol using a hash lock and a time lock between parties Light Client method Verified one chain by the other This method is simple but does not support complex logic. This method requires no additional trust, but costs more for the chain. Blockchain X Token s 方 式 を 採 用 Blockchain Y Token Blockchain X Token Blockchain Y Token 監視 監視 Blockchain X Blockchain Y Token Verify Hash Token Hash This method requires additional trust, but costs less for the chain. ● Cons for Light Client method ○ Low extensibility ○ High verification cost

Slide 7

Slide 7 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. 7 Demo: Token transfer between Hyperledger Fabric and Cosmos ● Transfer fungible token between Hyperledger Fabric and Cosmos by ICS-20 ○ ICS-20 is a specification in IBC/APP ○ Refer to fabric-cosmos-ibc-demo repository ● Main components ○ yui-relayer: Relayer implementation for IBC ○ yui-fabric-ibc: IBC implementation in Golang for Hyperledger Fabric. ○ ibc-go: IBC implementation in Golang for Cosmos/Tendermint ■ Tendermint is a PoS consensus algorithm Relayer Cosmos Fabric 1. Call token transfer from Cosmos to Fabric 2. Lock token & Create a packet 3. Detect a packet & Send to Fabric 4. Verify a packet & Mint token & Create an ack packet 5. Detect an ack packet & Send to Cosmos 6. Verify an ack packet & Succeeded * Note that this sequence is simplified.

Slide 8

Slide 8 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. 8 Demo: Directory Structure The chaincode and contract include an IBC application that references the transfer module for Fabric and Cosmos The networks includes environments such as Dockerfile, utility scripts, and some configs for launch blockchain respectively The relayer refers to yui-relayer repository using Git-submodule The tests has demo scripts and relayer configs

Slide 9

Slide 9 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. 9 Demo: How to implement business logic on Fabric and Cosmos ● Fabric ○ Running Chaincode like Smart Contract using Golang ○ The yui-fabric-ibc provides IBC Chaincode integrated Cosmos modules ○ Therefore, implement Cosmos modules as well as Cosmos blockchain ● Cosmos ○ Implement IBCModule based on Cosmos SDK in Golang type IBCModule interface { OnRecvPacket( ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress, ) exported.Acknowledgement OnAcknowledgementPacket( ctx sdk.Context, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress, ) (*sdk.Result, error) OnTimeoutPacket( ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress, ) (*sdk.Result, error) } 05-port/…/module.go (showed only one part) type MsgServer interface { Transfer(context.Context, *MsgTransfer) (*MsgTransferResponse, error) transfer/…/msg_server.go Call when receiving a packet from Relayer Call when receiving an ack from Relayer Call when exceeding timeout There is an entry point to initiate token transfer

Slide 10

Slide 10 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. 10 Demo: Relayer configurations { "src": { "chain-id": "ibc0", "client-id": "ibconeclient", "connection-id": "ibconeconnection", "channel-id": "ibconexfer", "port-id": "transfer", "order": "unordered", "version": "ics20-1" }, "dst": { "chain-id": "ibc1", "client-id": "ibczeroclient", "connection-id": "ibczeroconnection", "channel-id": "ibczeroxfer", "port-id": "transfer", "order": "unordered", "version": "ics20-1" }, "strategy": { "type": "naive" } } path.json { "@type": "/relayer.fabric.config.ChainConfig", "chain_id": "ibc1", "msp_id": "PlatformerMSP", "channel": "channel1", "chaincode_id": "trade", "connection_profile_path": "./ccp/platformer.yaml", "ibc_policies": ["PlatformerMSP"], "endorsement_policies": ["PlatformerMSP"], "msp_config_paths": ["./fixtures/msps/PlatformerMSP"] } ibc-1.json { "@type": "/relayer.tendermint.config.ChainConfig", "key": "testkey", "chain_id": "ibc0", "rpc_addr": "http://localhost:26657", "account_prefix": "cosmos", "gas_adjustment": 1.5, "gas_prices": "0.025stake", "trusting_period": "336h" } ibc-0.json Directory structure ● The path.json specifies a connection end to each other via IBC ● The ibc-x.json has a configuration to connect to one side ibc0 is Cosmos side ibc1 is Fabric side It is necessary to establish a connection via connection and channel handshake The port-id and version are needed to tie an application module const ( ModuleName = "transfer" Version = "ics20-1" PortID = "transfer" ) transfer/…/keys.go (showed only one part)

Slide 11

Slide 11 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. 11 Demo: Build ● Build IBC applications by make build .PHONY: build build: make -C chaincode build \ && make -C contract build \ && make -C relayer build Makefile .PHONY: build build: go build -mod=readonly -o $(CURDIR)/build/app $(CURDIR)/bin chaincode/Makefile .PHONY: build build: go build -mod=readonly -o ./build/simd ./simapp/simd contract/Makefile .PHONY: build build: go build -o ./build/uly . relayer/Makefile Build a Relayer CLI to interact with Fabric and Cosmos Build an IBC application with a transfer module for Fabric Build an IBC application with a transfer module for Cosmos As a result:

Slide 12

Slide 12 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. 12 Demo: Setup ● Launch networks and initialize by make setup .PHONY: setup setup: start-cosmos start-fabric prepare .PHONY: start-fabric start-fabric: make -C networks/fabric start .PHONY: start-cosmos start-cosmos: make -C networks/cosmos up .PHONY: prepare prepare: make \ RLY_BINARY=${CURDIR}/relayer/build/uly \ TM_BINARY=${CURDIR}/contract/build/simd \ MSPS_DIR=${CURDIR}/networks/fabric/msps \ TM_DATA_DIR=${CURDIR}/networks/cosmos/fixtures/data \ -C tests prepare Makefile The start-fabric launches the Fabric network as a Docker container The start-cosmos launches Cosmos network as a Docker container The prepare runs setup scripts and works below: - Initialize both networks - Create a light client respectively - Initiate opening handshake as defined by IBC Thus, It enables both chains to communicate via IBC

Slide 13

Slide 13 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. 13 Demo: Setup ● As a result: Established channels Established connections Started Docker containers

Slide 14

Slide 14 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. 14 Demo: Transfer via IBC ● Run a demo script by make transfer echo "!!! Tendermint -> Fabric !!!" echo "Before TM balance: $(${RLY} query balance ibc0 ${TM_ADDRESS})" echo "Before Fab balance: $(${RLY} query balance ibc1 ${FABRIC_ADDRESS} | tail -n 1)" ${RLY} tx transfer ibc01 ibc0 ibc1 100samoleans ${FABRIC_ADDRESS} sleep ${TX_INTERNAL} ${RLY} tx relay ibc01 sleep ${TX_INTERNAL} ${RLY} tx acks ibc01 sleep ${TX_INTERNAL} echo "After TM balance: $(${RLY} query balance ibc0 ${TM_ADDRESS})" echo "After Fab balance: $(${RLY} query balance ibc1 ${FABRIC_ADDRESS} | tail -n 1)" test-tx (showed only a part of token transfer) transfer: make \ RLY_BINARY=${CURDIR}/relayer/build/uly \ TM_BINARY=${CURDIR}/contract/build/simd \ MSPS_DIR=${CURDIR}/networks/fabric/msps \ TM_DATA_DIR=${CURDIR}/networks/cosmos/fixtures/data \ -C tests test Makefile Printed states before the token transfer Executed transfer on Cosmos Executed transfer on Fabric Printed states after the token transfer ● As a result:

Slide 15

Slide 15 text

Copyright © 2022 Datachain, Inc. All Rights Reserved. 15 Current Work: LCP (Light Client Proxy) ● LCP is another way to address Cross-chain communication ● LCP solves the following issues of the Light Client method ○ Low extensibility ○ High verification cost LCP Node and Enclave Light Client (ELC) - Equipped with Intel SGX - ELC verifies commitment proofs from each network submitted by Relayer - Verified result (commitment) is then signed with Enclave Key and sent to the other network by Relayer Attestation Service - Provide verifiable quote for soundness and public key of LCP Enclave Relayer - Exchange information with Chains and LCP Node LCP Client - IBC client that verifies the commitment by ELC - Public key of Enclave is attained through verification of Quote by Attestation Service datachainlab/lcp