Fixed CODECOPY bug
This commit is contained in:
parent
7af06b8c18
commit
9c769d5b77
|
@ -188,6 +188,8 @@ public class Program {
|
||||||
// check if you need to allocate
|
// check if you need to allocate
|
||||||
if (memSize < (address + value.length)) {
|
if (memSize < (address + value.length)) {
|
||||||
|
|
||||||
|
long overlap = memSize - address;
|
||||||
|
|
||||||
int sizeToAllocate = 0;
|
int sizeToAllocate = 0;
|
||||||
if (memSize > address) {
|
if (memSize > address) {
|
||||||
sizeToAllocate = memSize + value.length;
|
sizeToAllocate = memSize + value.length;
|
||||||
|
@ -195,6 +197,8 @@ public class Program {
|
||||||
sizeToAllocate = memSize + (address - memSize) + value.length;
|
sizeToAllocate = memSize + (address - memSize) + value.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (overlap > 0) sizeToAllocate -= overlap;
|
||||||
|
|
||||||
// complete to 32
|
// complete to 32
|
||||||
sizeToAllocate = (sizeToAllocate % 32)==0 ? sizeToAllocate :
|
sizeToAllocate = (sizeToAllocate % 32)==0 ? sizeToAllocate :
|
||||||
sizeToAllocate + (32 - sizeToAllocate % 32);
|
sizeToAllocate + (32 - sizeToAllocate % 32);
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class VM {
|
||||||
|
|
||||||
byte op = program.getCurrentOp();
|
byte op = program.getCurrentOp();
|
||||||
program.setLastOp(op);
|
program.setLastOp(op);
|
||||||
logger.debug("Op: {}" ,OpCode.code(op).name());
|
logger.debug("[ {} ] Op: {}" ,program.getPC(), OpCode.code(op).name());
|
||||||
|
|
||||||
int oldMemSize = program.getMemSize();
|
int oldMemSize = program.getMemSize();
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,7 @@ import org.junit.Test;
|
||||||
import org.junit.runners.MethodSorters;
|
import org.junit.runners.MethodSorters;
|
||||||
import org.spongycastle.util.encoders.Hex;
|
import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* www.ethereumJ.com
|
* www.ethereumJ.com
|
||||||
|
@ -2361,9 +2359,38 @@ public class VMTest {
|
||||||
assertTrue(program.isStopped());
|
assertTrue(program.isStopped());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=RuntimeException.class) // CODECOPY OP mal
|
// DataWord memOffsetData
|
||||||
|
// DataWord codeOffsetData
|
||||||
|
// DataWord lengthData
|
||||||
|
|
||||||
|
|
||||||
|
@Test // CODECOPY OP
|
||||||
public void testCODECOPY_5() {
|
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();
|
VM vm = new VM();
|
||||||
Program program =
|
Program program =
|
||||||
new Program(Hex.decode("605E6007396000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e756600054600053602002351234"),
|
new Program(Hex.decode("605E6007396000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e756600054600053602002351234"),
|
||||||
|
|
Loading…
Reference in New Issue