Exception severity uniform

This commit is contained in:
nicksavers 2014-10-30 16:57:17 +01:00
parent bf8163da7a
commit 3dfb7e44f9
3 changed files with 24 additions and 38 deletions

View File

@ -114,13 +114,8 @@ public class Program {
public void setPC(int pc) {
this.pc = pc;
if (this.pc == ops.length)
if (this.pc >= ops.length)
stop();
if (this.pc > ops.length) {
stop();
throw new PcOverflowException("pc overflow pc=" + pc);
}
}
public boolean isStopped() {
@ -142,10 +137,8 @@ public class Program {
public byte[] sweep(int n) {
if (pc + n > ops.length) {
if (pc + n > ops.length)
stop();
throw new PcOverflowException("pc overflow sweep n: " + n + " pc: " + pc);
}
byte[] data = Arrays.copyOfRange(ops, pc, pc + n);
pc += n;
@ -825,11 +818,4 @@ public class Program {
super(message);
}
}
@SuppressWarnings("serial")
public class PcOverflowException extends RuntimeException {
public PcOverflowException(String message) {
super(message);
}
}
}

View File

@ -2,7 +2,6 @@ package org.ethereum.vm;
import org.ethereum.crypto.HashUtil;
import org.ethereum.db.ContractDetails;
import org.ethereum.vm.Program.OutOfGasException;
import static org.ethereum.config.SystemProperties.CONFIG;
@ -741,9 +740,9 @@ public class VM {
if (logger.isInfoEnabled())
hint = "key: " + key + " value: " + val;
if (val == null) {
if (val == null)
val = key.and(DataWord.ZERO);
}
program.stackPush(val);
program.step();
} break;
@ -825,6 +824,8 @@ public class VM {
int nPush = op.val() - PUSH1.val() + 1;
byte[] data = program.sweep(nPush);
if (logger.isInfoEnabled())
hint = "" + Hex.toHexString(data);
program.stackPush(data);
@ -913,9 +914,8 @@ public class VM {
vmCounter++;
} catch (RuntimeException e) {
if(e instanceof OutOfGasException)
program.spendAllGas();
logger.warn("VM halted", e.getMessage());
program.spendAllGas();
program.stop();
throw e;
} finally {

View File

@ -452,32 +452,32 @@ public class VMTest {
assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase() );
}
@Test(expected=RuntimeException.class) // PUSHN OP mal data
@Test // PUSHN OP not enough data
public void testPUSHN_1() {
VM vm = new VM();
program = new Program(Hex.decode("61AA"), invoke);
String expected = "000000000000000000000000000000000000000000000000000000000000AA00";
try {
program.fullTrace();
vm.step(program);
} finally {
assertTrue(program.isStopped());
}
assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase());
}
@Test(expected=RuntimeException.class) // PUSHN OP mal data
@Test // PUSHN OP not enough data
public void testPUSHN_2() {
VM vm = new VM();
program = new Program(Hex.decode("7fAABB"), invoke);
String expected = "AABB000000000000000000000000000000000000000000000000000000000000";
try {
program.fullTrace();
vm.step(program);
} finally {
assertTrue(program.isStopped());
}
assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase());
}
@Test // AND OP