Skip to content

Fix general merkle keypath to start w/ last op's key#2733

Merged
ebuchman merged 3 commits intodevelopfrom
jae/generalmerklefix
Oct 31, 2018
Merged

Fix general merkle keypath to start w/ last op's key#2733
ebuchman merged 3 commits intodevelopfrom
jae/generalmerklefix

Conversation

@jaekwon
Copy link
Contributor

@jaekwon jaekwon commented Oct 31, 2018

  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG_PENDING.md

General Merkle ProofOperator was iterating over the keys in the wrong order. The keypath should start with the last operation to run (e.g. the top-level root hash operation), not end with it.

NOTE: This is related to https://github.com/cosmos/cosmos-sdk/pull/2633/files

@codecov-io
Copy link

codecov-io commented Oct 31, 2018

Codecov Report

❗ No coverage uploaded for pull request base (develop@a530352). Click here to learn what that means.
The diff coverage is 100%.

@@            Coverage Diff             @@
##             develop    #2733   +/-   ##
==========================================
  Coverage           ?   62.32%           
==========================================
  Files              ?      211           
  Lines              ?    17055           
  Branches           ?        0           
==========================================
  Hits               ?    10630           
  Misses             ?     5552           
  Partials           ?      873
Impacted Files Coverage Δ
crypto/merkle/proof.go 38.18% <100%> (ø)

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

🍵

if len(key) != 0 {
if !bytes.Equal(keys[0], key) {
return cmn.NewError("Key mismatch on operation #%d: expected %+v but %+v", i, []byte(keys[0]), []byte(key))
lastKey := keys[len(keys)-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

should we check that len(keys) > 0 especially when we're modifying them later keys = keys[:len(keys)-1]

Copy link
Contributor

Choose a reason for hiding this comment

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

KeyPathToKeys ensures that the keys aren't empty, unless there's an error

@ebuchman
Copy link
Contributor

if len(key) != 0 {
if !bytes.Equal(keys[0], key) {
return cmn.NewError("Key mismatch on operation #%d: expected %+v but %+v", i, []byte(keys[0]), []byte(key))
lastKey := keys[len(keys)-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

KeyPathToKeys ensures that the keys aren't empty, unless there's an error

op3 := NewDominoOp("", "INPUT3", "INPUT4")
op4 := NewDominoOp("KEY4", "INPUT4", "OUTPUT4")

// Good
Copy link
Contributor

Choose a reason for hiding this comment

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

would make a good table driven test

@ebuchman
Copy link
Contributor

Oh nvm, we haven't even written the keypath spec ...

@ebuchman ebuchman merged commit 1660e30 into develop Oct 31, 2018
@ebuchman ebuchman deleted the jae/generalmerklefix branch October 31, 2018 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants