diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/ProgramPlayDialog.java b/ethereumj-core/src/main/java/org/ethereum/gui/ProgramPlayDialog.java index 46709bc7..ef9d2102 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/ProgramPlayDialog.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/ProgramPlayDialog.java @@ -34,7 +34,7 @@ public class ProgramPlayDialog extends JPanel implements ActionListener, ChangeL program.addListener(this); program.fullTrace(); - while(!program.isStoped()) + while(!program.isStopped()) vm.step(program); setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java b/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java index f00585ff..3408a102 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java @@ -1,14 +1,11 @@ package org.ethereum.vm; -import com.fasterxml.jackson.databind.ser.std.ArraySerializerBase; import org.spongycastle.util.Arrays; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.nio.ByteBuffer; -import static java.util.Arrays.*; - /** * www.ethereumJ.com * User: Roman Mandeleil diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/Program.java b/ethereumj-core/src/main/java/org/ethereum/vm/Program.java index 1afe41e0..0a005a87 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/Program.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/Program.java @@ -1,11 +1,8 @@ package org.ethereum.vm; -import com.google.api.client.util.ByteStreams; -import io.netty.buffer.UnpooledDirectByteBuf; import org.ethereum.util.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.nio.ByteBuffer; @@ -65,7 +62,7 @@ public class Program { this.pc = pc; } - public boolean isStoped(){ + public boolean isStopped(){ return stopped; } diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java index 015573ec..91230379 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java @@ -20,7 +20,7 @@ public class VM { Logger logger = LoggerFactory.getLogger("VM"); - public void step(Program program){ + public void step(Program program) { try { @@ -28,7 +28,7 @@ public class VM { byte op = program.getCurrentOp(); logger.debug("Op: {}" ,OpCode.code(op).name()); - switch (OpCode.code(op)){ + switch (OpCode.code(op)) { /** @@ -36,12 +36,10 @@ public class VM { */ case STOP:{ - program.stop(); } break; case ADD:{ - DataWord word1 = program.stackPull(); DataWord word2 = program.stackPull(); word1.add(word2); @@ -50,7 +48,6 @@ public class VM { } break; case MUL:{ - DataWord word1 = program.stackPull(); DataWord word2 = program.stackPull(); word1.mull(word2); @@ -59,7 +56,6 @@ public class VM { } break; case SUB:{ - DataWord word1 = program.stackPull(); DataWord word2 = program.stackPull(); word1.sub(word2); @@ -68,7 +64,6 @@ public class VM { } break; case DIV:{ - DataWord word1 = program.stackPull(); DataWord word2 = program.stackPull(); word1.div(word2); @@ -83,7 +78,6 @@ public class VM { case SMOD: break; case EXP:{ - DataWord word1 = program.stackPull(); DataWord word2 = program.stackPull(); word1.exp(word2); @@ -96,7 +90,8 @@ public class VM { word1.negate(); program.stackPush(word1); program.step(); - }break; + } + break; case LT:{ DataWord word1 = program.stackPull(); DataWord word2 = program.stackPull(); @@ -108,12 +103,13 @@ public class VM { } program.stackPush(word1); program.step(); - }break; + } + break; case SLT: break; case SGT: break; - case GT:{ + case GT: { DataWord word1 = program.stackPull(); DataWord word2 = program.stackPull(); if (word1.value().compareTo(word2.value()) == 1){ @@ -124,8 +120,9 @@ public class VM { } program.stackPush(word1); program.step(); - }break; - case EQ:{ + } + break; + case EQ: { DataWord word1 = program.stackPull(); DataWord word2 = program.stackPull(); if (word1.xor(word2).isZero()){ @@ -150,8 +147,6 @@ public class VM { } break; - - /** * Bitwise Logic Operations */ @@ -180,20 +175,18 @@ public class VM { program.step(); } break; - case BYTE:{ - + case BYTE: { DataWord word1 = program.stackPull(); DataWord word2 = program.stackPull(); - DataWord result = null; if (word1.value().compareTo(_32_) == -1){ byte tmp = word2.getData()[word1.value().intValue()]; word2.and(DataWord.ZERO); word2.getData()[31] = tmp; result = word2; - } else + } else { result = new DataWord(); - + } program.stackPush(result); program.step(); } @@ -267,7 +260,6 @@ public class VM { case SWAP:{ DataWord word_1 = program.stackPull(); DataWord word_2 = program.stackPull(); - program.stackPush(word_1); program.stackPush(word_2); program.step(); @@ -283,13 +275,11 @@ public class VM { case MSTORE:{ DataWord addr = program.stackPull(); DataWord value = program.stackPull(); - program.memorySave(addr, value); program.step(); } break; case MSTORE8:{ - DataWord addr = program.stackPull(); DataWord value = program.stackPull(); byte[] byteVal = {value.getData()[31]}; @@ -300,8 +290,7 @@ public class VM { case SLOAD:{ DataWord key = program.stackPull(); DataWord val = program.storageLoad(key); - - if (val == null){ + if (val == null) { val = key.and(DataWord.ZERO); } program.stackPush(val); @@ -311,7 +300,6 @@ public class VM { case SSTORE:{ DataWord addr = program.stackPull(); DataWord value = program.stackPull(); - program.storageSave(addr, value); program.step(); } @@ -324,7 +312,6 @@ public class VM { case JUMPI:{ DataWord pos = program.stackPull(); DataWord cond = program.stackPull(); - if (!cond.isZero()){ program.setPC(pos); } else{ @@ -335,13 +322,11 @@ public class VM { case PC:{ int pc = program.getPC(); DataWord pcWord = new DataWord(pc); - program.stackPush(pcWord); program.step(); } break; case MEMSIZE:{ - int memSize = program.getMemSize(); DataWord wordMemSize = new DataWord(memSize); program.stackPush(wordMemSize); diff --git a/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java b/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java index cb7b7cd3..f17c873f 100644 --- a/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java @@ -1,6 +1,5 @@ package org.ethereum.vm; -import org.junit.Assert; import org.junit.Test; import org.spongycastle.util.encoders.Hex; @@ -444,7 +443,7 @@ public class VMTest { program.fullTrace(); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -460,7 +459,7 @@ public class VMTest { program.fullTrace(); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -504,7 +503,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -548,7 +547,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -593,7 +592,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -653,7 +652,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -695,7 +694,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -753,7 +752,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -811,7 +810,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -870,7 +869,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -978,7 +977,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -1011,7 +1010,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -1236,7 +1235,7 @@ public class VMTest { try { vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -1296,7 +1295,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -1487,7 +1486,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -1540,7 +1539,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -1615,7 +1614,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -1676,7 +1675,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -1829,7 +1828,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail(); @@ -1923,7 +1922,7 @@ public class VMTest { vm.step(program); vm.step(program); } catch (RuntimeException e) { - assertTrue(program.isStoped()); + assertTrue(program.isStopped()); return; } fail();