Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/cosmos/ics23

Building generic merkle proof format for IBC
https://github.com/cosmos/ics23

Last synced: 2 months ago
JSON representation

Building generic merkle proof format for IBC

Lists

README

        

[![Cosmos ecosystem][cosmos-shield]][cosmos-link]

# ICS 23 [![Apache 2.0 Licensed][license-badge]][license-link]

| Language | Test Suite | Code Coverage |
| ------------------ | ------------------------------------------------- | ---------------------------------------------- |
| [Go](./go) | [![Go Test][go-test-badge]][go-test-link] | [![Go Cov][go-cov-badge]][go-cov-link] |
| [Rust](./rust) | [![Rust Test][rust-test-badge]][rust-test-link] | [![Rust Cov][rust-cov-badge]][rust-cov-link] |
| [TypeScript](./js) | [![TypeScript Test][ts-test-badge]][ts-test-link] | [![TypeScript Cov][ts-cov-badge]][ts-cov-link] |

[cosmos-link]: https://cosmos.network
[go-test-link]: https://github.com/cosmos/ics23/actions/workflows/go.yml
[go-test-badge]: https://github.com/cosmos/ics23/actions/workflows/go.yml/badge.svg?branch=master
[go-cov-link]: https://sonarcloud.io/project/configuration?id=ics23-go
[go-cov-badge]: https://sonarcloud.io/api/project_badges/measure?project=ics23-go&metric=coverage
[rust-test-link]: https://github.com/cosmos/ics23/actions/workflows/rust.yml
[rust-test-badge]: https://github.com/cosmos/ics23/actions/workflows/rust.yml/badge.svg?branch=master
[rust-cov-link]: https://codecov.io/gh/cosmos/ics23/tree/master/rust
[rust-cov-badge]: https://codecov.io/github/cosmos/ics23/branch/master/graph/badge.svg?token=xlGriS907o&flag=rust
[ts-test-link]: https://github.com/cosmos/ics23/actions/workflows/typescript.yml
[ts-test-badge]: https://github.com/cosmos/ics23/actions/workflows/typescript.yml/badge.svg?branch=master
[ts-cov-link]: https://sonarcloud.io/project/configuration?id=ics23-js
[ts-cov-badge]: https://sonarcloud.io/api/project_badges/measure?project=ics23-js&metric=coverage
[license-link]: https://github.com/cosmos/ics23/blob/master/LICENSE
[license-badge]: https://img.shields.io/badge/license-Apache2.0-blue.svg

## Proofs

This is an attempt to define a generic, cross-language, binary representation
of merkle proofs, which can be generated by many underlying merkle tree storage
implementations and validated by many client libraries over various languages.

The end goal is to provide a standard representation not only for light-client
proofs of blockchains, but more specifically for proofs that accompany IBC
(inter-blockchain communication) packets as defined in the cosmos specification.

## Feature set

The features and naming follow the [ICS23: Vector Commitments](https://github.com/cosmos/ibc/tree/master/spec/core/ics-023-vector-commitments) Specification

* Proof of Existence (key-value pair linked to root hash)
* Hold Existence Proof to db-specific spec (avoid reinterpretation of bytes to different key-value pair)
* Proof of Non-Existence (key proven not to be inside tree with given root hash)

### Future features

* Batch Proof or Range Proof (prove many keys at once, more efficiently than separate proofs)

## Organization

The top level package will provide language-agnostic documentation and protobuf specifications.
Every language should have a sub-folder, containing both protobuf generated code,
as well as client-side code for validating such proofs. The server-side code should
live alongside the various merkle tree representations (eg. not in this repository).

### Supported client languages

* [Go](./go)
* [TypeScript](./js)
* [Rust](./rust)

Anyone interested in adding support for Solidity could pick up where [#58](https://github.com/cosmos/ics23/pull/58) left off.

### Compatibility table

| ICS 023 Spec | Go | Rust |
|---------------|-------------------|---------------------|
| 2019-08-25 | 0.9.x | 0.9.x |
| 2019-08-25 | 0.10.x | 0.10.x, 0.11.x |

## Supported merkle stores

* [cosmos/iavl](https://github.com/cosmos/iavl)
* [cometbft/crypto/merkle](https://github.com/cometbft/cometbft/tree/main/crypto/merkle)
* [penumbra-zone/jmt](https://github.com/penumbra-zone/jmt)

### Unsupported

* [turbofish-org/merk](https://github.com/turbofish-org/merk)
* [go-ethereum Merkle Patricia Trie](https://github.com/ethereum/go-ethereum/blob/master/trie/trie.go)

Ethan Frey [spent quite some time](https://github.com/confio/proofs-ethereum) to wrestle out a well-defined serialization and a validation logic that didn't involve importing too much code from go-ethereum (copying parts and stripping it down to the minimum). At the end, he realized the key is only present from parsing the entire path and is quite a painstaking process, even with go code that imports rlp and has the custom patricia key encodings. After a long time reflecting, he cannot see any way to implement this that doesn't either: (A) allow the provider to forge a different key that cannot be detected by the verifier or (B) include a huge amount of custom code in the client side.

If anyone has a solution to this, please open an issue in this repository.

## Known limitations

This format is designed to support any merklized data store that encodes key-value pairs into
a node, and computes a root hash by repeatedly concatenating hashes and re-hashing them.

Notably, this requires the *key* to be present in the leaf node in order to enforce the structure properly
and prove the *key* provided matches the proof without extensive db-dependent code. Since some
tries (such as Ethereum's Patricia Trie) do not store the key in the leaf, but require precise analysis of
every step along the path in order to reconstruct the path, these are not supported. Doing so would
require a much more complex format and most likely custom code for each such database. The design goal
was to be able to add new data sources with only configuration (spec object), rather than custom code.

[cosmos-shield]: https://img.shields.io/static/v1?label=&labelColor=1B1E36&color=1B1E36&message=cosmos%20ecosystem&style=for-the-badge&logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI0LjMuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHZpZXdCb3g9IjAgMCAyNTAwIDI1MDAiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDI1MDAgMjUwMDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsOiM2RjczOTA7fQoJLnN0MXtmaWxsOiNCN0I5Qzg7fQo8L3N0eWxlPgo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNMTI1Mi42LDE1OS41Yy0xMzQuOSwwLTI0NC4zLDQ4OS40LTI0NC4zLDEwOTMuMXMxM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