Try   HackMD

Completion of the "Support for merkle proof integrations" milestone

Support for merkle proofs has been implemented as part of CosmJS by Ethan Frey, Will Clark and Simon Warta between June and August 2020.

In order to make this integration possible, a Cosmos SDK client that connects to Tendermint directly had to be implemented. This is available as a separate package @cosmjs/tendermint-rpc to be usable independent of a certain blockchain.

Building on top of Tendermint, there is a new package @cosmjs/stargate for connecting to Cosmos SDK 0.40+ blockchains. This package contains a high level StargateClient using a QueryClient.

QueryClient is the core of the query work. It only contains two methods queryUnverified and queryVerified but can be extended with module-specific queries. queryUnverified submits a gRPC query and returns a result. Since this includes data processing, such queries cannot be verified. queryVerified accessed Tendermit state directly and allows us to verify light client proofs provided by Tendermint using the ICS23 implementation by Confio.

The extension system for QueryClient works very similar to the one in @cosmjs/launchpad. You create a client with all the extensions you need, and have them available in a type safe way:

const tmClient = await TendermintClient.connect(endpoint);
const queryClient = QueryClient.withExtensions(
  tmClient,
  setupAuthExtension,
  setupBankExtension,
  setupIbcExtension
);

// Examples verified queries
const account = await queryClient.auth.account(searchAddress);
const balance = await queryClient.bank.balance(address, searchDenom);

// Examples unverified queries
const balances = await queryClient.bank.unverified.allBalances(address);
const channels = await queryClient.ibc.unverified.channels();

Extensions are implemented using auto-generated code from the Cosmos SDK .proto schemas. This makes the setup robust and maintainable. An example for an extension that shows one verified query and multiple gPRC queries is BankExtension.

Code generation from .proto files is powered by protobuf.js and provides a runtime implementation in JavaScript as well as TypeScript type definitions. The process works as follows:

The provable (raw) queries need to be manually writen after looking at the relevant Cosmos SDK implementations. We have done the following provable queries (which assert there is a proof to match the result to the AppHash in the header of height H+1):

The following work was done along with the milestone:

  • Support the Cosmos SDK team with the definition of the protobuf based signing mechanism (primarily ADR 020 and ADR 027)
  • Testing and bug reporting for the development version of the demo application simapp
  • Creating the transaction signing library @cosmjs/proto-signing that handles common Cosmos SDK messages types as well as custom message types using an class decorator system
  • Basic read and write client functionality for Stargate: getHeight, getBlock, getChainId, broadcastTx, searchTx