Skip to content

Commit

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

Signed-off-by: Jason Frame <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
  • Loading branch information
jframe and macfarla authored Jun 24, 2024
1 parent 609eb76 commit 04eaaf9
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 04eaaf9

Please sign in to comment.