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 c99fed52..ea40232c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/Program.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/Program.java @@ -407,14 +407,14 @@ public class Program { // actual gas subtract this.spendGas(msg.getGas().longValue(), "internal call"); - + Repository trackRepository = result.getRepository().getTrack(); trackRepository.startTracking(); ProgramInvoke programInvoke = ProgramInvokeFactory.createProgramInvoke( this, new DataWord(contextAddress), msg.getEndowment(), msg.getGas(), contextBalance, data, trackRepository); - + ProgramResult result = null; if (programCode != null && programCode.length != 0) { @@ -811,11 +811,13 @@ public class Program { } @SuppressWarnings("serial") - public class OutOfGasException extends RuntimeException { - } + public class OutOfGasException extends RuntimeException {} @SuppressWarnings("serial") public class IllegalOperationException extends RuntimeException {} + + @SuppressWarnings("serial") + public class BadJumpDestinationException extends RuntimeException {} @SuppressWarnings("serial") public class StackTooSmallException extends RuntimeException { @@ -829,5 +831,5 @@ public class Program { public PcOverflowException(String message) { super(message); } - } + } } \ No newline at end of file diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/ProgramInvokeFactory.java b/ethereumj-core/src/main/java/org/ethereum/vm/ProgramInvokeFactory.java index 60999a0c..2cc552ab 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/ProgramInvokeFactory.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/ProgramInvokeFactory.java @@ -123,7 +123,6 @@ public class ProgramInvokeFactory { return programInvoke; } - /** * This invocation created for contract call contract */ @@ -150,8 +149,6 @@ public class ProgramInvokeFactory { DataWord gasLimit = program.getGaslimit(); if (logger.isInfoEnabled()) { - - logger.info("Internal call: \n" + "address={}\n" + "origin={}\n" + @@ -174,7 +171,7 @@ public class ProgramInvokeFactory { gasPrice.longValue(), gas.longValue(), callValue.longValue(), - data == null ? "null": Hex.toHexString(data), + data == null ? "": Hex.toHexString(data), Hex.toHexString(lastHash.getData()), Hex.toHexString(coinbase.getLast20Bytes()), timestamp.longValue(), @@ -184,9 +181,8 @@ public class ProgramInvokeFactory { } int newCallDepth = program.invokeData.getCallDeep() + 1; - if (newCallDepth >= MAX_CREATE_CALL_DEPTH) { + if (newCallDepth > MAX_CREATE_CALL_DEPTH) throw program.new OutOfGasException(); - } return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue, data, lastHash, coinbase, timestamp, number, difficulty, gasLimit, diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java index c4fa9bde..966acfe4 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java @@ -81,11 +81,11 @@ public class VM { try { OpCode op = OpCode.code(program.getCurrentOp()); - if (op == null) throw program.new IllegalOperationException(); - + program.setLastOp(op.val()); + program.stackRequire(op.require()); long oldMemSize = program.getMemSize(); BigInteger newMemSize = BigInteger.ZERO; @@ -96,9 +96,7 @@ public class VM { long gasCost = GasCost.STEP; long gasBefore = program.getGas().longValue(); int stepBefore = program.getPC(); - - program.stackRequire(op.require()); - + // Calculate fees and spend gas switch (op) { case STOP: case SUICIDE: @@ -763,7 +761,7 @@ public class VM { DataWord pos = program.stackPop(); int nextPC = pos.intValue(); // possible overflow if (nextPC != 0 && program.getOp(nextPC-1) != OpCode.JUMPDEST.val()) - throw new BadJumpDestinationException(); + throw program.new BadJumpDestinationException(); if (logger.isInfoEnabled()) hint = "~> " + nextPC; @@ -778,7 +776,7 @@ public class VM { if (!cond.isZero()) { int nextPC = pos.intValue(); // possible overflow if (nextPC != 0 && program.getOp(nextPC-1) != OpCode.JUMPDEST.val()) - throw new BadJumpDestinationException(); + throw program.new BadJumpDestinationException(); if (logger.isInfoEnabled()) hint = "~> " + nextPC; @@ -875,7 +873,7 @@ public class VM { op.equals(CALL) ? MsgType.CALL : MsgType.STATELESS, gas, codeAddress, value, inDataOffs, inDataSize, outDataOffs, outDataSize); - program.callToAddress(msg); + program.callToAddress(msg); program.step(); } break; @@ -1019,9 +1017,5 @@ public class VM { level, contract, vmCounter, internalSteps, op, gasBefore, gasCost, memWords); } - } - - @SuppressWarnings("serial") - public class BadJumpDestinationException extends RuntimeException {} - + } } \ No newline at end of file diff --git a/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java b/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java index 57441538..4893b3a3 100644 --- a/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java @@ -3,7 +3,7 @@ package org.ethereum.vm; import org.ethereum.facade.Repository; import org.ethereum.util.ByteUtil; import org.ethereum.vm.Program.StackTooSmallException; -import org.ethereum.vm.VM.BadJumpDestinationException; +import org.ethereum.vm.Program.BadJumpDestinationException; import org.junit.After; import org.junit.Before; import org.junit.FixMethodOrder;