diff --git a/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java b/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java index e912f073..51f12ff6 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java @@ -100,6 +100,25 @@ public class TransactionExecutor { return; } + // GET TOTAL ETHER VALUE AVAILABLE FOR TX FEE + BigInteger gasPrice = new BigInteger(1, tx.getGasPrice()); + BigInteger gasDebit = new BigInteger(1, tx.getGasLimit()).multiply(gasPrice); + logger.info("Gas price limited to [{} wei]", gasDebit.toString()); + + // Debit the actual total gas value from the sender + // the purchased gas will be available for + // the contract in the execution state, + // it can be retrieved using GAS op + BigInteger txValue = new BigInteger(1, tx.getValue()); + if (track.getBalance(senderAddress).compareTo(gasDebit.add(txValue)) == -1) { + logger.debug("No gas to start the execution: sender={}", + Hex.toHexString(senderAddress)); + + receipt.setCumulativeGas(0); + this.receipt = receipt; + return; + } + // FIND OUT THE TRANSACTION TYPE final byte[] receiverAddress; final byte[] code; @@ -122,27 +141,6 @@ public class TransactionExecutor { } } - - // GET TOTAL ETHER VALUE AVAILABLE FOR TX FEE - BigInteger gasPrice = new BigInteger(1, tx.getGasPrice()); - BigInteger gasDebit = new BigInteger(1, tx.getGasLimit()).multiply(gasPrice); - logger.info("Gas price limited to [{} wei]", gasDebit.toString()); - - // Debit the actual total gas value from the sender - // the purchased gas will be available for - // the contract in the execution state, - // it can be retrieved using GAS op - BigInteger txValue = new BigInteger(1, tx.getValue()); - if (track.getBalance(senderAddress).compareTo(gasDebit.add(txValue)) == -1) { - logger.debug("No gas to start the execution: sender={}", - Hex.toHexString(senderAddress)); - - receipt.setCumulativeGas(0); - this.receipt = receipt; - return; - } - - // THE SIMPLE VALUE/BALANCE CHANGE if (track.getBalance(senderAddress).compareTo(txValue) >= 0) { diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/Program.java b/ethereumj-core/src/main/java/org/ethereum/vm/Program.java index 84a6aa8e..68f019f8 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/Program.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/Program.java @@ -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); diff --git a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java index ef48ba55..0af27485 100644 --- a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java +++ b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java @@ -44,9 +44,6 @@ public class GitHubStateTest { public void stInitCodeTest() throws ParseException { // [V] Set excluded = new HashSet<>(); - excluded.add("NotEnoughCashContractCreation"); - excluded.add("CallContractToCreateContractOOG"); - excluded.add("CallContractToCreateContractNoCash"); excluded.add("CallContractToCreateContractWhichWouldCreateContractInInitCode"); String json = JSONReader.loadJSON("StateTests/stInitCodeTest.json");