Fix new call level

When the current level is 1024, next CALL/CREATE
will do simple return with zero value pushed to the
 stack
This commit is contained in:
Roman Mandeleil 2015-01-06 20:40:05 +02:00
parent 832c24014d
commit 02be38a85d
3 changed files with 20 additions and 11 deletions

View File

@ -44,6 +44,14 @@ public class Program {
private static final Logger logger = LoggerFactory.getLogger("VM");
private static final Logger gasLogger = LoggerFactory.getLogger("gas");
/**
* This attribute defines the number of recursive calls allowed in the EVM
* Note: For the JVM to reach this level without a StackOverflow exception,
* ethereumj may need to be started with a JVM argument to increase
* the stack size. For example: -Xss10m
*/
private static final int MAX_DEPTH = 1024;
ProgramInvokeFactory programInvokeFactory = new ProgramInvokeFactoryImpl();
private int invokeHash;
@ -295,6 +303,11 @@ public class Program {
public void createContract(DataWord value, DataWord memStart, DataWord memSize) {
if (invokeData.getCallDeep() == MAX_DEPTH){
stackPushZero();
return;
}
// [1] FETCH THE CODE FROM THE MEMORY
byte[] programCode = memoryChunk(memStart, memSize).array();
@ -403,6 +416,11 @@ public class Program {
*/
public void callToAddress(MessageCall msg) {
if (invokeData.getCallDeep() == MAX_DEPTH){
stackPushZero();
return;
}
byte[] data = memoryChunk(msg.getInDataOffs(), msg.getInDataSize()).array();
// FETCH THE SAVED STORAGE

View File

@ -28,13 +28,6 @@ public class ProgramInvokeFactoryImpl implements ProgramInvokeFactory {
@Autowired
private Blockchain blockchain;
/**
* This attribute defines the number of recursive calls allowed in the EVM
* Note: For the JVM to reach this level without a StackOverflow exception,
* ethereumj may need to be started with a JVM argument to increase
* the stack size. For example: -Xss10m
*/
private static final int MAX_DEPTH = 1024;
// Invocation by the wire tx
@Override
@ -189,9 +182,6 @@ public class ProgramInvokeFactoryImpl implements ProgramInvokeFactory {
gasLimit.longValue());
}
if (program.invokeData.getCallDeep() >= MAX_DEPTH)
throw program.new OutOfGasException();
return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue,
data, lastHash, coinbase, timestamp, number, difficulty, gasLimit,
repository, program.invokeData.getCallDeep() + 1);

View File

@ -68,6 +68,7 @@ public class VM {
private static BigInteger MAX_GAS = BigInteger.valueOf(Long.MAX_VALUE);
/* Keeps track of the number of steps performed in this VM */
private int vmCounter = 0;