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

Handle invalid snap getTrieNode requests with empty paths gracefully #7221

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading