diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2017-01-05 03:17:24 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2017-02-14 04:44:25 +0800 |
commit | c12f4df910e2da1cc5dd28c5c4bbe2d8721e1057 (patch) | |
tree | da94063644627d9da853a91c28bc37f2df341dd1 /core/vm/jump_table.go | |
parent | 72dcd3c58bec0a281280d5d42ed53b6e429ce4af (diff) | |
download | go-tangerine-c12f4df910e2da1cc5dd28c5c4bbe2d8721e1057.tar.gz go-tangerine-c12f4df910e2da1cc5dd28c5c4bbe2d8721e1057.tar.zst go-tangerine-c12f4df910e2da1cc5dd28c5c4bbe2d8721e1057.zip |
params: core, core/vm, miner: 64bit gas instructions
Reworked the EVM gas instructions to use 64bit integers rather than
arbitrary size big ints. All gas operations, be it additions,
multiplications or divisions, are checked and guarded against 64 bit
integer overflows.
In additon, most of the protocol paramaters in the params package have
been converted to uint64 and are now constants rather than variables.
* common/math: added overflow check ops
* core: vmenv, env renamed to evm
* eth, internal/ethapi, les: unmetered eth_call and cancel methods
* core/vm: implemented big.Int pool for evm instructions
* core/vm: unexported intPool methods & verification methods
* core/vm: added memoryGasCost overflow check and test
Diffstat (limited to 'core/vm/jump_table.go')
-rw-r--r-- | core/vm/jump_table.go | 105 |
1 files changed, 54 insertions, 51 deletions
diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index 073798274..ed30100ac 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -17,6 +17,7 @@ package vm import ( + "errors" "math/big" "github.com/ethereum/go-ethereum/params" @@ -24,11 +25,13 @@ import ( type ( executionFunc func(pc *uint64, env *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) - gasFunc func(params.GasTable, *EVM, *Contract, *Stack, *Memory, *big.Int) *big.Int + gasFunc func(params.GasTable, *EVM, *Contract, *Stack, *Memory, uint64) (uint64, error) // last parameter is the requested memory size as a uint64 stackValidationFunc func(*Stack) error memorySizeFunc func(*Stack) *big.Int ) +var errGasUintOverflow = errors.New("gas uint64 overflow") + type operation struct { // op is the operation function execute executionFunc @@ -54,7 +57,7 @@ func NewJumpTable() [256]operation { return [256]operation{ STOP: { execute: opStop, - gasCost: constGasFunc(new(big.Int)), + gasCost: constGasFunc(0), validateStack: makeStackFunc(0, 0), halts: true, valid: true, @@ -62,139 +65,139 @@ func NewJumpTable() [256]operation { ADD: { execute: opAdd, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, MUL: { execute: opMul, gasCost: constGasFunc(GasFastStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, SUB: { execute: opSub, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, DIV: { execute: opDiv, gasCost: constGasFunc(GasFastStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, SDIV: { execute: opSdiv, gasCost: constGasFunc(GasFastStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, MOD: { execute: opMod, gasCost: constGasFunc(GasFastStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, SMOD: { execute: opSmod, gasCost: constGasFunc(GasFastStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, ADDMOD: { execute: opAddmod, gasCost: constGasFunc(GasMidStep), - validateStack: makeStackFunc(3, -2), + validateStack: makeStackFunc(3, 1), valid: true, }, MULMOD: { execute: opMulmod, gasCost: constGasFunc(GasMidStep), - validateStack: makeStackFunc(3, -2), + validateStack: makeStackFunc(3, 1), valid: true, }, EXP: { execute: opExp, gasCost: gasExp, - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, SIGNEXTEND: { execute: opSignExtend, gasCost: constGasFunc(GasFastStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, LT: { execute: opLt, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, GT: { execute: opGt, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, SLT: { execute: opSlt, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, SGT: { execute: opSgt, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, EQ: { execute: opEq, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, ISZERO: { execute: opIszero, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(1, 0), + validateStack: makeStackFunc(1, 1), valid: true, }, AND: { execute: opAnd, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, XOR: { execute: opXor, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, OR: { execute: opOr, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, NOT: { execute: opNot, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(1, 0), + validateStack: makeStackFunc(1, 1), valid: true, }, BYTE: { execute: opByte, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), valid: true, }, SHA3: { execute: opSha3, gasCost: gasSha3, - validateStack: makeStackFunc(2, -1), + validateStack: makeStackFunc(2, 1), memorySize: memorySha3, valid: true, }, @@ -207,7 +210,7 @@ func NewJumpTable() [256]operation { BALANCE: { execute: opBalance, gasCost: gasBalance, - validateStack: makeStackFunc(1, 0), + validateStack: makeStackFunc(1, 1), valid: true, }, ORIGIN: { @@ -231,7 +234,7 @@ func NewJumpTable() [256]operation { CALLDATALOAD: { execute: opCalldataLoad, gasCost: constGasFunc(GasFastestStep), - validateStack: makeStackFunc(1, 0), + validateStack: makeStackFunc(1, 1), valid: true, }, CALLDATASIZE: { @@ -243,7 +246,7 @@ func NewJumpTable() [256]operation { CALLDATACOPY: { execute: opCalldataCopy, gasCost: gasCalldataCopy, - validateStack: makeStackFunc(3, -3), + validateStack: makeStackFunc(3, 0), memorySize: memoryCalldataCopy, valid: true, }, @@ -256,7 +259,7 @@ func NewJumpTable() [256]operation { CODECOPY: { execute: opCodeCopy, gasCost: gasCodeCopy, - validateStack: makeStackFunc(3, -3), + validateStack: makeStackFunc(3, 0), memorySize: memoryCodeCopy, valid: true, }, @@ -269,20 +272,20 @@ func NewJumpTable() [256]operation { EXTCODESIZE: { execute: opExtCodeSize, gasCost: gasExtCodeSize, - validateStack: makeStackFunc(1, 0), + validateStack: makeStackFunc(1, 1), valid: true, }, EXTCODECOPY: { execute: opExtCodeCopy, gasCost: gasExtCodeCopy, - validateStack: makeStackFunc(4, -4), + validateStack: makeStackFunc(4, 0), memorySize: memoryExtCodeCopy, valid: true, }, BLOCKHASH: { execute: opBlockhash, gasCost: constGasFunc(GasExtStep), - validateStack: makeStackFunc(1, 0), + validateStack: makeStackFunc(1, 1), valid: true, }, COINBASE: { @@ -318,20 +321,20 @@ func NewJumpTable() [256]operation { POP: { execute: opPop, gasCost: constGasFunc(GasQuickStep), - validateStack: makeStackFunc(1, -1), + validateStack: makeStackFunc(1, 0), valid: true, }, MLOAD: { execute: opMload, gasCost: gasMLoad, - validateStack: makeStackFunc(1, 0), + validateStack: makeStackFunc(1, 1), memorySize: memoryMLoad, valid: true, }, MSTORE: { execute: opMstore, gasCost: gasMStore, - validateStack: makeStackFunc(2, -2), + validateStack: makeStackFunc(2, 0), memorySize: memoryMStore, valid: true, }, @@ -339,33 +342,33 @@ func NewJumpTable() [256]operation { execute: opMstore8, gasCost: gasMStore8, memorySize: memoryMStore8, - validateStack: makeStackFunc(2, -2), + validateStack: makeStackFunc(2, 0), valid: true, }, SLOAD: { execute: opSload, gasCost: gasSLoad, - validateStack: makeStackFunc(1, 0), + validateStack: makeStackFunc(1, 1), valid: true, }, SSTORE: { execute: opSstore, gasCost: gasSStore, - validateStack: makeStackFunc(2, -2), + validateStack: makeStackFunc(2, 0), valid: true, }, JUMP: { execute: opJump, gasCost: constGasFunc(GasMidStep), - validateStack: makeStackFunc(1, -1), + validateStack: makeStackFunc(1, 0), jumps: true, valid: true, }, JUMPI: { execute: opJumpi, gasCost: constGasFunc(GasSlowStep), - validateStack: makeStackFunc(2, -2), + validateStack: makeStackFunc(2, 0), jumps: true, valid: true, }, @@ -780,63 +783,63 @@ func NewJumpTable() [256]operation { LOG0: { execute: makeLog(0), gasCost: makeGasLog(0), - validateStack: makeStackFunc(2, -2), + validateStack: makeStackFunc(2, 0), memorySize: memoryLog, valid: true, }, LOG1: { execute: makeLog(1), gasCost: makeGasLog(1), - validateStack: makeStackFunc(3, -3), + validateStack: makeStackFunc(3, 0), memorySize: memoryLog, valid: true, }, LOG2: { execute: makeLog(2), gasCost: makeGasLog(2), - validateStack: makeStackFunc(4, -4), + validateStack: makeStackFunc(4, 0), memorySize: memoryLog, valid: true, }, LOG3: { execute: makeLog(3), gasCost: makeGasLog(3), - validateStack: makeStackFunc(5, -5), + validateStack: makeStackFunc(5, 0), memorySize: memoryLog, valid: true, }, LOG4: { execute: makeLog(4), gasCost: makeGasLog(4), - validateStack: makeStackFunc(6, -6), + validateStack: makeStackFunc(6, 0), memorySize: memoryLog, valid: true, }, CREATE: { execute: opCreate, gasCost: gasCreate, - validateStack: makeStackFunc(3, -2), + validateStack: makeStackFunc(3, 1), memorySize: memoryCreate, valid: true, }, CALL: { execute: opCall, gasCost: gasCall, - validateStack: makeStackFunc(7, -6), + validateStack: makeStackFunc(7, 1), memorySize: memoryCall, valid: true, }, CALLCODE: { execute: opCallCode, gasCost: gasCallCode, - validateStack: makeStackFunc(7, -6), + validateStack: makeStackFunc(7, 1), memorySize: memoryCall, valid: true, }, RETURN: { execute: opReturn, gasCost: gasReturn, - validateStack: makeStackFunc(2, -2), + validateStack: makeStackFunc(2, 0), memorySize: memoryReturn, halts: true, valid: true, @@ -844,14 +847,14 @@ func NewJumpTable() [256]operation { DELEGATECALL: { execute: opDelegateCall, gasCost: gasDelegateCall, - validateStack: makeStackFunc(6, -5), + validateStack: makeStackFunc(6, 1), memorySize: memoryDelegateCall, valid: true, }, SELFDESTRUCT: { execute: opSuicide, gasCost: gasSuicide, - validateStack: makeStackFunc(1, -1), + validateStack: makeStackFunc(1, 0), halts: true, valid: true, }, |