use of org.ethereum.vm.program.Stack in project rskj by rsksmart.
the class VM method dumpLine.
/*
* Dumping the VM state at the current operation in various styles
* - standard Not Yet Implemented
* - standard+ (owner address, program counter, operation, gas left)
* - pretty (stack, memory, storage, level, contract,
* vmCounter, internalSteps, operation
gasBefore, gasCost, memWords)
*/
private void dumpLine(OpCode op, long gasBefore, long gasCost, long memWords, Program program) {
if ("standard+".equals(vmConfig.dumpStyle())) {
switch(op) {
case STOP:
case RETURN:
case SUICIDE:
ContractDetails details = program.getStorage().getContractDetails(new RskAddress(program.getOwnerAddress()));
List<DataWord> storageKeys = new ArrayList<>(details.getStorage().keySet());
Collections.sort(storageKeys);
storageKeys.forEach(key -> dumpLogger.trace("{} {}", Hex.toHexString(key.getNoLeadZeroesData()), Hex.toHexString(details.getStorage().get(key).getNoLeadZeroesData())));
break;
default:
break;
}
String addressString = Hex.toHexString(program.getOwnerAddress().getLast20Bytes());
String pcString = Hex.toHexString(new DataWord(program.getPC()).getNoLeadZeroesData());
String opString = Hex.toHexString(new byte[] { op.val() });
String gasString = Long.toHexString(program.getRemainingGas());
dumpLogger.trace("{} {} {} {}", addressString, pcString, opString, gasString);
} else if ("pretty".equals(vmConfig.dumpStyle())) {
dumpLogger.trace("-------------------------------------------------------------------------");
dumpLogger.trace(" STACK");
program.getStack().forEach(item -> dumpLogger.trace("{}", item));
dumpLogger.trace(" MEMORY");
String memoryString = program.memoryToString();
if (!"".equals(memoryString)) {
dumpLogger.trace("{}", memoryString);
}
dumpLogger.trace(" STORAGE");
ContractDetails details = program.getStorage().getContractDetails(new RskAddress(program.getOwnerAddress()));
List<DataWord> storageKeys = new ArrayList<>(details.getStorage().keySet());
Collections.sort(storageKeys);
storageKeys.forEach(key -> dumpLogger.trace("{}: {}", key.shortHex(), details.getStorage().get(key).shortHex()));
int level = program.getCallDeep();
String contract = Hex.toHexString(program.getOwnerAddress().getLast20Bytes());
String internalSteps = String.format("%4s", Integer.toHexString(program.getPC())).replace(' ', '0').toUpperCase();
dumpLogger.trace("{} | {} | #{} | {} : {} | {} | -{} | {}x32", level, contract, vmCounter, internalSteps, op, gasBefore, gasCost, memWords);
}
}
use of org.ethereum.vm.program.Stack in project rskj by rsksmart.
the class VMExecutionTest method swapnTwentiethItem.
@Test
public void swapnTwentiethItem() {
Program program = executeCode("PUSH1 0x01 PUSH1 0x02 PUSH1 0x03 PUSH1 0x04 PUSH1 0x05 PUSH1 0x06 PUSH1 0x07 PUSH1 0x08 PUSH1 0x09 PUSH1 0x0a PUSH1 0x0b PUSH1 0x0c PUSH1 0x0d PUSH1 0x0e PUSH1 0x0f PUSH1 0x10 PUSH1 0x11 PUSH1 0x12 PUSH1 0x13 PUSH1 0x14 PUSH1 0x12 SWAPN", 22);
Stack stack = program.getStack();
Assert.assertEquals(20, stack.size());
Assert.assertEquals(new DataWord(1), stack.peek());
Assert.assertEquals(new DataWord(20), stack.get(0));
for (int k = 1; k < 19; k++) Assert.assertEquals(new DataWord(k + 1), stack.get(k));
}
use of org.ethereum.vm.program.Stack in project rskj by rsksmart.
the class VMExecutionTest method swapnFourthItem.
@Test
public void swapnFourthItem() {
Program program = executeCode("PUSH1 0x01 PUSH1 0x02 PUSH1 0x03 PUSH1 0x04 PUSH1 0x02 SWAPN", 6);
Stack stack = program.getStack();
Assert.assertEquals(4, stack.size());
Assert.assertEquals(new DataWord(1), stack.peek());
Assert.assertEquals(new DataWord(4), stack.get(0));
Assert.assertEquals(new DataWord(2), stack.get(1));
Assert.assertEquals(new DataWord(3), stack.get(2));
}
use of org.ethereum.vm.program.Stack in project rskj by rsksmart.
the class VMExecutionTest method testSub.
@Test
public void testSub() {
Program program = executeCode("PUSH1 1 PUSH1 2 SUB", 3);
Stack stack = program.getStack();
Assert.assertEquals(1, stack.size());
Assert.assertEquals(new DataWord(1), stack.peek());
}
use of org.ethereum.vm.program.Stack in project rskj by rsksmart.
the class VMExecutionTest method dupnFirstItem.
@Test
public void dupnFirstItem() {
Program program = executeCode("PUSH1 0x01 PUSH1 0x00 DUPN", 3);
Stack stack = program.getStack();
Assert.assertEquals(2, stack.size());
Assert.assertEquals(new DataWord(1), stack.peek());
Assert.assertEquals(new DataWord(1), stack.get(0));
}
Aggregations