diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java index c2fa186489c..bfccede676d 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java @@ -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 diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java index c15056d66cc..d7d3fc52751 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java @@ -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 trieNodes = trieNodeRequest.nodes(false); + assertThat(trieNodes.isEmpty()).isTrue(); + } + @Test public void assertAccountTrieLimitRequest() { insertTestAccounts(acct1, acct2, acct3, acct4);