Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ADR-040: ICS-23 proofs for SMT store #10015

Merged
merged 6 commits into from
Feb 22, 2022

Conversation

roysc
Copy link
Contributor

@roysc roysc commented Aug 26, 2021

Description

Implements ICS-23 conformant proofs for the SMT-based KV store and defines the proof spec as part of ADR-040.

Closes: vulcanize#8


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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules - n/a
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • 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 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)

@roysc roysc marked this pull request as draft August 26, 2021 17:03
@roysc roysc force-pushed the roysc/adr-040-ics23 branch 3 times, most recently from 6faf915 to d5eea91 Compare August 26, 2021 17:27
@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Oct 11, 2021
@roysc
Copy link
Contributor Author

roysc commented Oct 13, 2021

Commenting so the bot won't close - this builds on #9892 and will be un-drafted when that's merged

@github-actions github-actions bot removed the stale label Oct 14, 2021
@roysc roysc force-pushed the roysc/adr-040-ics23 branch 2 times, most recently from 83ddee6 to 37559e4 Compare October 28, 2021 16:04
@codecov
Copy link

codecov bot commented Oct 28, 2021

Codecov Report

Merging #10015 (998a94f) into master (9ce0844) will decrease coverage by 0.95%.
The diff coverage is 62.65%.

❗ Current head 998a94f differs from pull request most recent head 0ae8bd4. Consider uploading reports for the commit 0ae8bd4 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10015      +/-   ##
==========================================
- Coverage   65.85%   64.89%   -0.96%     
==========================================
  Files         659      616      -43     
  Lines       67511    59315    -8196     
==========================================
- Hits        44456    38493    -5963     
+ Misses      20469    18587    -1882     
+ Partials     2586     2235     -351     
Impacted Files Coverage Δ
db/memdb/db.go 72.72% <ø> (ø)
store/rootmulti/proof.go 100.00% <ø> (+26.66%) ⬆️
store/types/commit_info.go 0.00% <0.00%> (ø)
store/types/proof.go 0.00% <0.00%> (ø)
store/types/store.go 66.66% <ø> (+1.96%) ⬆️
store/v2/dbadapter/store.go 0.00% <0.00%> (-97.15%) ⬇️
db/prefix/prefix.go 42.20% <26.08%> (ø)
store/v2/root/view_store.go 52.63% <52.63%> (ø)
store/v2/root/proof.go 58.62% <58.62%> (ø)
store/v2/smt/ics23.go 62.13% <62.13%> (ø)
... and 238 more

@roysc roysc force-pushed the roysc/adr-040-ics23 branch 2 times, most recently from eaddf6b to d878af5 Compare November 10, 2021 09:02
@roysc roysc marked this pull request as ready for review November 10, 2021 09:03
@roysc roysc mentioned this pull request Nov 10, 2021
38 tasks
@roysc roysc force-pushed the roysc/adr-040-ics23 branch from d94d770 to e37f769 Compare November 18, 2021 15:58
@roysc roysc force-pushed the roysc/adr-040-ics23 branch from e37f769 to ddf9a63 Compare November 23, 2021 04:48
@roysc
Copy link
Contributor Author

roysc commented Nov 23, 2021

This depends on the SmtSpec introduced here cosmos/ics23#57, need to update go.mod once that is merged & tagged

@roysc roysc force-pushed the roysc/adr-040-ics23 branch from ddf9a63 to 975027e Compare November 23, 2021 04:54
@roysc
Copy link
Contributor Author

roysc commented Nov 23, 2021

There's an unfortunate consequence of how the SMT functions which may or may not be an issue here.

The SMT hashes keys to produce a path, so when a proof is created, the resulting CommitmentProof contains a Key field equal to the hash of the key used to query the store, rather than the key itself. This could be counterintuitive and less ergonomic for users.

req := abci.RequestQuery{
	Path:  "/store_name/key",
	Data:  []byte("key_name"),
	Prove: true,
}
res := store.Query(req)
// res.Key == req.Data
// but, res.ProofOps.Ops[0].Key == sha256(res.Key)

It doesn't seem like there should be major consequences for this as long as code that deals with proofs doesn't expect these fields to match. If nothing outside the SDK looks at them, it should be fine.

But if we do want to change it, it can't be changed within the SMT proof spec as is. There is LeafSpec.PrehashKey, but this just indicates hashing of the key path within the leaf node. In this case, the key is hashed to create the key path, so I think a proper solution would be to add a PrehashKey field to ProofSpec (defaulting to NO_HASH of course) to reflect this behavior.

@roysc roysc force-pushed the roysc/adr-040-ics23 branch from d9dcdb9 to eaf2fa0 Compare November 24, 2021 08:37
@roysc roysc force-pushed the roysc/adr-040-ics23 branch from ea5cc99 to 998a94f Compare November 26, 2021 12:16
@roysc
Copy link
Contributor Author

roysc commented Dec 22, 2021

Update: this depends on cosmos/ics23#61 - marking draft until that's merged

@roysc roysc marked this pull request as draft December 22, 2021 14:59
@roysc roysc force-pushed the roysc/adr-040-ics23 branch from 998a94f to caa8a54 Compare February 2, 2022 09:53
@roysc roysc marked this pull request as ready for review February 2, 2022 09:53
@roysc
Copy link
Contributor Author

roysc commented Feb 2, 2022

All the dependencies in https://github.com/confio/ics23 have been merged, so this is ready for review (it functions independently of #10174 which is also in-flight).

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left one comment to address before merge - one error check is missing.

@@ -111,8 +111,8 @@ func createExistenceProof(data map[string][]byte, key []byte) (*ics23.ExistenceP
return nil, fmt.Errorf("cannot make existence proof if key is not in map")
}

_, ics23, _ := sdkmaps.ProofsFromMap(data)
proof := ics23[string(key)]
_, proofs, _ := sdkmaps.ProofsFromMap(data)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lat return value is an error - we must check it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's actually the list of keys in the map:

func ProofsFromMap(m map[string][]byte) ([]byte, map[string]*tmcrypto.Proof, []string) {

@robert-zaremba robert-zaremba added the A:automerge Automatically merge PR once all prerequisites pass. label Feb 21, 2022
@robert-zaremba
Copy link
Collaborator

does this depends on the latest / not released changes in ibc repo?

@roysc
Copy link
Contributor Author

roysc commented Feb 21, 2022

No changes needed for ibc. But ics23 can bump to go/v0.7.0-rc, I'll update it

@roysc roysc force-pushed the roysc/adr-040-ics23 branch from caa8a54 to 127e902 Compare February 21, 2022 15:58
@mergify mergify bot merged commit e66b8ef into cosmos:master Feb 22, 2022
@roysc roysc deleted the roysc/adr-040-ics23 branch February 22, 2022 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:Store
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Epic 6: ics23 support
3 participants