Exception severity uniform
This commit is contained in:
parent
bf8163da7a
commit
3dfb7e44f9
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
@ -739,11 +738,11 @@ public class VM {
|
|||
DataWord val = program.storageLoad(key);
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
hint = "key: " + key + " value: " + val;
|
||||
hint = "key: " + key + " value: " + val;
|
||||
|
||||
if (val == null) {
|
||||
if (val == null)
|
||||
val = key.and(DataWord.ZERO);
|
||||
}
|
||||
|
||||
program.stackPush(val);
|
||||
program.step();
|
||||
} break;
|
||||
|
@ -825,7 +824,9 @@ public class VM {
|
|||
int nPush = op.val() - PUSH1.val() + 1;
|
||||
|
||||
byte[] data = program.sweep(nPush);
|
||||
hint = "" + Hex.toHexString(data);
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
hint = "" + Hex.toHexString(data);
|
||||
|
||||
program.stackPush(data);
|
||||
} break;
|
||||
|
@ -913,9 +914,8 @@ public class VM {
|
|||
|
||||
vmCounter++;
|
||||
} catch (RuntimeException e) {
|
||||
if(e instanceof OutOfGasException)
|
||||
program.spendAllGas();
|
||||
logger.warn("VM halted", e.getMessage());
|
||||
logger.warn("VM halted", e.getMessage());
|
||||
program.spendAllGas();
|
||||
program.stop();
|
||||
throw e;
|
||||
} finally {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
program.fullTrace();
|
||||
vm.step(program);
|
||||
|
||||
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());
|
||||
}
|
||||
program.fullTrace();
|
||||
vm.step(program);
|
||||
|
||||
assertTrue(program.isStopped());
|
||||
assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase());
|
||||
}
|
||||
|
||||
@Test // AND OP
|
||||
|
|
Loading…
Reference in New Issue