Handle invalid snap getTrieNode requests with empty paths gracefully (#7221)

Signed-off-by: Jason Frame <jason.frame@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/7253/head
Jason Frame 5 months ago committed by GitHub
parent 609eb76ba0
commit 04eaaf9c24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServer.java
  2. 12
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java

@ -519,6 +519,12 @@ class SnapServer implements BesuEvents.InitialSyncCompletionListener {
}
} 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

@ -368,6 +368,18 @@ public class SnapServerTest {
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);

Loading…
Cancel
Save