Skip to content

ChorusOne/gaia

 
 

Repository files navigation

Cosmos Hub

banner

license LoC

This branch contains a modified version of Gaia that references a version of cosmos-sdk with an additional IBC module which enables uploading and running of light client as a WASM smart contract.

Note: Requires Go 1.14+

Installation & Running

For installation, just run make install. This will install gaiad and gaiacli in $GOPATH/bin. To run local testnet/node you can follow instructions from here.

Upload wasm bytecode of substrate light client

Once you have gaia up and running, we need to upload substrate_light_client's build using gaiacli.

gaiacli tx ibc wasm store "target/wasm32-unknown-unknown/release/substrate_client.wasm"  --gas=2000000  --from=<account with $ for gas> --chain-id "<your chain id>" --yes

Start Gaia light client daemon

Quantum tunnel interacts with light client daemon instead of interacting with gaia daemon directly. So, we also need to start Gaia LCD locally.

gaiacli rest-server --chain-id="<your chain id>" --laddr=tcp://localhost:1317  --node tcp://localhost:26657 --read-timeout 10000 --write-timeout 10000

Submit a transaction to the light client:

  1. Creating a light client: To create light client, message of type ibc/client/MsgCreateWasmClient needs to be submitted. Example of such message:
{
  "type": "ibc/client/MsgCreateWasmClient",
  "value": {
    "address": "cosmos1xccsl78jz98ydsfahrnluxefyvcnavuy4g3wd5",
    "client_id": "mtnzosnstn",
    "header": {
      "authority_set": "<Initial authority set>",
      "block": "<scale codec serialized SignedBlockWithAuthoritySet>",
      "max_headers_allowed_between_justifications": 512,
      "max_headers_allowed_to_store": 256,
      "set_id": 0
    },
    "max_clock_drift": "30000000000",
    "trusting_period": "2592000000000000",
    "unbonding_period": "2595600000000000",
    "wasm_id": "1"
  }
}

Here, wasm_id is Id of the wasm contract. max_headers_allowed_between_justifications is require that user must submit justification after stipulated blocks. This is to prevent an attack where attacker just feed non-finalized fork without submitting any justification.

  1. Update a light client: To update light client, message of type ibc/client/MsgUpdateWasmClient needs to be submitted. Example of such message:
{
  "type": "ibc/client/MsgUpdateWasmClient",
  "value": {
    "address": "cosmos1xccsl78jz98ydsfahrnluxefyvcnavuy4g3wd5",
    "client_id": "mtnzosnstn",
    "header": {
      "authority_set": "<authority set>",
      "block": "<scale codec serialized SignedBlockWithAuthoritySet>",
      "set_id": 0
    }
  }
}

Here, client_id needs to be previously referenced by MsgCreateWasmClient. authority_set and set_id are no-op for current version of light client.

Check status of the client:

There are two rpc endpoints available in Gaia LCD to query status of light client instances:

  1. http://localhost:1317/ibc/clients: Gives array of all clients exist in the system. Sample response:
{
  "height": "76",
  "result": [
    {
      "type": "ibc/client/wasm/ClientState",
      "value": {
        "id": "vffykhgkrc",
        "trusting_period": "2592000000000000",
        "unbonding_period": "2595600000000000",
        "MaxClockDrift": "30000000000",
        "frozen_height": "0",
        "last_header": {
          "Data": "<last header data>"
        },
        "validity_predicate_address": "Q4GAgIAQAAAAAAAAAAAAAAAAAAA="
      }
    },
    {
      "type": "ibc/client/wasm/ClientState",
      "value": {
        "id": "bggehqndmp",
        "trusting_period": "43230005550666000",
        "unbonding_period": "5323600000000000",
        "MaxClockDrift": "30000000000",
        "frozen_height": "0",
        "last_header": {
          "Data": "<last header data>"
        },
        "validity_predicate_address": "EpGAgIAQgBABAghAIAGAAAgAAEA="
      }
    }
  ]
}
  1. http://localhost:1317/ibc/wasm/client/{client_id}: Gets status of a particular client referred by its id.

For example, Let's take first client with id vffykhgkrc from the sample response of 1st api call. In that case, url would be: http://localhost:1317/ibc/wasm/client/vffykhgkrc and response would be:

{
  "height": "200",
  "result": "{\"best_header_height\":165,\"best_header_hash\":[130,154,171,213,11,253,140,13,103,86,2,142,169,186,243,243,198,245,76,49,38,231,98,156,110,21,70,169,224,206,174,141],\"last_finalized_header_hash\":[],\"best_header_commitment_root\":[83,250,120,181,184,202,74,105,205,244,131,140,177,137,88,254,157,92,224,21,93,231,252,89,60,56,164,212,16,9,86,122],\"current_authority_set\":\"LightAuthoritySet { set_id: 0, authorities: [(Public(88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee (5FA9nQDV...)), 1)] }\"}"
}

You can parse the stringified json to get the data about light client for example: best header, last finalized header, current authority set etc etc.

Packages

No packages published

Languages

  • Go 60.3%
  • Python 21.9%
  • Makefile 8.0%
  • HCL 6.0%
  • Shell 3.1%
  • Dockerfile 0.7%