Skip to content

Commit

Permalink
add checks in StackTrie to ensure lastKey() is safe to use
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <[email protected]>
  • Loading branch information
garyschulte committed Dec 14, 2023
1 parent 3bb5f1a commit e7f96fe
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class Hash extends DelegatingBytes32 {
/** The constant ZERO. */
public static final Hash ZERO = new Hash(Bytes32.ZERO);

/** Last hash */
public static final Hash LAST = new Hash(Bytes32.fromHexString("F".repeat(64)));

/**
* Hash of an RLP encoded trie hash with no content, or
* "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void commit(final FlatDatabaseUpdater flatDatabaseUpdater, final NodeUpda
Function.identity(),
Function.identity(),
startKeyHash,
keys.lastKey(),
keys.size() > 0 ? keys.lastKey() : Hash.LAST,
true);

final MerkleTrie<Bytes, Bytes> trie =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

@ExtendWith(MockitoExtension.class)
public class StorageRangeDataRequestTest {
private static final Hash HASH_LAST = Hash.fromHexString("F".repeat(64));

@Mock WorldStateStorage storage;
WorldStateProofProvider worldstateProofProvider = new WorldStateProofProvider(storage);
Expand All @@ -28,7 +27,7 @@ public void assertEmptySlotsWithProofOfExclusionCompletes() {

var storageRangeRequest =
new StorageRangeDataRequest(
Hash.EMPTY_TRIE_HASH, Bytes32.ZERO, Hash.EMPTY_TRIE_HASH, Bytes32.ZERO, HASH_LAST);
Hash.EMPTY_TRIE_HASH, Bytes32.ZERO, Hash.EMPTY_TRIE_HASH, Bytes32.ZERO, Hash.LAST);

var proofs = new ArrayDeque<Bytes>();
proofs.add(0, Hash.EMPTY_TRIE_HASH);
Expand All @@ -44,7 +43,7 @@ public void assertEmptySlotsWithProofOfExclusionCompletes() {
public void assertEmptySlotsWithInvalidProofCompletes() {
var storageRangeRequest =
new StorageRangeDataRequest(
Hash.EMPTY_TRIE_HASH, Bytes32.ZERO, Hash.EMPTY_TRIE_HASH, Bytes32.ZERO, HASH_LAST);
Hash.EMPTY_TRIE_HASH, Bytes32.ZERO, Hash.EMPTY_TRIE_HASH, Bytes32.ZERO, Hash.LAST);

var proofs = new ArrayDeque<Bytes>();
proofs.add(0, Hash.ZERO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class BlockHashOperationTest {

@Test
void shouldReturnZeroWhenArgIsBiggerThanALong() {
assertBlockHash(
Bytes32.fromHexString("F".repeat(64)), Bytes32.ZERO, 100, n -> Hash.EMPTY_LIST_HASH);
assertBlockHash(Hash.LAST, Bytes32.ZERO, 100, n -> Hash.EMPTY_LIST_HASH);
}

@Test
Expand Down

0 comments on commit e7f96fe

Please sign in to comment.