aboutsummaryrefslogtreecommitdiffstats
path: root/vm/gas.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-10 07:25:27 +0800
committerobscuren <geffobscura@gmail.com>2015-03-10 07:25:27 +0800
commit9007f2bbdc3b38f8f005778467157db12056c17e (patch)
tree15ceec2bd62ebd11ec7850cebd20a0ba32775c89 /vm/gas.go
parent0795fd2701f67e489e47d9b7998ffa52adf8863e (diff)
downloaddexon-9007f2bbdc3b38f8f005778467157db12056c17e.tar
dexon-9007f2bbdc3b38f8f005778467157db12056c17e.tar.gz
dexon-9007f2bbdc3b38f8f005778467157db12056c17e.tar.bz2
dexon-9007f2bbdc3b38f8f005778467157db12056c17e.tar.lz
dexon-9007f2bbdc3b38f8f005778467157db12056c17e.tar.xz
dexon-9007f2bbdc3b38f8f005778467157db12056c17e.tar.zst
dexon-9007f2bbdc3b38f8f005778467157db12056c17e.zip
reworked stack
Diffstat (limited to 'vm/gas.go')
-rw-r--r--vm/gas.go86
1 files changed, 86 insertions, 0 deletions
diff --git a/vm/gas.go b/vm/gas.go
new file mode 100644
index 000000000..a19afeb67
--- /dev/null
+++ b/vm/gas.go
@@ -0,0 +1,86 @@
+package vm
+
+import "math/big"
+
+type req struct {
+ stack int
+ gas *big.Int
+}
+
+var _baseCheck = map[OpCode]req{
+ // Req stack Gas price
+ ADD: {2, GasFastestStep},
+ LT: {2, GasFastestStep},
+ GT: {2, GasFastestStep},
+ SLT: {2, GasFastestStep},
+ SGT: {2, GasFastestStep},
+ EQ: {2, GasFastestStep},
+ ISZERO: {1, GasFastestStep},
+ SUB: {2, GasFastestStep},
+ AND: {2, GasFastestStep},
+ OR: {2, GasFastestStep},
+ XOR: {2, GasFastestStep},
+ NOT: {1, GasFastestStep},
+ BYTE: {2, GasFastestStep},
+ CALLDATALOAD: {1, GasFastestStep},
+ CALLDATACOPY: {3, GasFastestStep},
+ MLOAD: {1, GasFastestStep},
+ MSTORE: {2, GasFastestStep},
+ MSTORE8: {2, GasFastestStep},
+ CODECOPY: {3, GasFastestStep},
+ MUL: {2, GasFastStep},
+ DIV: {2, GasFastStep},
+ SDIV: {2, GasFastStep},
+ MOD: {2, GasFastStep},
+ SMOD: {2, GasFastStep},
+ SIGNEXTEND: {2, GasFastStep},
+ ADDMOD: {3, GasMidStep},
+ MULMOD: {3, GasMidStep},
+ JUMP: {1, GasMidStep},
+ JUMPI: {2, GasSlowStep},
+ EXP: {2, GasSlowStep},
+ ADDRESS: {0, GasQuickStep},
+ ORIGIN: {0, GasQuickStep},
+ CALLER: {0, GasQuickStep},
+ CALLVALUE: {0, GasQuickStep},
+ CODESIZE: {0, GasQuickStep},
+ GASPRICE: {0, GasQuickStep},
+ COINBASE: {0, GasQuickStep},
+ TIMESTAMP: {0, GasQuickStep},
+ NUMBER: {0, GasQuickStep},
+ CALLDATASIZE: {0, GasQuickStep},
+ DIFFICULTY: {0, GasQuickStep},
+ GASLIMIT: {0, GasQuickStep},
+ POP: {0, GasQuickStep},
+ PC: {0, GasQuickStep},
+ MSIZE: {0, GasQuickStep},
+ GAS: {0, GasQuickStep},
+ BLOCKHASH: {1, GasExtStep},
+ BALANCE: {0, GasExtStep},
+ EXTCODESIZE: {1, GasExtStep},
+ EXTCODECOPY: {4, GasExtStep},
+ SLOAD: {1, GasStorageGet},
+ SSTORE: {2, Zero},
+ SHA3: {1, GasSha3Base},
+ CREATE: {3, GasCreate},
+ CALL: {7, GasCall},
+ CALLCODE: {7, GasCall},
+ JUMPDEST: {0, GasJumpDest},
+ SUICIDE: {1, Zero},
+ RETURN: {2, Zero},
+}
+
+func baseCheck(op OpCode, stack *stack, gas *big.Int) {
+ if r, ok := _baseCheck[op]; ok {
+ stack.require(r.stack)
+
+ gas.Add(gas, r.gas)
+ }
+}
+
+func toWordSize(size *big.Int) *big.Int {
+ tmp := new(big.Int)
+ tmp.Add(size, u256(31))
+ tmp.Div(tmp, u256(32))
+ return tmp
+}