diff options
Diffstat (limited to 'core/vm')
-rw-r--r-- | core/vm/environment.go | 8 | ||||
-rw-r--r-- | core/vm/instructions.go | 11 | ||||
-rw-r--r-- | core/vm/interface.go | 3 | ||||
-rw-r--r-- | core/vm/jump_table.go | 260 | ||||
-rw-r--r-- | core/vm/log.go | 190 | ||||
-rw-r--r-- | core/vm/log_test.go | 131 | ||||
-rw-r--r-- | core/vm/noop.go | 3 |
7 files changed, 147 insertions, 459 deletions
diff --git a/core/vm/environment.go b/core/vm/environment.go index b74b3a795..c19ef464b 100644 --- a/core/vm/environment.go +++ b/core/vm/environment.go @@ -34,7 +34,7 @@ type ( GetHashFunc func(uint64) common.Hash ) -// Context provides the EVM with auxilary information. Once provided it shouldn't be modified. +// Context provides the EVM with auxiliary information. Once provided it shouldn't be modified. type Context struct { // CanTransfer returns whether the account contains // sufficient ether to transfer the value @@ -99,7 +99,7 @@ func (evm *EVM) Cancel() { atomic.StoreInt32(&evm.abort, 1) } -// Call executes the contract associated with the addr with the given input as paramaters. It also handles any +// Call executes the contract associated with the addr with the given input as parameters. It also handles any // necessary value transfer required and takes the necessary steps to create accounts and reverses the state in // case of an execution error or failed value transfer. func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas, value *big.Int) (ret []byte, err error) { @@ -157,7 +157,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas, return ret, err } -// CallCode executes the contract associated with the addr with the given input as paramaters. It also handles any +// CallCode executes the contract associated with the addr with the given input as parameters. It also handles any // necessary value transfer required and takes the necessary steps to create accounts and reverses the state in // case of an execution error or failed value transfer. // @@ -203,7 +203,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, return ret, err } -// DelegateCall executes the contract associated with the addr with the given input as paramaters. +// DelegateCall executes the contract associated with the addr with the given input as parameters. // It reverses the state in case of an execution error. // // DelegateCall differs from CallCode in the sense that it executes the given address' code with the caller as context diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 2839b7109..5bfa73a30 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -22,6 +22,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params" ) @@ -605,8 +606,14 @@ func makeLog(size int) executionFunc { } d := memory.Get(mStart.Int64(), mSize.Int64()) - log := NewLog(contract.Address(), topics, d, env.BlockNumber.Uint64()) - env.StateDB.AddLog(log) + env.StateDB.AddLog(&types.Log{ + Address: contract.Address(), + Topics: topics, + Data: d, + // This is a non-consensus field, but assigned here because + // core/state doesn't know the current block number. + BlockNumber: env.BlockNumber.Uint64(), + }) return nil, nil } } diff --git a/core/vm/interface.go b/core/vm/interface.go index b81f59125..8617b2d0f 100644 --- a/core/vm/interface.go +++ b/core/vm/interface.go @@ -20,6 +20,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" ) // StateDB is an EVM database for full state querying. @@ -58,7 +59,7 @@ type StateDB interface { RevertToSnapshot(int) Snapshot() int - AddLog(*Log) + AddLog(*types.Log) } // Account represents a contract or basic ethereum account. diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index eb85ae6af..f4ce81883 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -52,283 +52,283 @@ var defaultJumpTable = NewJumpTable() func NewJumpTable() [256]operation { return [256]operation{ - ADD: operation{ + ADD: { execute: opAdd, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(2, 1), valid: true, }, - SUB: operation{ + SUB: { execute: opSub, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(2, 1), valid: true, }, - MUL: operation{ + MUL: { execute: opMul, gasCost: constGasFunc(GasFastStep), validateStack: makeStackFunc(2, 1), valid: true, }, - DIV: operation{ + DIV: { execute: opDiv, gasCost: constGasFunc(GasFastStep), validateStack: makeStackFunc(2, 1), valid: true, }, - SDIV: operation{ + SDIV: { execute: opSdiv, gasCost: constGasFunc(GasFastStep), validateStack: makeStackFunc(2, 1), valid: true, }, - MOD: operation{ + MOD: { execute: opMod, gasCost: constGasFunc(GasFastStep), validateStack: makeStackFunc(2, 1), valid: true, }, - SMOD: operation{ + SMOD: { execute: opSmod, gasCost: constGasFunc(GasFastStep), validateStack: makeStackFunc(2, 1), valid: true, }, - EXP: operation{ + EXP: { execute: opExp, gasCost: gasExp, validateStack: makeStackFunc(2, 1), valid: true, }, - SIGNEXTEND: operation{ + SIGNEXTEND: { execute: opSignExtend, gasCost: constGasFunc(GasFastStep), validateStack: makeStackFunc(2, 1), valid: true, }, - NOT: operation{ + NOT: { execute: opNot, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(1, 1), valid: true, }, - LT: operation{ + LT: { execute: opLt, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(2, 1), valid: true, }, - GT: operation{ + GT: { execute: opGt, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(2, 1), valid: true, }, - SLT: operation{ + SLT: { execute: opSlt, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(2, 1), valid: true, }, - SGT: operation{ + SGT: { execute: opSgt, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(2, 1), valid: true, }, - EQ: operation{ + EQ: { execute: opEq, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(2, 1), valid: true, }, - ISZERO: operation{ + ISZERO: { execute: opIszero, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(1, 1), valid: true, }, - AND: operation{ + AND: { execute: opAnd, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(2, 1), valid: true, }, - OR: operation{ + OR: { execute: opOr, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(2, 1), valid: true, }, - XOR: operation{ + XOR: { execute: opXor, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(2, 1), valid: true, }, - BYTE: operation{ + BYTE: { execute: opByte, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(2, 1), valid: true, }, - ADDMOD: operation{ + ADDMOD: { execute: opAddmod, gasCost: constGasFunc(GasMidStep), validateStack: makeStackFunc(3, 1), valid: true, }, - MULMOD: operation{ + MULMOD: { execute: opMulmod, gasCost: constGasFunc(GasMidStep), validateStack: makeStackFunc(3, 1), valid: true, }, - SHA3: operation{ + SHA3: { execute: opSha3, gasCost: gasSha3, validateStack: makeStackFunc(2, 1), memorySize: memorySha3, valid: true, }, - ADDRESS: operation{ + ADDRESS: { execute: opAddress, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - BALANCE: operation{ + BALANCE: { execute: opBalance, gasCost: gasBalance, validateStack: makeStackFunc(0, 1), valid: true, }, - ORIGIN: operation{ + ORIGIN: { execute: opOrigin, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - CALLER: operation{ + CALLER: { execute: opCaller, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - CALLVALUE: operation{ + CALLVALUE: { execute: opCallValue, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - CALLDATALOAD: operation{ + CALLDATALOAD: { execute: opCalldataLoad, gasCost: constGasFunc(GasFastestStep), validateStack: makeStackFunc(1, 1), valid: true, }, - CALLDATASIZE: operation{ + CALLDATASIZE: { execute: opCalldataSize, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - CALLDATACOPY: operation{ + CALLDATACOPY: { execute: opCalldataCopy, gasCost: gasCalldataCopy, validateStack: makeStackFunc(3, 1), memorySize: memoryCalldataCopy, valid: true, }, - CODESIZE: operation{ + CODESIZE: { execute: opCodeSize, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - EXTCODESIZE: operation{ + EXTCODESIZE: { execute: opExtCodeSize, gasCost: gasExtCodeSize, validateStack: makeStackFunc(1, 1), valid: true, }, - CODECOPY: operation{ + CODECOPY: { execute: opCodeCopy, gasCost: gasCodeCopy, validateStack: makeStackFunc(3, 0), memorySize: memoryCodeCopy, valid: true, }, - EXTCODECOPY: operation{ + EXTCODECOPY: { execute: opExtCodeCopy, gasCost: gasExtCodeCopy, validateStack: makeStackFunc(4, 0), memorySize: memoryExtCodeCopy, valid: true, }, - GASPRICE: operation{ + GASPRICE: { execute: opGasprice, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - BLOCKHASH: operation{ + BLOCKHASH: { execute: opBlockhash, gasCost: constGasFunc(GasExtStep), validateStack: makeStackFunc(1, 1), valid: true, }, - COINBASE: operation{ + COINBASE: { execute: opCoinbase, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - TIMESTAMP: operation{ + TIMESTAMP: { execute: opTimestamp, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - NUMBER: operation{ + NUMBER: { execute: opNumber, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - DIFFICULTY: operation{ + DIFFICULTY: { execute: opDifficulty, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - GASLIMIT: operation{ + GASLIMIT: { execute: opGasLimit, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - POP: operation{ + POP: { execute: opPop, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(1, 0), valid: true, }, - MLOAD: operation{ + MLOAD: { execute: opMload, gasCost: gasMLoad, validateStack: makeStackFunc(1, 1), memorySize: memoryMLoad, valid: true, }, - MSTORE: operation{ + MSTORE: { execute: opMstore, gasCost: gasMStore, validateStack: makeStackFunc(2, 0), memorySize: memoryMStore, valid: true, }, - MSTORE8: operation{ + MSTORE8: { execute: opMstore8, gasCost: gasMStore8, memorySize: memoryMStore8, @@ -336,71 +336,71 @@ func NewJumpTable() [256]operation { valid: true, }, - SLOAD: operation{ + SLOAD: { execute: opSload, gasCost: gasSLoad, validateStack: makeStackFunc(1, 1), valid: true, }, - SSTORE: operation{ + SSTORE: { execute: opSstore, gasCost: gasSStore, validateStack: makeStackFunc(2, 0), valid: true, }, - JUMPDEST: operation{ + JUMPDEST: { execute: opJumpdest, gasCost: constGasFunc(params.JumpdestGas), validateStack: makeStackFunc(0, 0), valid: true, }, - PC: operation{ + PC: { execute: opPc, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - MSIZE: operation{ + MSIZE: { execute: opMsize, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - GAS: operation{ + GAS: { execute: opGas, gasCost: constGasFunc(GasQuickStep), validateStack: makeStackFunc(0, 1), valid: true, }, - CREATE: operation{ + CREATE: { execute: opCreate, gasCost: gasCreate, validateStack: makeStackFunc(3, 1), memorySize: memoryCreate, valid: true, }, - CALL: operation{ + CALL: { execute: opCall, gasCost: gasCall, validateStack: makeStackFunc(7, 1), memorySize: memoryCall, valid: true, }, - CALLCODE: operation{ + CALLCODE: { execute: opCallCode, gasCost: gasCallCode, validateStack: makeStackFunc(7, 1), memorySize: memoryCall, valid: true, }, - DELEGATECALL: operation{ + DELEGATECALL: { execute: opDelegateCall, gasCost: gasDelegateCall, validateStack: makeStackFunc(6, 1), memorySize: memoryDelegateCall, valid: true, }, - RETURN: operation{ + RETURN: { execute: opReturn, gasCost: gasReturn, validateStack: makeStackFunc(2, 0), @@ -408,448 +408,448 @@ func NewJumpTable() [256]operation { halts: true, valid: true, }, - SUICIDE: operation{ + SUICIDE: { execute: opSuicide, gasCost: gasSuicide, validateStack: makeStackFunc(1, 0), halts: true, valid: true, }, - JUMP: operation{ + JUMP: { execute: opJump, gasCost: constGasFunc(GasMidStep), validateStack: makeStackFunc(1, 0), jumps: true, valid: true, }, - JUMPI: operation{ + JUMPI: { execute: opJumpi, gasCost: constGasFunc(GasSlowStep), validateStack: makeStackFunc(2, 0), jumps: true, valid: true, }, - STOP: operation{ + STOP: { execute: opStop, gasCost: constGasFunc(Zero), validateStack: makeStackFunc(0, 0), halts: true, valid: true, }, - LOG0: operation{ + LOG0: { execute: makeLog(0), gasCost: makeGasLog(0), validateStack: makeStackFunc(2, 0), memorySize: memoryLog, valid: true, }, - LOG1: operation{ + LOG1: { execute: makeLog(1), gasCost: makeGasLog(1), validateStack: makeStackFunc(3, 0), memorySize: memoryLog, valid: true, }, - LOG2: operation{ + LOG2: { execute: makeLog(2), gasCost: makeGasLog(2), validateStack: makeStackFunc(4, 0), memorySize: memoryLog, valid: true, }, - LOG3: operation{ + LOG3: { execute: makeLog(3), gasCost: makeGasLog(3), validateStack: makeStackFunc(5, 0), memorySize: memoryLog, valid: true, }, - LOG4: operation{ + LOG4: { execute: makeLog(4), gasCost: makeGasLog(4), validateStack: makeStackFunc(6, 0), memorySize: memoryLog, valid: true, }, - SWAP1: operation{ + SWAP1: { execute: makeSwap(1), gasCost: gasSwap, validateStack: makeStackFunc(2, 0), valid: true, }, - SWAP2: operation{ + SWAP2: { execute: makeSwap(2), gasCost: gasSwap, validateStack: makeStackFunc(3, 0), valid: true, }, - SWAP3: operation{ + SWAP3: { execute: makeSwap(3), gasCost: gasSwap, validateStack: makeStackFunc(4, 0), valid: true, }, - SWAP4: operation{ + SWAP4: { execute: makeSwap(4), gasCost: gasSwap, validateStack: makeStackFunc(5, 0), valid: true, }, - SWAP5: operation{ + SWAP5: { execute: makeSwap(5), gasCost: gasSwap, validateStack: makeStackFunc(6, 0), valid: true, }, - SWAP6: operation{ + SWAP6: { execute: makeSwap(6), gasCost: gasSwap, validateStack: makeStackFunc(7, 0), valid: true, }, - SWAP7: operation{ + SWAP7: { execute: makeSwap(7), gasCost: gasSwap, validateStack: makeStackFunc(8, 0), valid: true, }, - SWAP8: operation{ + SWAP8: { execute: makeSwap(8), gasCost: gasSwap, validateStack: makeStackFunc(9, 0), valid: true, }, - SWAP9: operation{ + SWAP9: { execute: makeSwap(9), gasCost: gasSwap, validateStack: makeStackFunc(10, 0), valid: true, }, - SWAP10: operation{ + SWAP10: { execute: makeSwap(10), gasCost: gasSwap, validateStack: makeStackFunc(11, 0), valid: true, }, - SWAP11: operation{ + SWAP11: { execute: makeSwap(11), gasCost: gasSwap, validateStack: makeStackFunc(12, 0), valid: true, }, - SWAP12: operation{ + SWAP12: { execute: makeSwap(12), gasCost: gasSwap, validateStack: makeStackFunc(13, 0), valid: true, }, - SWAP13: operation{ + SWAP13: { execute: makeSwap(13), gasCost: gasSwap, validateStack: makeStackFunc(14, 0), valid: true, }, - SWAP14: operation{ + SWAP14: { execute: makeSwap(14), gasCost: gasSwap, validateStack: makeStackFunc(15, 0), valid: true, }, - SWAP15: operation{ + SWAP15: { execute: makeSwap(15), gasCost: gasSwap, validateStack: makeStackFunc(16, 0), valid: true, }, - SWAP16: operation{ + SWAP16: { execute: makeSwap(16), gasCost: gasSwap, validateStack: makeStackFunc(17, 0), valid: true, }, - PUSH1: operation{ + PUSH1: { execute: makePush(1, big.NewInt(1)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH2: operation{ + PUSH2: { execute: makePush(2, big.NewInt(2)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH3: operation{ + PUSH3: { execute: makePush(3, big.NewInt(3)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH4: operation{ + PUSH4: { execute: makePush(4, big.NewInt(4)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH5: operation{ + PUSH5: { execute: makePush(5, big.NewInt(5)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH6: operation{ + PUSH6: { execute: makePush(6, big.NewInt(6)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH7: operation{ + PUSH7: { execute: makePush(7, big.NewInt(7)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH8: operation{ + PUSH8: { execute: makePush(8, big.NewInt(8)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH9: operation{ + PUSH9: { execute: makePush(9, big.NewInt(9)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH10: operation{ + PUSH10: { execute: makePush(10, big.NewInt(10)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH11: operation{ + PUSH11: { execute: makePush(11, big.NewInt(11)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH12: operation{ + PUSH12: { execute: makePush(12, big.NewInt(12)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH13: operation{ + PUSH13: { execute: makePush(13, big.NewInt(13)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH14: operation{ + PUSH14: { execute: makePush(14, big.NewInt(14)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH15: operation{ + PUSH15: { execute: makePush(15, big.NewInt(15)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH16: operation{ + PUSH16: { execute: makePush(16, big.NewInt(16)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH17: operation{ + PUSH17: { execute: makePush(17, big.NewInt(17)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH18: operation{ + PUSH18: { execute: makePush(18, big.NewInt(18)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH19: operation{ + PUSH19: { execute: makePush(19, big.NewInt(19)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH20: operation{ + PUSH20: { execute: makePush(20, big.NewInt(20)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH21: operation{ + PUSH21: { execute: makePush(21, big.NewInt(21)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH22: operation{ + PUSH22: { execute: makePush(22, big.NewInt(22)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH23: operation{ + PUSH23: { execute: makePush(23, big.NewInt(23)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH24: operation{ + PUSH24: { execute: makePush(24, big.NewInt(24)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH25: operation{ + PUSH25: { execute: makePush(25, big.NewInt(25)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH26: operation{ + PUSH26: { execute: makePush(26, big.NewInt(26)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH27: operation{ + PUSH27: { execute: makePush(27, big.NewInt(27)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH28: operation{ + PUSH28: { execute: makePush(28, big.NewInt(28)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH29: operation{ + PUSH29: { execute: makePush(29, big.NewInt(29)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH30: operation{ + PUSH30: { execute: makePush(30, big.NewInt(30)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH31: operation{ + PUSH31: { execute: makePush(31, big.NewInt(31)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - PUSH32: operation{ + PUSH32: { execute: makePush(32, big.NewInt(32)), gasCost: gasPush, validateStack: makeStackFunc(0, 1), valid: true, }, - DUP1: operation{ + DUP1: { execute: makeDup(1), gasCost: gasDup, validateStack: makeStackFunc(1, 1), valid: true, }, - DUP2: operation{ + DUP2: { execute: makeDup(2), gasCost: gasDup, validateStack: makeStackFunc(2, 1), valid: true, }, - DUP3: operation{ + DUP3: { execute: makeDup(3), gasCost: gasDup, validateStack: makeStackFunc(3, 1), valid: true, }, - DUP4: operation{ + DUP4: { execute: makeDup(4), gasCost: gasDup, validateStack: makeStackFunc(4, 1), valid: true, }, - DUP5: operation{ + DUP5: { execute: makeDup(5), gasCost: gasDup, validateStack: makeStackFunc(5, 1), valid: true, }, - DUP6: operation{ + DUP6: { execute: makeDup(6), gasCost: gasDup, validateStack: makeStackFunc(6, 1), valid: true, }, - DUP7: operation{ + DUP7: { execute: makeDup(7), gasCost: gasDup, validateStack: makeStackFunc(7, 1), valid: true, }, - DUP8: operation{ + DUP8: { execute: makeDup(8), gasCost: gasDup, validateStack: makeStackFunc(8, 1), valid: true, }, - DUP9: operation{ + DUP9: { execute: makeDup(9), gasCost: gasDup, validateStack: makeStackFunc(9, 1), valid: true, }, - DUP10: operation{ + DUP10: { execute: makeDup(10), gasCost: gasDup, validateStack: makeStackFunc(10, 1), valid: true, }, - DUP11: operation{ + DUP11: { execute: makeDup(11), gasCost: gasDup, validateStack: makeStackFunc(11, 1), valid: true, }, - DUP12: operation{ + DUP12: { execute: makeDup(12), gasCost: gasDup, validateStack: makeStackFunc(12, 1), valid: true, }, - DUP13: operation{ + DUP13: { execute: makeDup(13), gasCost: gasDup, validateStack: makeStackFunc(13, 1), valid: true, }, - DUP14: operation{ + DUP14: { execute: makeDup(14), gasCost: gasDup, validateStack: makeStackFunc(14, 1), valid: true, }, - DUP15: operation{ + DUP15: { execute: makeDup(15), gasCost: gasDup, validateStack: makeStackFunc(15, 1), valid: true, }, - DUP16: operation{ + DUP16: { execute: makeDup(16), gasCost: gasDup, validateStack: makeStackFunc(16, 1), diff --git a/core/vm/log.go b/core/vm/log.go deleted file mode 100644 index 347bd6e5d..000000000 --- a/core/vm/log.go +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright 2014 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -package vm - -import ( - "encoding/json" - "errors" - "fmt" - "io" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/rlp" -) - -var errMissingLogFields = errors.New("missing required JSON log fields") - -// Log represents a contract log event. These events are generated by the LOG opcode and -// stored/indexed by the node. -type Log struct { - // Consensus fields. - Address common.Address // address of the contract that generated the event - Topics []common.Hash // list of topics provided by the contract. - Data []byte // supplied by the contract, usually ABI-encoded - - // Derived fields. These fields are filled in by the node - // but not secured by consensus. - BlockNumber uint64 // block in which the transaction was included - TxHash common.Hash // hash of the transaction - TxIndex uint // index of the transaction in the block - BlockHash common.Hash // hash of the block in which the transaction was included - Index uint // index of the log in the receipt - - // The Removed field is true if this log was reverted due to a chain reorganisation. - // You must pay attention to this field if you receive logs through a filter query. - Removed bool -} - -type rlpLog struct { - Address common.Address - Topics []common.Hash - Data []byte -} - -type rlpStorageLog struct { - Address common.Address - Topics []common.Hash - Data []byte - BlockNumber uint64 - TxHash common.Hash - TxIndex uint - BlockHash common.Hash - Index uint -} - -type jsonLog struct { - Address *common.Address `json:"address"` - Topics *[]common.Hash `json:"topics"` - Data *hexutil.Bytes `json:"data"` - BlockNumber *hexutil.Uint64 `json:"blockNumber"` - TxIndex *hexutil.Uint `json:"transactionIndex"` - TxHash *common.Hash `json:"transactionHash"` - BlockHash *common.Hash `json:"blockHash"` - Index *hexutil.Uint `json:"logIndex"` - Removed bool `json:"removed"` -} - -func NewLog(address common.Address, topics []common.Hash, data []byte, number uint64) *Log { - return &Log{Address: address, Topics: topics, Data: data, BlockNumber: number} -} - -// EncodeRLP implements rlp.Encoder. -func (l *Log) EncodeRLP(w io.Writer) error { - return rlp.Encode(w, rlpLog{Address: l.Address, Topics: l.Topics, Data: l.Data}) -} - -// DecodeRLP implements rlp.Decoder. -func (l *Log) DecodeRLP(s *rlp.Stream) error { - var dec rlpLog - err := s.Decode(&dec) - if err == nil { - l.Address, l.Topics, l.Data = dec.Address, dec.Topics, dec.Data - } - return err -} - -func (l *Log) String() string { - return fmt.Sprintf(`log: %x %x %x %x %d %x %d`, l.Address, l.Topics, l.Data, l.TxHash, l.TxIndex, l.BlockHash, l.Index) -} - -// MarshalJSON implements json.Marshaler. -func (l *Log) MarshalJSON() ([]byte, error) { - jslog := &jsonLog{ - Address: &l.Address, - Topics: &l.Topics, - Data: (*hexutil.Bytes)(&l.Data), - TxIndex: (*hexutil.Uint)(&l.TxIndex), - TxHash: &l.TxHash, - Index: (*hexutil.Uint)(&l.Index), - Removed: l.Removed, - } - // Set block information for mined logs. - if (l.BlockHash != common.Hash{}) { - jslog.BlockHash = &l.BlockHash - jslog.BlockNumber = (*hexutil.Uint64)(&l.BlockNumber) - } - return json.Marshal(jslog) -} - -// UnmarshalJSON implements json.Umarshaler. -func (l *Log) UnmarshalJSON(input []byte) error { - var dec jsonLog - if err := json.Unmarshal(input, &dec); err != nil { - return err - } - if dec.Address == nil || dec.Topics == nil || dec.Data == nil || - dec.TxIndex == nil || dec.TxHash == nil || dec.Index == nil { - return errMissingLogFields - } - declog := Log{ - Address: *dec.Address, - Topics: *dec.Topics, - Data: *dec.Data, - TxHash: *dec.TxHash, - TxIndex: uint(*dec.TxIndex), - Index: uint(*dec.Index), - Removed: dec.Removed, - } - // Block information may be missing if the log is received through - // the pending log filter, so it's handled specially here. - if dec.BlockHash != nil && dec.BlockNumber != nil { - declog.BlockHash = *dec.BlockHash - declog.BlockNumber = uint64(*dec.BlockNumber) - } - *l = declog - return nil -} - -type Logs []*Log - -// LogForStorage is a wrapper around a Log that flattens and parses the entire content of -// a log including non-consensus fields. -type LogForStorage Log - -// EncodeRLP implements rlp.Encoder. -func (l *LogForStorage) EncodeRLP(w io.Writer) error { - return rlp.Encode(w, rlpStorageLog{ - Address: l.Address, - Topics: l.Topics, - Data: l.Data, - BlockNumber: l.BlockNumber, - TxHash: l.TxHash, - TxIndex: l.TxIndex, - BlockHash: l.BlockHash, - Index: l.Index, - }) -} - -// DecodeRLP implements rlp.Decoder. -func (l *LogForStorage) DecodeRLP(s *rlp.Stream) error { - var dec rlpStorageLog - err := s.Decode(&dec) - if err == nil { - *l = LogForStorage{ - Address: dec.Address, - Topics: dec.Topics, - Data: dec.Data, - BlockNumber: dec.BlockNumber, - TxHash: dec.TxHash, - TxIndex: dec.TxIndex, - BlockHash: dec.BlockHash, - Index: dec.Index, - } - } - return err -} diff --git a/core/vm/log_test.go b/core/vm/log_test.go deleted file mode 100644 index 994753c62..000000000 --- a/core/vm/log_test.go +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2016 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -package vm - -import ( - "encoding/json" - "reflect" - "testing" - - "github.com/davecgh/go-spew/spew" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" -) - -var unmarshalLogTests = map[string]struct { - input string - want *Log - wantError error -}{ - "ok": { - input: `{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","data":"0x000000000000000000000000000000000000000000000001a055690d9db80000","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`, - want: &Log{ - Address: common.HexToAddress("0xecf8f87f810ecf450940c9f60066b4a7a501d6a7"), - BlockHash: common.HexToHash("0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056"), - BlockNumber: 2019236, - Data: hexutil.MustDecode("0x000000000000000000000000000000000000000000000001a055690d9db80000"), - Index: 2, - TxIndex: 3, - TxHash: common.HexToHash("0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e"), - Topics: []common.Hash{ - common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"), - common.HexToHash("0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615"), - }, - }, - }, - "empty data": { - input: `{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","data":"0x","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`, - want: &Log{ - Address: common.HexToAddress("0xecf8f87f810ecf450940c9f60066b4a7a501d6a7"), - BlockHash: common.HexToHash("0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056"), - BlockNumber: 2019236, - Data: []byte{}, - Index: 2, - TxIndex: 3, - TxHash: common.HexToHash("0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e"), - Topics: []common.Hash{ - common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"), - common.HexToHash("0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615"), - }, - }, - }, - "missing block fields (pending logs)": { - input: `{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","data":"0x","logIndex":"0x0","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`, - want: &Log{ - Address: common.HexToAddress("0xecf8f87f810ecf450940c9f60066b4a7a501d6a7"), - BlockHash: common.Hash{}, - BlockNumber: 0, - Data: []byte{}, - Index: 0, - TxIndex: 3, - TxHash: common.HexToHash("0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e"), - Topics: []common.Hash{ - common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"), - }, - }, - }, - "Removed: true": { - input: `{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","data":"0x","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3","removed":true}`, - want: &Log{ - Address: common.HexToAddress("0xecf8f87f810ecf450940c9f60066b4a7a501d6a7"), - BlockHash: common.HexToHash("0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056"), - BlockNumber: 2019236, - Data: []byte{}, - Index: 2, - TxIndex: 3, - TxHash: common.HexToHash("0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e"), - Topics: []common.Hash{ - common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"), - }, - Removed: true, - }, - }, - "missing data": { - input: `{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615","0x000000000000000000000000f9dff387dcb5cc4cca5b91adb07a95f54e9f1bb6"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`, - wantError: errMissingLogFields, - }, -} - -func TestUnmarshalLog(t *testing.T) { - dumper := spew.ConfigState{DisableMethods: true, Indent: " "} - for name, test := range unmarshalLogTests { - var log *Log - err := json.Unmarshal([]byte(test.input), &log) - checkError(t, name, err, test.wantError) - if test.wantError == nil && err == nil { - if !reflect.DeepEqual(log, test.want) { - t.Errorf("test %q:\nGOT %sWANT %s", name, dumper.Sdump(log), dumper.Sdump(test.want)) - } - } - } -} - -func checkError(t *testing.T, testname string, got, want error) bool { - if got == nil { - if want != nil { - t.Errorf("test %q: got no error, want %q", testname, want) - return false - } - return true - } - if want == nil { - t.Errorf("test %q: unexpected error %q", testname, got) - } else if got.Error() != want.Error() { - t.Errorf("test %q: got error %q, want %q", testname, got, want) - } - return false -} diff --git a/core/vm/noop.go b/core/vm/noop.go index ca7d1055a..ef6837273 100644 --- a/core/vm/noop.go +++ b/core/vm/noop.go @@ -20,6 +20,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" ) func NoopCanTransfer(db StateDB, from common.Address, balance *big.Int) bool { @@ -65,4 +66,4 @@ func (NoopStateDB) Exist(common.Address) bool { return f func (NoopStateDB) Empty(common.Address) bool { return false } func (NoopStateDB) RevertToSnapshot(int) {} func (NoopStateDB) Snapshot() int { return 0 } -func (NoopStateDB) AddLog(*Log) {} +func (NoopStateDB) AddLog(*types.Log) {} |