Move protection to beginning of contract creation to not spend gas

This commit is contained in:
Faiz Khan 2015-02-03 12:32:15 -06:00
parent 7c4f749835
commit d6a2714c12
2 changed files with 8 additions and 9 deletions

View File

@ -322,10 +322,17 @@ public class Program {
return;
}
byte[] senderAddress = this.getOwnerAddress().getLast20Bytes();
BigInteger endowment = value.value();
BigInteger senderBalance = result.getRepository().getBalance(senderAddress);
if (senderBalance.compareTo(endowment) < 0) {
stackPushZero();
return;
}
// [1] FETCH THE CODE FROM THE MEMORY
byte[] programCode = memoryChunk(memStart, memSize).array();
byte[] senderAddress = this.getOwnerAddress().getLast20Bytes();
if (logger.isInfoEnabled())
logger.info("creating a new contract inside contract run: [{}]", Hex.toHexString(senderAddress));
@ -346,12 +353,6 @@ public class Program {
}
// [4] TRANSFER THE BALANCE
BigInteger endowment = value.value();
BigInteger senderBalance = result.getRepository().getBalance(senderAddress);
if (senderBalance.compareTo(endowment) < 0) {
stackPushZero();
return;
}
result.getRepository().addBalance(senderAddress, endowment.negate());
BigInteger newBalance = result.getRepository().addBalance(newAddress, endowment);

View File

@ -44,8 +44,6 @@ public class GitHubStateTest {
public void stInitCodeTest() throws ParseException { // [V]
Set<String> excluded = new HashSet<>();
excluded.add("CallContractToCreateContractOOG");
excluded.add("CallContractToCreateContractNoCash");
excluded.add("CallContractToCreateContractWhichWouldCreateContractInInitCode");
String json = JSONReader.loadJSON("StateTests/stInitCodeTest.json");