mirror of
https://github.com/status-im/ethereumj-personal.git
synced 2025-02-11 11:16:28 +00:00
Move protection to beginning of contract creation to not spend gas
This commit is contained in:
parent
7c4f749835
commit
d6a2714c12
@ -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);
|
||||
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user