Gas Ledger introduced
+ latest merge + some GUI adjustments
This commit is contained in:
parent
991d9770cb
commit
517bb2cec1
|
@ -59,7 +59,7 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{
|
|||
AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance();
|
||||
atmf.putMapping("text/console", "org.ethereum.gui.ConsoleTokenMaker");
|
||||
|
||||
textArea = new RSyntaxTextArea(16, 47);
|
||||
textArea = new RSyntaxTextArea(16, 44);
|
||||
textArea.setSyntaxEditingStyle("text/console");
|
||||
// textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_LISP);
|
||||
textArea.setCodeFoldingEnabled(true);
|
||||
|
@ -74,7 +74,7 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{
|
|||
setTitle("Connection Console");
|
||||
// setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
pack();
|
||||
setLocation(775, 390);
|
||||
setLocation(802, 460);
|
||||
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
|
|
|
@ -37,8 +37,8 @@ public class PeersTableWindow extends JFrame{
|
|||
|
||||
// Set the frame characteristics
|
||||
setTitle("Ethereum Peers");
|
||||
setSize(355, 300);
|
||||
setLocation(815, 80);
|
||||
setSize(355, 400);
|
||||
setLocation(815, 30);
|
||||
|
||||
java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png");
|
||||
Toolkit kit = Toolkit.getDefaultToolkit();
|
||||
|
|
|
@ -31,7 +31,8 @@ public class ProgramPlayDialog extends JPanel implements ActionListener,
|
|||
outputList = new ArrayList<String>();
|
||||
VM vm = new VM();
|
||||
// Program program = new Program(Hex.decode("630000000060445960CC60DD611234600054615566602054630000000060445960CC60DD611234600054615566602054630000000060445960CC60DD611234600054615566602054"));
|
||||
Program program = new Program(Hex.decode("60016023576000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e75660005460005360200235602054"), null);
|
||||
// Program program = new Program(Hex.decode("60016023576000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e75660005460005360200235602054"), null);
|
||||
Program program = new Program(Hex.decode("620f424073cd2a3d9f938e13cd947ec05abc7fe734df8dd826576086602660003960866000f26001602036040e0f630000002159600060200235600054600053565b525b54602052f263000000765833602054602053566040546000602002356060546001602002356080546080536040530a0f0f630000006c59608053604053036020535760805360605356016060535760015b525b54602052f263000000765860005b525b54602052f2"), null);
|
||||
|
||||
program.addListener(this);
|
||||
program.fullTrace();
|
||||
|
@ -117,9 +118,15 @@ public class ProgramPlayDialog extends JPanel implements ActionListener,
|
|||
ProgramPlayDialog ppd = new ProgramPlayDialog();
|
||||
|
||||
//Create and set up the window.
|
||||
JFrame frame = new JFrame("SliderDemo");
|
||||
JFrame frame = new JFrame("Program Draft Play");
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
|
||||
java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png");
|
||||
Toolkit kit = Toolkit.getDefaultToolkit();
|
||||
Image img = kit.createImage(url);
|
||||
frame.setIconImage(img);
|
||||
|
||||
|
||||
frame.setPreferredSize(new Dimension(580, 500));
|
||||
frame.setLocation(400, 200);
|
||||
|
||||
|
|
|
@ -115,12 +115,19 @@ public class ByteUtil {
|
|||
// check if the string is numeric
|
||||
if (arg.toString().trim().matches("-?\\d+(\\.\\d+)?")) {
|
||||
data = new BigInteger(arg.toString().trim()).toByteArray();
|
||||
} else {
|
||||
|
||||
// check if it's hex number
|
||||
} else if (arg.toString().trim().matches("0[xX][0-9a-fA-F]+")){
|
||||
data = new BigInteger(arg.toString().trim().substring(2), 16).toByteArray();
|
||||
|
||||
} else {
|
||||
data = arg.toString().trim().getBytes();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (data.length > 32)
|
||||
throw new RuntimeException("values can't be more than 32 bits");
|
||||
throw new RuntimeException("values can't be more than 32 byte");
|
||||
|
||||
byte[] val = new byte[32];
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package org.ethereum.vm;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* www.ethereumJ.com
|
||||
* User: Roman Mandeleil
|
||||
* Created on: 04/06/2014 23:58
|
||||
*/
|
||||
|
||||
public class GasLedger {
|
||||
|
||||
/* YP Appendix B.
|
||||
Gstep 1 Default amount of gas to pay for execution cycle.
|
||||
Gstop 0 Nothing paid for the STOP operation.
|
||||
Gsuicide 0 Nothing paid for the SUICIDE operation.
|
||||
Gsha3 20 Paid for a SHA3 operation.
|
||||
Gsload 20 Paid for a SLOAD operation.
|
||||
Gsstore 100 Paid for a normal SSTORE operation (doubled or waived sometimes).
|
||||
Gbalance 20 Paid for a BALANCE operation.
|
||||
Gcreate 100 Paid for a CREATE operation.
|
||||
Gcall 20 Paid for a CALL operation.
|
||||
Gmemory 1 Paid for every additional word when expanding memory.
|
||||
Gtxdata 5 Paid for every byte of data or code for a transaction.
|
||||
Gtransaction 500 Paid for every transaction.
|
||||
*/
|
||||
|
||||
|
||||
public static int G_STEP = 1;
|
||||
public static int G_STOP = 0;
|
||||
public static int G_SUICIDE = 0;
|
||||
public static int G_SLOAD = 20;
|
||||
public static int G_SHA3 = 20;
|
||||
public static int G_SSTORE = 100;
|
||||
public static int G_BALANCE = 20;
|
||||
public static int G_CREATE = 100;
|
||||
public static int G_CALL = 20;
|
||||
public static int G_MEMORY = 1;
|
||||
public static int G_TXDATA = 5;
|
||||
public static int G_TRANSACTION = 500;
|
||||
}
|
|
@ -131,8 +131,8 @@ public enum OpCode {
|
|||
* System operations
|
||||
*/
|
||||
|
||||
CREATE(0xf0),
|
||||
CALL(0xf1),
|
||||
CREATE(0xf0), // [in_size] [in_offs] [gas_val] CREATE
|
||||
CALL(0xf1), // [out_data_size] [out_data_start] [in_data_size] [in_data_start] [value] [to_addr] [gas] CALL
|
||||
RETURN(0xf2),
|
||||
SUICIDE(0xff);
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ public class Program {
|
|||
byte[] ops;
|
||||
int pc = 0;
|
||||
boolean stopped = false;
|
||||
int spendGas = 0;
|
||||
|
||||
ProgramInvoke invokeData;
|
||||
|
||||
|
@ -186,6 +187,13 @@ public class Program {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void spendGas(int gasValue){
|
||||
// todo: check it against avail gas
|
||||
// todo: out of gas will revert the changes
|
||||
spendGas += gasValue;
|
||||
}
|
||||
|
||||
public void storageSave(DataWord word1, DataWord word2){
|
||||
storageSave(word1.getData(), word2.getData());
|
||||
}
|
||||
|
|
|
@ -30,6 +30,38 @@ public class VM {
|
|||
byte op = program.getCurrentOp();
|
||||
logger.debug("Op: {}" ,OpCode.code(op).name());
|
||||
|
||||
|
||||
switch (OpCode.code(op)) {
|
||||
case SHA3:
|
||||
program.spendGas( GasLedger.G_SHA3 );
|
||||
break;
|
||||
case SLOAD:
|
||||
program.spendGas( GasLedger.G_SLOAD );
|
||||
break;
|
||||
case SSTORE:
|
||||
// todo: calc gas in the execution
|
||||
// todo: according to the size
|
||||
break;
|
||||
case BALANCE:
|
||||
program.spendGas( GasLedger.G_BALANCE );
|
||||
break;
|
||||
case CREATE:
|
||||
program.spendGas( GasLedger.G_CREATE );
|
||||
break;
|
||||
case CALL:
|
||||
program.spendGas( GasLedger.G_CALL );
|
||||
break;
|
||||
case MSTORE8:
|
||||
case MSTORE:
|
||||
// todo: calc gas in the execution
|
||||
// todo: according to the size
|
||||
break;
|
||||
default:
|
||||
program.spendGas( GasLedger.G_STEP );
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
switch (OpCode.code(op)) {
|
||||
|
||||
|
||||
|
@ -480,9 +512,15 @@ public class VM {
|
|||
program.stop();
|
||||
}
|
||||
break;
|
||||
case SUICIDE:
|
||||
break;
|
||||
default:
|
||||
case SUICIDE:{
|
||||
DataWord address = program.stackPop();
|
||||
// todo: transfer left balance to the address
|
||||
program.stop();
|
||||
}
|
||||
break;
|
||||
default:{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
program.fullTrace();
|
||||
|
|
|
@ -8,7 +8,7 @@ init:
|
|||
# this part run only on init stage
|
||||
# we are about to set the maxim
|
||||
# amount of currency
|
||||
contract.storage[0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826] = 1000000
|
||||
contract.storage[0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826] = 10000000
|
||||
code:
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue