Skip to content

Commit

Permalink
Prague Devnet5 - EIP2935 - Fix edge case when the contract is deploye…
Browse files Browse the repository at this point in the history
…d after the fork (#8211)

Signed-off-by: Gabriel-Trintinalia <[email protected]>
  • Loading branch information
Gabriel-Trintinalia authored Jan 31, 2025
1 parent 68665db commit e984126
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ public void processBlockHashes(
super.processBlockHashes(mutableWorldState, currentBlockHeader);

WorldUpdater worldUpdater = mutableWorldState.updater();
final MutableAccount historyStorageAccount = worldUpdater.getOrCreate(historyStorageAddress);
final MutableAccount historyStorageAccount = worldUpdater.getAccount(historyStorageAddress);

if (currentBlockHeader.getNumber() > 0) {
if (historyStorageAccount != null
&& historyStorageAccount.getNonce() > 0
&& currentBlockHeader.getNumber() > 0) {
storeParentHash(historyStorageAccount, currentBlockHeader);
}
worldUpdater.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ void setUp() {
mutableWorldState = mock(MutableWorldState.class);
worldUpdater = mock(WorldUpdater.class);
account = mock(MutableAccount.class);
when(account.getNonce()).thenReturn(1L);
when(mutableWorldState.updater()).thenReturn(worldUpdater);
when(worldUpdater.getOrCreate(PragueBlockHashProcessor.HISTORY_STORAGE_ADDRESS))
when(worldUpdater.getAccount(PragueBlockHashProcessor.HISTORY_STORAGE_ADDRESS))
.thenReturn(account);
}

Expand All @@ -72,7 +73,7 @@ void shouldNotStoreBlockHashForGenesisBlock() {
mockAncestorHeaders(currentBlockHeader, 0);

processor.processBlockHashes(mutableWorldState, currentBlockHeader);
verifyNoInteractions(account);
verify(account, times(0)).setStorageValue(any(), any());
}

@Test
Expand All @@ -89,6 +90,20 @@ void shouldStoreAncestorBlockHashesAtForkCorrectlyParentIsGenesis() {
verifyAccount(0, historicalWindow);
}

@Test
void shouldNotStoreBlockHashIfContractIsNotDeployed() {
when(worldUpdater.getAccount(PragueBlockHashProcessor.HISTORY_STORAGE_ADDRESS))
.thenReturn(null);

long currentBlock = 1;
processor = new PragueBlockHashProcessor();
BlockHeader currentBlockHeader = mockBlockHeader(currentBlock);
mockAncestorHeaders(currentBlockHeader, 0);

processor.processBlockHashes(mutableWorldState, currentBlockHeader);
verifyNoInteractions(account);
}

@Test
void shouldWriteGenesisHashAtSlot0() {
processor = new PragueBlockHashProcessor();
Expand Down

0 comments on commit e984126

Please sign in to comment.