cosmos-sdk/store/tools/ics23/smt
Roy Crihfield 56af6a7fbb
feat: Add ics23 proof tools: `ics23-{iavl,tendermint,smt}` (#10802)
Moves the separate repos for ICS23 proof tooling into `store/tools`

I've set `github.com/confio/ics23/go` to version 0.7.0 in anticipation of https://github.com/confio/ics23/pull/61 being merged, as it's a dependency for SMT proofs, so this shouldn't be merged until that version exists.

Closes: https://github.com/cosmos/cosmos-sdk/issues/10801



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2022-02-22 11:39:08 +00:00
..
cmd/testgen-smt feat: Add ics23 proof tools: `ics23-{iavl,tendermint,smt}` (#10802) 2022-02-22 11:39:08 +00:00
helpers feat: Add ics23 proof tools: `ics23-{iavl,tendermint,smt}` (#10802) 2022-02-22 11:39:08 +00:00
Makefile feat: Add ics23 proof tools: `ics23-{iavl,tendermint,smt}` (#10802) 2022-02-22 11:39:08 +00:00
README.md feat: Add ics23 proof tools: `ics23-{iavl,tendermint,smt}` (#10802) 2022-02-22 11:39:08 +00:00
create.go feat: Add ics23 proof tools: `ics23-{iavl,tendermint,smt}` (#10802) 2022-02-22 11:39:08 +00:00
create_test.go feat: Add ics23 proof tools: `ics23-{iavl,tendermint,smt}` (#10802) 2022-02-22 11:39:08 +00:00

README.md

Proofs SMT

This project demonstrates the generation and validation of ICS-23 proofs for a sparse Merkle tree (SMT) as implemented by Celestia.

Library usage

It exposes a two main functions :

func CreateMembershipProof(tree *smt.SparseMerkleTree, key []byte) (*ics23.CommitmentProof, error) produces a CommitmentProof that the given key exists in the SMT (and contains the current value). This returns an error if the key does not exist in the tree.

func CreateNonMembershipProof(tree *smt.SparseMerkleTree, key []byte, preimages PreimageMap) (*ics23.CommitmentProof, error) produces a CommitmentProof that the given key doesn't exist in the SMT. This returns an error if the key does not exist in the tree. This relies on an auxiliary PreimageMap object which provides access to the preimages of all keys in the tree based on their (hashed) path ordering.

CLI usage

We also expose a simple script to generate test data for the confio proofs package.

go install ./cmd/testgen-smt
testgen-smt exist left 10

Will output some json data, from a randomly generated Merkle tree each time.

{
  "key": "574f516c4364415274743845444d397347484937",
  "proof": "0a9d010a2024910c64b5b74b6b72e6b9d3310a1d0bd599032e05e8abc43112d194e1a78f30121e76616c75655f666f725f574f516c4364415274743845444d3973474849371a07080118012a0100222708011201011a20b51557119b6985d54a48a4510e528d5f929f0b1c8b57914bb6cd8f9eab035d75222708011201011a20fff8248ca9e98cbb05c81612d38e74780b2c02d9c88ee628cfbdb8ca44769a63",
  "root": "f69ef3599b7f0471b61735490636608a8ff43a327b2b5a3a5528ca7f7059ffa5",
  "value": "76616c75655f666f725f574f516c4364415274743845444d397347484937"
}

"root" is the hex-encoded root hash of the Merkle tree.

"proof" is the hex-encoding of the protobuf binary encoding of a proofs.ExistenceProof object. This contains a (key, value) pair, along with all steps to reach the root hash. This provides a non-trivial test case, to ensure clients in multiple languages can verify the protobuf proofs we generate from the SMT.