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

Fixes: REVERT counts code storage gas cost while shouldn't #1270

Merged
merged 1 commit into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
28 changes: 18 additions & 10 deletions ethereumj-core/src/main/java/org/ethereum/vm/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down