Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[Cosmoverse 2023] IBC-Solidity - Programming IB...

TOKI
October 05, 2023

[Cosmoverse 2023] IBC-Solidity - Programming IBC in Solidity

This is the deck for Cosmoverse 2023. Susumu, the VP of Product at TOKI, gave a presentation about IBC-Solidity, the IBC implementation in Solidity.

Find our more:
- GitHub: https://github.com/hyperledger-labs/yui-ibc-solidity
- X(Twitter): https://twitter.com/tokifinance

TOKI

October 05, 2023
Tweet

More Decks by TOKI

Other Decks in Technology

Transcript

  1. IBC-Solidity Overview IBC implementations in Solidity - IBC compatibility: v4.0.0

    - Supports EVM-compatible chains such as Ethereum Key Features - Implementation of ICS (IBC Core/TAO) - Implementation of ICS-20 (protobuf encoding) - Enable ERC-20 Token Transfer
  2. Key Specification Integration of Light Client (ICS-02) - Implements IClient

    interface to integrate with IBC-Solidity - Examples includes IBFT 2.0, Tendermint Light Client and Mock Client Internal encoding - Currently using solidity-protobuf for Packet encoding unlike JSON in specs such as ICS-20 - Currently, v0.1.0 is required
  3. Example: MiniToken 🪙 IBC-based token transfer between chains - Use

    IBC to create and send packets between blockchains - Create a basic token and send tokens to another blockchain - Basically, ICS-20 without denomination trace https://github.com/hyperledger-labs/yui-docs Ledgers used in sample: (MockClient is used for simplicity) - Geth - Besu (variant of Ethereum client in Java)
  4. Contract relationship IBCHandler (ICS-25) IBCChannel (ICS-04) IBCConnection (ICS-03) IBCClient (ICS-02)

    MiniToken (IBCAppBase) IBCModule (ICS-05) IBCPacket (ICS-04) MiniToken PacketData bindPort to set callbacks delegatecall Encode to send through IBCHandler ibcHandler.bindPort(PortTransfer, MiniToken.address) MiniToken App IBC-Solidity
  5. Packet Structure/Schema for MiniToken syntax = "proto3"; option go_package =

    "pkg/ibc/app"; message MiniTokenPacketData { // the token amount to be transferred uint64 amount = 1; // the sender address bytes sender = 2; // the recipient address on the destination chain bytes receiver = 3; } Generated Packet.sol: https://github.com/hyperledger-labs/yui-docs/blob/main/contracts/minitoken/solidi ty/contracts/lib/Packet.sol
  6. Key Functions for MiniToken: Send data function sendTransfer( uint64 amount,

    address receiver, string calldata sourcePort, string calldata sourceChannel, uint64 timeoutHeight ) external { require(_burn(msg.sender, amount), "MiniToken: failed to burn"); _sendPacket( MiniTokenPacketData.Data({ amount: amount, sender: abi.encodePacked(msg.sender), receiver: abi.encodePacked(receiver) }), sourcePort, sourceChannel, timeoutHeight ); emit SendTransfer( msg.sender, receiver, sourcePort, sourceChannel, timeoutHeight, amount ); }
  7. Key Functions for MiniToken: Send data (Contd.) function _sendPacket( MiniTokenPacketData.Data

    memory data, string memory sourcePort, string memory sourceChannel, uint64 timeoutHeight ) internal virtual { ibcHandler.sendPacket( sourcePort, sourceChannel, Height.Data({ revision_number: 0, revision_height: timeoutHeight }), 0, MiniTokenPacketData.encode(data) ); } interface IIBCPacket { function sendPacket( string calldata sourcePort, string calldata sourceChannel, Height.Data calldata timeoutHeight, uint64 timeoutTimestamp, bytes calldata data ) external returns (uint64);
  8. Key Functions for MiniToken: Callbacks function onRecvPacket(Packet.Data calldata packet, address

    /*relayer*/) external virtual override onlyIBC returns (bytes memory acknowledgement) { MiniTokenPacketData.Data memory data = MiniTokenPacketData.decode( packet.data ); return _newAcknowledgement(_mint(data.receiver.toAddress(), data.amount)); } function onAcknowledgementPacket( Packet.Data calldata packet, bytes calldata acknowledgement, address /*relayer*/ ) external virtual override onlyIBC { if (!_isSuccessAcknowledgement(acknowledgement)) { _refundTokens(MiniTokenPacketData.decode(packet.data)); } }
  9. $ truffle console --network=ibc0 truffle(ibc0)> MiniToken.deployed().then((instance) => instance.balanceOf(accounts[1])) BN {

    negative: 0, words: [ 0, <1 empty item> ], length: 1, red: null } truffle(ibc0)> MiniToken.deployed().then((instance) => instance.balanceOf(accounts[1])) BN { negative: 0, words: [ 100, <1 empty item> ], length: 1, red: null } truffle(ibc0)> await MiniToken.deployed().then(instance => instance.mint(accounts[1], 100)); { tx: '0xce...', receipt: { ... }, logs: [ { ... event: 'Mint', args: [Result] } ] }
  10. truffle(ibc0)> await MiniToken.deployed().then(instance => instance.sendTransfer(50, accounts[2], "transfer", "channel-0", 1500, {from:

    accounts[1]})); { tx: '0x011...', receipt: { ... }, logs: [ { ... event: 'Burn', args: [Result] }, { ... event: 'SendTransfer', args: [Result] } ] }
  11. truffle(ibc1)> MiniToken.deployed().then((instance) => instance.balanceOf(accounts[2])) BN { negative: 0, words: [

    50, <1 empty item> ], length: 1, red: null } truffle(ibc1)> await MiniToken.deployed().then(instance => instance.sendTransfer(25, accounts[1], "transfer", "channel-0", 1500, {from: accounts[2]})); { tx: '0xd7f...', receipt: { ... }, logs: [ { ... event: 'Burn', args: [Result] }, { ... event: 'SendTransfer', args: [Result] } ] } truffle(ibc1)> MiniToken.deployed().then((instance) => instance.balanceOf(accounts[2])) BN { negative: 0, words: [ 25, <1 empty item> ], length: 1, red: null }
  12. Related Projects YUI-Relayer: https://github.com/hyperledger-labs/yui-relayer - Modular architecture to support multiple

    chains (forked go-relayer) - Abstraction of “Chain” and “Prover” - Supports non-instant finality chains such as Ethereum Cosmos Ethereum LCP: https://github.com/datachainlab/cosmos-ethereum-ibc-lcp - Presented in keynote from 15:50 [IBC Gets Ready to Land on Ethereum] - PingPong between Cosmos and Ethereum with full-fledged light clients
  13. Roadmap - Already on Testnet (Sepolia) - Audit -> December

    - Mainnet 🚀 -> Early 2024 - Bridge to Noble -> 2024 Other teams also have plans 💝
  14. Key Issues - ICS-20: Use JSON for packet data serialization

    - ICS-30: Middleware support You can refer to issues: https://github.com/hyperledger-labs/yui-ibc-solidity