Fixed CODECOPY bug

This commit is contained in:
romanman 2014-07-11 21:59:38 +03:00
parent 7af06b8c18
commit 9c769d5b77
3 changed files with 36 additions and 5 deletions

View File

@ -188,6 +188,8 @@ public class Program {
// check if you need to allocate
if (memSize < (address + value.length)) {
long overlap = memSize - address;
int sizeToAllocate = 0;
if (memSize > address) {
sizeToAllocate = memSize + value.length;
@ -195,6 +197,8 @@ public class Program {
sizeToAllocate = memSize + (address - memSize) + value.length;
}
if (overlap > 0) sizeToAllocate -= overlap;
// complete to 32
sizeToAllocate = (sizeToAllocate % 32)==0 ? sizeToAllocate :
sizeToAllocate + (32 - sizeToAllocate % 32);

View File

@ -59,7 +59,7 @@ public class VM {
byte op = program.getCurrentOp();
program.setLastOp(op);
logger.debug("Op: {}" ,OpCode.code(op).name());
logger.debug("[ {} ] Op: {}" ,program.getPC(), OpCode.code(op).name());
int oldMemSize = program.getMemSize();

View File

@ -6,9 +6,7 @@ import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.spongycastle.util.encoders.Hex;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
/**
* www.ethereumJ.com
@ -2361,9 +2359,38 @@ public class VMTest {
assertTrue(program.isStopped());
}
@Test(expected=RuntimeException.class) // CODECOPY OP mal
// DataWord memOffsetData
// DataWord codeOffsetData
// DataWord lengthData
@Test // CODECOPY OP
public void testCODECOPY_5() {
VM vm = new VM();
Program program =
new Program(Hex.decode("611234600054615566602054607060006020396000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e756600054600053602002351234"),
new ProgramInvokeMockImpl());
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
program.getResult().getRepository().close();
assertFalse(program.isStopped());
}
@Test(expected=RuntimeException.class) // CODECOPY OP mal
public void testCODECOPY_6() {
VM vm = new VM();
Program program =
new Program(Hex.decode("605E6007396000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e756600054600053602002351234"),