Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Fix NPE in DAO rescue code
Browse files Browse the repository at this point in the history
(cherry picked from commit 04747ac)
  • Loading branch information
Nashatyrev committed Jun 28, 2016
1 parent e854dd5 commit 896bd3b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class HomesteadDAOConfig extends HomesteadConfig {

public static final long DAO_RESCUE_BLOCK = 1_800_000;
public static final long DAO_RESCUE_BLOCK = 1_787_300;
public static final long DAO_RESCUE_GAS_LIMIT_TRIGGER = 4_000_000;
public static final byte[] DAO_CODE_HASH = Hex.decode("6a5d24750f78441e56fec050dc52fe8e911976485b7472faac7464a176a67caa");
public static final byte[][] WHITELISTED_RECIPIENTS = new byte[][] {
Expand Down Expand Up @@ -87,7 +87,10 @@ public String validateTransactionChanges(BlockStore blockStore, Block curBlock,
if (shouldRescueDAO(blockStore, curBlock)) {
Set<ByteArrayWrapper> changedAddresses = repositoryTrack.getFullAddressSet();
for (ByteArrayWrapper address : changedAddresses) {
AccountState accountState = repositoryTrack.getOriginRepository().getAccountState(address.getData());
AccountState accountState = repositoryTrack.getAccountState(address.getData());
if (accountState == null) {
return null;
}
byte[] codeHash = accountState.getCodeHash();
if (codeHash != null && FastByteComparisons.compareTo(daoCodeHash, 0, 32, codeHash, 0, 32) == 0) {
BigInteger newBalance = repositoryTrack.getBalance(address.getData());
Expand Down
24 changes: 24 additions & 0 deletions ethereumj-core/src/test/java/org/ethereum/core/DAORescueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.ethereum.config.blockchain.HomesteadDAOConfig;
import org.ethereum.config.net.AbstractNetConfig;
import org.ethereum.config.net.MainNetConfig;
import org.ethereum.crypto.ECKey;
import org.ethereum.util.blockchain.SolidityContract;
import org.ethereum.util.blockchain.StandaloneBlockchain;
import org.ethereum.vm.program.Program;
Expand Down Expand Up @@ -46,6 +47,11 @@ public BigInteger getMINIMUM_DIFFICULTY() {
"function saveDao(address daoAddr) {" +
" TestDAO(daoAddr).withdraw();" +
"}" +
"}" +
"contract Suicide {" +
"function selfDestroy() {" +
" suicide(msg.sender);" +
"}" +
"}";

@BeforeClass
Expand Down Expand Up @@ -126,6 +132,24 @@ public void testForkAgreed() {
Assert.assertEquals(BigInteger.valueOf(balance),
bc.getBlockchain().getRepository().getBalance(dao.getAddress()));
}

ECKey rndReceiver = new ECKey();
bc.sendEther(rndReceiver.getAddress(), BigInteger.valueOf(10000));
bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(10000),
bc.getBlockchain().getRepository().getBalance(rndReceiver.getAddress()));

SolidityContract suicide = bc.submitNewContract(daoEmulator, "Suicide");
bc.createBlock();
bc.sendEther(suicide.getAddress(), BigInteger.valueOf(10000));
bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(10000),
bc.getBlockchain().getRepository().getBalance(suicide.getAddress()));
suicide.callFunction("selfDestroy");
bc.createBlock();
Assert.assertEquals(BigInteger.ZERO,
bc.getBlockchain().getRepository().getBalance(suicide.getAddress()));

}

@Test
Expand Down

0 comments on commit 896bd3b

Please sign in to comment.