Skip to content

Commit

Permalink
Remove redundant checks in gas calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalinin committed Oct 4, 2018
1 parent b2ba99a commit fe10be2
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions ethereumj-core/src/main/java/org/ethereum/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,8 @@ else if (!currentValue.isZero() && newValue.isZero()) {
break;
case SHA3:
gasCost = gasCosts.getSHA3() + calcMemGas(gasCosts, oldMemSize, memNeeded(stack.peek(), stack.get(stack.size() - 2)), 0);
long size = stack.get(stack.size() - 2).longValueSafe();
if (size == Long.MAX_VALUE) {
throw Program.Exception.gasOverflow(BigInteger.valueOf(size), BigInteger.valueOf(Long.MAX_VALUE));
}
long chunkUsed = getSizeInWords(size);
DataWord size = stack.get(stack.size() - 2);
long chunkUsed = getSizeInWords(size.longValueSafe());
gasCost += chunkUsed * gasCosts.getSHA3_WORD();
break;
case CALLDATACOPY:
Expand Down Expand Up @@ -398,14 +395,10 @@ else if (!currentValue.isZero() && newValue.isZero()) {
memNeeded(stack.get(stack.size() - 2), stack.get(stack.size() - 3)), 0);
break;
case CREATE2:
gasCost = gasCosts.getCREATE() + calcMemGas(gasCosts, oldMemSize,
memNeeded(stack.get(stack.size() - 2), stack.get(stack.size() - 3)), 0);
long codeSize = stack.get(stack.size() - 3).longValueSafe();
if (codeSize == Long.MAX_VALUE) {
throw Program.Exception.gasOverflow(BigInteger.valueOf(codeSize), BigInteger.valueOf(Long.MAX_VALUE));
}
gasCost += getSizeInWords(codeSize) * gasCosts.getSHA3_WORD();

DataWord codeSize = stack.get(stack.size() - 3);
gasCost = gasCosts.getCREATE() +
calcMemGas(gasCosts, oldMemSize, memNeeded(stack.get(stack.size() - 2), codeSize), 0) +
getSizeInWords(codeSize.longValueSafe()) * gasCosts.getSHA3_WORD();
break;
case LOG0:
case LOG1:
Expand Down

0 comments on commit fe10be2

Please sign in to comment.