Skip to content

Commit

Permalink
Handle invalid snap getTrieNode requests with empty paths gracefully (h…
Browse files Browse the repository at this point in the history
…yperledger#7221)

Signed-off-by: Jason Frame <jason.frame@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
  • Loading branch information
2 people authored and daniellehrner committed Jul 16, 2024
1 parent 07fbe3c commit 86165b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ MessageData constructGetTrieNodesResponse(final MessageData message) {
}

} else {
// There must be at least one element in the path otherwise it is invalid
if (triePath.isEmpty()) {
LOGGER.debug("returned empty trie nodes message due to invalid path");
return EMPTY_TRIE_NODES_MESSAGE;
}

// otherwise the first element should be account hash, and subsequent paths
// are compact encoded account storage paths

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,18 @@ public void assertAccountTriePathRequest() {
assertThat(trieNodes.size()).isEqualTo(2);
}

@Test
public void assertAccountTrieRequest_invalidEmptyPath() {
insertTestAccounts(acct1);
var partialPathToAcct1 = Bytes.fromHexString("0x01"); // first nibble is 1
var trieNodeRequest =
requestTrieNodes(
storageTrie.getRootHash(), List.of(List.of(), List.of(partialPathToAcct1)));
assertThat(trieNodeRequest).isNotNull();
List<Bytes> trieNodes = trieNodeRequest.nodes(false);
assertThat(trieNodes.isEmpty()).isTrue();
}

@Test
public void assertAccountTrieLimitRequest() {
insertTestAccounts(acct1, acct2, acct3, acct4);
Expand Down

0 comments on commit 86165b8

Please sign in to comment.