From 9c656b71569c94210f4628484e5e8657bba54a4b Mon Sep 17 00:00:00 2001 From: Dmitrii Shmatko Date: Sat, 30 Mar 2019 21:24:02 +0300 Subject: [PATCH] Fixes: REVERT counts code storage gas cost while shouldn't --- .../org/ethereum/core/BlockchainImpl.java | 4 ++- .../java/org/ethereum/vm/program/Program.java | 28 ++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java b/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java index c5a043924c..4307db99a6 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java @@ -562,7 +562,9 @@ public synchronized BlockSummary add(Repository repo, final Block block) { public synchronized BlockSummary addImpl(Repository repo, final Block block) { if (exitOn < block.getNumber()) { - System.out.print("Exiting after block.number: " + bestBlock.getNumber()); + String msg = String.format("Exiting after block.number: %d", bestBlock.getNumber()); + logger.info(msg); + System.out.println(msg); dbFlushManager.flushSync(); System.exit(-1); } diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/program/Program.java b/ethereumj-core/src/main/java/org/ethereum/vm/program/Program.java index 659caf9af5..18713fbf21 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/program/Program.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/program/Program.java @@ -552,20 +552,28 @@ private void createContractImpl(DataWord value, byte[] programCode, byte[] newAd byte[] code = result.getHReturn(); long storageCost = getLength(code) * getBlockchainConfig().getGasCost().getCREATE_DATA(); - long afterSpend = programInvoke.getGas().longValue() - storageCost - result.getGasUsed(); - if (afterSpend < 0) { - if (!blockchainConfig.getConstants().createEmptyContractOnOOG()) { + if (result.isRevert()) { + long afterSpend = programInvoke.getGas().longValue() - result.getGasUsed(); + if (afterSpend < 0) { result.setException(Program.Exception.notEnoughSpendingGas("No gas to return just created contract", storageCost, this)); + } + } else { + long afterSpend = programInvoke.getGas().longValue() - result.getGasUsed() - storageCost; + if (afterSpend < 0) { + if (!blockchainConfig.getConstants().createEmptyContractOnOOG()) { + result.setException(Program.Exception.notEnoughSpendingGas("No gas to return just created contract", + storageCost, this)); + } else { + track.saveCode(newAddress, EMPTY_BYTE_ARRAY); + } + } else if (getLength(code) > blockchainConfig.getConstants().getMAX_CONTRACT_SZIE()) { + result.setException(Program.Exception.notEnoughSpendingGas("Contract size too large: " + getLength(result.getHReturn()), + storageCost, this)); } else { - track.saveCode(newAddress, EMPTY_BYTE_ARRAY); + result.spendGas(storageCost); + track.saveCode(newAddress, code); } - } else if (getLength(code) > blockchainConfig.getConstants().getMAX_CONTRACT_SZIE()) { - result.setException(Program.Exception.notEnoughSpendingGas("Contract size too large: " + getLength(result.getHReturn()), - storageCost, this)); - } else if (!result.isRevert()){ - result.spendGas(storageCost); - track.saveCode(newAddress, code); } getResult().merge(result);