diff --git a/LICENSE b/LICENSE-APACHEv2 similarity index 100% rename from LICENSE rename to LICENSE-APACHEv2 diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000000..8766e65da9 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2018 Status Research & Development GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 3842475193..86fd4edbe1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # Nimbus -[![Build Status](https://travis-ci.org/status-im/nimbus.svg?branch=master)](https://travis-ci.org/status-im/nimbus) +[![Build Status (Travis)](https://img.shields.io/travis/status-im/nimbus/master.svg?label=Linux%20/%20macOS "Linux/macOS build status (Travis)")](https://travis-ci.org/status-im/nimbus) +[![Windows build status (Appveyor)](https://img.shields.io/appveyor/ci/jarradh/nimbus/master.svg?label=Windows "Windows build status (Appveyor)")](https://ci.appveyor.com/project/jarradh/nimbus)[![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) +![Stability: experimental](https://img.shields.io/badge/stability-experimental-orange.svg) An Ethereum 2.0 Sharding Client for Resource-Restricted Devices @@ -12,3 +15,12 @@ Join the Status community chats: Rationale https://docs.google.com/document/d/14u65XVNLOd83cq3t7wNC9UPweZ6kPWvmXwRTWWn0diQ/edit# + +## License + +Licensed under either of + + * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) + * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) + +at your option. diff --git a/src/account.nim b/src/account.nim index afb7d4a7ec..c8a3bde658 100644 --- a/src/account.nim +++ b/src/account.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import constants, errors, ttmath, rlp diff --git a/src/block_obj.nim b/src/block_obj.nim index 6d446ad913..3c0d169d6d 100644 --- a/src/block_obj.nim +++ b/src/block_obj.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import logging, constants, utils / header, ttmath diff --git a/src/chain.nim b/src/chain.nim index 1056aad6be..0a67c6e58e 100644 --- a/src/chain.nim +++ b/src/chain.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import tables, ttmath, logging, constants, errors, validation, utils / hexadecimal, vm / base, db / db_chain diff --git a/src/computation.nim b/src/computation.nim index 1d3c5cb663..3bb4c7b852 100644 --- a/src/computation.nim +++ b/src/computation.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, strutils, sequtils, tables, macros, ttmath, terminal, constants, errors, utils/hexadecimal, utils_numeric, validation, vm_state, logging, opcode_values, types, diff --git a/src/constants b/src/constants deleted file mode 100755 index b19fc23e7b..0000000000 Binary files a/src/constants and /dev/null differ diff --git a/src/db/backends/memory_backend.nim b/src/db/backends/memory_backend.nim index 8019e5db29..c83e851e7d 100644 --- a/src/db/backends/memory_backend.nim +++ b/src/db/backends/memory_backend.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import tables, ttmath type diff --git a/src/db/db_chain.nim b/src/db/db_chain.nim index 31273500fb..c8d0f593f3 100644 --- a/src/db/db_chain.nim +++ b/src/db/db_chain.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, tables, ttmath, state_db, backends / memory_backend type @@ -23,7 +30,7 @@ proc `$`*(db: BaseChainDB): string = # proc getCanonicalBlockHeaderByNumber*(self: BaseChainDB; blockNumber: int): BlockHeader = # ## Returns the block header with the given number in the canonical chain. -# ## +# ## # ## Raises BlockNotFound if there's no block header with the given number in the # ## canonical chain. # validateUint256(blockNumber) @@ -59,7 +66,7 @@ proc `$`*(db: BaseChainDB): string = # proc getBlockHeaderByHash*(self: BaseChainDB; blockHash: cstring): BlockHeader = # ## Returns the requested block header as specified by block hash. -# ## +# ## # ## Raises BlockNotFound if it is not present in the db. # validateWord(blockHash) # try: @@ -90,7 +97,7 @@ proc `$`*(db: BaseChainDB): string = # yield rlp.decode(receiptData) # else: # break - + # iterator getBlockTransactions*(self: BaseChainDB; blockHeader: BlockHeader; # transactionClass: typedesc): FrontierTransaction = # var transactionDb = HexaryTrie(self.db) @@ -101,7 +108,7 @@ proc `$`*(db: BaseChainDB): string = # yield rlp.decode(transactionData) # else: # break - + # proc addBlockNumberToHashLookup*(self: BaseChainDB; header: BlockHeader): void = # var blockNumberToHashKey = makeBlockNumberToHashLookupKey(header.blockNumber) # self.db.set(blockNumberToHashKey, rlp.encode(header.hash)) diff --git a/src/db/state_db.nim b/src/db/state_db.nim index 6c82581df9..474403bd3b 100644 --- a/src/db/state_db.nim +++ b/src/db/state_db.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, tables, ../constants, ../errors, ../validation, ../account, ../logging, ../utils_numeric, .. / utils / [padding, bytes, keccak], ttmath, rlp @@ -13,7 +20,7 @@ proc newAccountStateDB*(db: Table[string, string], readOnly: bool = false): Acco proc logger*(db: AccountStateDB): Logger = logging.getLogger("db.State") -proc getAccount(db: AccountStateDB, address: string): Account = +proc getAccount(db: AccountStateDB, address: string): Account = # let rlpAccount = db.trie[address] # if not rlpAccount.isNil: # account = rlp.decode[Account](rlpAccount) @@ -24,7 +31,7 @@ proc getAccount(db: AccountStateDB, address: string): Account = proc setAccount(db: AccountStateDB, address: string, account: Account) = # db.trie[address] = rlp.encode[Account](account) - discard # TODO + discard # TODO proc getCodeHash*(db: AccountStateDB, address: string): string = @@ -51,7 +58,7 @@ proc setStorage*(db: var AccountStateDB, address: string, slot: UInt256, value: #validateGte(value, 0, title="Storage Value") #validateGte(slot, 0, title="Storage Slot") validateCanonicalAddress(address, title="Storage Address") - + # TODO # let account = db.getAccount(address) # var storage = HashTrie(HexaryTrie(self.db, account.storageRoot)) @@ -71,11 +78,11 @@ proc setStorage*(db: var AccountStateDB, address: string, slot: UInt256, value: proc getStorage*(db: var AccountStateDB, address: string, slot: UInt256): (UInt256, bool) = validateCanonicalAddress(address, title="Storage Address") #validateGte(slot, 0, title="Storage Slot") - + # TODO # make it more correct # for now, we just use a table - + # let account = db.GetAccount(address) # var storage = HashTrie(HexaryTrie(self.db, account.storageRoot)) diff --git a/src/errors.nim b/src/errors.nim index b14fb82ce6..776abed69f 100644 --- a/src/errors.nim +++ b/src/errors.nim @@ -1,10 +1,17 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + type EVMError* = object of Exception ## Base error class for all evm errors. VMNotFound* = object of EVMError ## No VM available for the provided block number. - + BlockNotFound* = object of EVMError ## The block with the given number/hash does not exist. diff --git a/src/lightchain_shell.nim b/src/lightchain_shell.nim index e426215c07..caf19b7622 100644 --- a/src/lightchain_shell.nim +++ b/src/lightchain_shell.nim @@ -1 +1,8 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + # not implemented diff --git a/src/logging.nim b/src/logging.nim index 9a4e90e6a4..8caf9c04e8 100644 --- a/src/logging.nim +++ b/src/logging.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, terminal type diff --git a/src/logic/arithmetic.nim b/src/logic/arithmetic.nim index 3464d4f658..1b062674a6 100644 --- a/src/logic/arithmetic.nim +++ b/src/logic/arithmetic.nim @@ -1,4 +1,11 @@ -import +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + +import ../constants, ../utils_numeric, ../computation, ../types, .. / vm / [gas_meter, stack], ../opcode, ../opcode_values, helpers, ttmath, strutils @@ -6,7 +13,7 @@ import proc add*(computation: var BaseComputation) = # Addition var (left, right) = computation.stack.popInt(2) - + var res = (left + right) and UINT_256_MAX pushRes() @@ -79,7 +86,7 @@ proc sdiv*(computation: var BaseComputation) = proc exp*(computation: var BaseComputation) = # Exponentiation let (base, exponent) = computation.stack.popInt(2) - + var gasCost = GAS_EXP_BYTE.u256 #if exponent != 0: # gasCost += GAS_EXP_BYTE * (1 + log256(exponent)) diff --git a/src/logic/block.nim b/src/logic/block.nim index 1277921847..964e951c60 100644 --- a/src/logic/block.nim +++ b/src/logic/block.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ../constants, ../computation, ../vm/stack, ../vm_state, ttmath diff --git a/src/logic/block_ops.nim b/src/logic/block_ops.nim index 1292a1e887..5f80e0db0e 100644 --- a/src/logic/block_ops.nim +++ b/src/logic/block_ops.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ../constants, ../errors, ../computation, ../vm_state, ../types, .. / vm / [stack] diff --git a/src/logic/call b/src/logic/call deleted file mode 100755 index 150e8bcd6b..0000000000 Binary files a/src/logic/call and /dev/null differ diff --git a/src/logic/call.nim b/src/logic/call.nim index 5fdbb8b12b..a9d4ab64d3 100644 --- a/src/logic/call.nim +++ b/src/logic/call.nim @@ -1,6 +1,13 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, - ../constants, ../types, ../errors, ../computation, ../opcode, ../opcode_values, ../logging, + ../constants, ../types, ../errors, ../computation, ../opcode, ../opcode_values, ../logging, .. / vm / [stack, memory, gas_meter, message], .. / utils / [address, bytes], ttmath @@ -87,7 +94,7 @@ method runLogic*(call: BaseCall, computation) = # else: # code = state_db.get_code(to) let code = "" - + let childMsg = computation.prepareChildMessage( childMsgGas, to, @@ -96,7 +103,7 @@ method runLogic*(call: BaseCall, computation) = code, MessageOptions( shouldTransferValue: shouldTransferValue, - isStatic: isStatic)) + isStatic: isStatic)) if not sender.isNil: childMsg.sender = sender # let childComputation = computation.applyChildComputation(childMsg) @@ -120,7 +127,7 @@ method msgExtraGas(call: Call, computation; gas: UInt256, to: string, value: UIn # with computation.vm_state.state_db(read_only=True) as state_db: # let accountExists = db.accountExists(to) let accountExists = false - + let transferGasFee = if value != 0: GAS_CALL_VALUE else: 0.u256 let createGasFee = if not accountExists: GAS_NEW_ACCOUNT else: 0.u256 transferGasFee + createGasFee diff --git a/src/logic/comparison.nim b/src/logic/comparison.nim index ee1cbed9fb..a8057edcd6 100644 --- a/src/logic/comparison.nim +++ b/src/logic/comparison.nim @@ -1,9 +1,16 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ../constants, ../utils_numeric, ../computation, ../vm/stack, ../types, helpers, ttmath quasiBoolean(lt, `<`) # Lesser Comparison - + quasiBoolean(gt, `>`) # Greater Comparison quasiBoolean(slt, `<`, signed=true) # Signed Lesser Comparison diff --git a/src/logic/context.nim b/src/logic/context.nim index b4d0d16d41..e69f611193 100644 --- a/src/logic/context.nim +++ b/src/logic/context.nim @@ -1,6 +1,13 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, - ../constants, ../types, ../errors, ../utils_numeric, ../computation, ../vm_state, ../account, ../db/state_db, ../validation, + ../constants, ../types, ../errors, ../utils_numeric, ../computation, ../vm_state, ../account, ../db/state_db, ../validation, .. / vm / [stack, message, gas_meter, memory, code_stream], .. / utils / [address, padding, bytes], ttmath proc balance*(computation: var BaseComputation) = @@ -106,10 +113,10 @@ proc returnDataSize*(computation: var BaseComputation) = proc returnDataCopy*(computation: var BaseComputation) = let (memStartPosition, returnDataStartPosition, size) = computation.stack.popInt(3) if returnDataStartPosition + size > computation.returnData.len: - raise newException(OutOfBoundsRead, + raise newException(OutOfBoundsRead, "Return data length is not sufficient to satisfy request. Asked \n" & &"for data from index {returnDataStartPosition} to {returnDataStartPosition + size}. Return data is {computation.returnData.len} in \n" & - "length") + "length") computation.extendMemory(memStartPosition, size) let wordCount = ceil32(size) div 32 diff --git a/src/logic/duplication.nim b/src/logic/duplication.nim index 1d8d25a324..c1dfd00c4a 100644 --- a/src/logic/duplication.nim +++ b/src/logic/duplication.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import macros, strformat, ../types, ../computation, ../vm/stack diff --git a/src/logic/flow.nim b/src/logic/flow.nim index 9e58462b10..805b0346b9 100644 --- a/src/logic/flow.nim +++ b/src/logic/flow.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, ttmath, ../constants, ../types, ../opcode_values, ../logging, ../errors, ../computation, .. /vm / [code_stream, stack] diff --git a/src/logic/helpers.nim b/src/logic/helpers.nim index 129cc4c706..f72d8a85b5 100644 --- a/src/logic/helpers.nim +++ b/src/logic/helpers.nim @@ -1,6 +1,12 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import macros - macro pushRes*: untyped = let resNode = ident("res") result = quote: @@ -30,6 +36,6 @@ macro quasiBoolean*(name: untyped, op: untyped, signed: untyped = nil, nonzero: proc `name`*(computation: var BaseComputation) = var (`leftNode`, `rightNode`) = computation.stack.popInt(2) `signedNode` - + var `resNode` = if `test`: 1.u256 else: 0.u256 computation.stack.push(`resNode`) diff --git a/src/logic/invalid.nim b/src/logic/invalid.nim index b8303fa823..05bd78b313 100644 --- a/src/logic/invalid.nim +++ b/src/logic/invalid.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ../errors, ../types, ../computation diff --git a/src/logic/logging_ops.nim b/src/logic/logging_ops.nim index 9ba5498ddb..c5a1d3bcfa 100644 --- a/src/logic/logging_ops.nim +++ b/src/logic/logging_ops.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, macros, ../constants, ../errors, ../types, ../computation, .. / vm / [stack, memory, gas_meter, message], .. / utils / bytes, ttmath diff --git a/src/logic/memory_ops.nim b/src/logic/memory_ops.nim index fbc20cadd5..6719accade 100644 --- a/src/logic/memory_ops.nim +++ b/src/logic/memory_ops.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ../constants, ../computation, ../types, .. / vm / [stack, memory], .. / utils / [padding, bytes] @@ -14,7 +21,7 @@ proc mstoreX(computation; x: int) = let paddedValue = padLeft(value, x, 0.byte) let normalizedValue = paddedValue[^x .. ^1] - + extendMemory(start, x.u256) memory.write(start, 32.u256, normalizedValue) diff --git a/src/logic/sha3.nim b/src/logic/sha3.nim index ff8823ca49..e517095e76 100644 --- a/src/logic/sha3.nim +++ b/src/logic/sha3.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ../constants, ../utils_numeric, .. / utils / [keccak, bytes], .. / vm / [stack, memory, gas_meter], ../computation, ../types, helpers, ttmath diff --git a/src/logic/stack_ops.nim b/src/logic/stack_ops.nim index 08608fd263..8f62d503b3 100644 --- a/src/logic/stack_ops.nim +++ b/src/logic/stack_ops.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, macros, sequtils, ../types, ../constants, ../errors, ../computation, .. / vm / [stack, code_stream], .. / utils / [padding, bytes], ttmath diff --git a/src/logic/storage.nim b/src/logic/storage.nim index 97f72b903a..04a5ffb246 100644 --- a/src/logic/storage.nim +++ b/src/logic/storage.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ../constants, ../types, ../errors, ../computation, ../vm_state, ../utils/header, diff --git a/src/logic/swap.nim b/src/logic/swap.nim index 31f4504eb0..950d8a5c63 100644 --- a/src/logic/swap.nim +++ b/src/logic/swap.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import macros, strformat, ../types, ../computation, ../vm/stack diff --git a/src/logic/system_ops.nim b/src/logic/system_ops.nim index 5ec42b2849..3ac81a14e2 100644 --- a/src/logic/system_ops.nim +++ b/src/logic/system_ops.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, ../constants, ../types, ../errors, ../computation, ../opcode, ../opcode_values, ../logging, ../vm_state, call, diff --git a/src/opcode.nim b/src/opcode.nim index a5c2e94abc..3d839f4f96 100644 --- a/src/opcode.nim +++ b/src/opcode.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, strutils, sequtils, macros, constants, logging, errors, types, opcode_values, computation, vm/stack, ttmath @@ -63,6 +70,6 @@ macro initOpcodes*(spec: untyped): untyped = quote: `value`[`op`] = Opcode(kind: `op`, gasCostConstant: `gasCost`, runLogic: `handler`) result[1].add(opcode) - + result[1].add(value) diff --git a/src/opcode_table.nim b/src/opcode_table.nim index 169248e53a..f46bf600ff 100644 --- a/src/opcode_table.nim +++ b/src/opcode_table.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, strutils, tables, macros, constants, ttmath, errors, logging, vm_state, @@ -32,7 +39,7 @@ var OPCODE_TABLE* = initOpcodes: Op.Not: GAS_VERY_LOW notOp Op.Byte: GAS_VERY_LOW byteOp - + # sha3 Op.SHA3: GAS_SHA3 sha3op @@ -59,7 +66,7 @@ var OPCODE_TABLE* = initOpcodes: Op.Number: GAS_BASE number Op.Difficulty: GAS_BASE difficulty Op.GasLimit: GAS_BASE gaslimit - + # stack Op.Pop: GAS_BASE stack_ops.pop diff --git a/src/opcode_values.nim b/src/opcode_values.nim index 2430ae37d3..b706151b1b 100644 --- a/src/opcode_values.nim +++ b/src/opcode_values.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + type Op* {.pure.} = enum STOP = 0x0, # 0 @@ -26,7 +33,7 @@ type BYTE, # 26 SHA3 = 0x20, # 32 - + ADDRESS = 0x30,# 48 BALANCE, # 49 ORIGIN, # 50 @@ -59,7 +66,7 @@ type DIFFICULTY, # 68 GASLIMIT, # 69 - + POP = 0x50, # 80 MLOAD, # 81 @@ -79,7 +86,7 @@ type GAS, # 90 JUMPDEST, # 91 - + PUSH1 = 0x60, # 96 PUSH2, # 97 PUSH3, # 98 diff --git a/src/runner.nim b/src/runner.nim index f9f16f5953..c1fde5f533 100644 --- a/src/runner.nim +++ b/src/runner.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, strutils, tables, macros, constants, ttmath, errors, logging, vm_state, opcode_table, diff --git a/src/transaction.nim b/src/transaction.nim index 4926c370fb..8fb448ff6f 100644 --- a/src/transaction.nim +++ b/src/transaction.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import constants, ttmath, errors @@ -33,4 +40,4 @@ proc validate*(t: BaseTransaction) = proc sender*(t: BaseTransaction): string = # TODO - "" \ No newline at end of file + "" diff --git a/src/types.nim b/src/types.nim index 1c5bcdf6e7..0a80a9b79e 100644 --- a/src/types.nim +++ b/src/types.nim @@ -1,6 +1,13 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import tables, - constants, vm_state, + constants, vm_state, opcode_values, ttmath, vm / [code_stream, gas_meter, memory, message, stack] @@ -37,6 +44,6 @@ type ## that's what parity does: ## it uses the peek methods of the stack and calculates the cost ## then it actually pops/pushes stuff in exec - ## I followed the py-evm approach which does that in opcode logic + ## I followed the py-evm approach which does that in opcode logic gasCostConstant*: UInt256 runLogic*: proc(computation: var BaseComputation) diff --git a/src/utils/address.nim b/src/utils/address.nim index 3151a9ae58..ebc4520160 100644 --- a/src/utils/address.nim +++ b/src/utils/address.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, strutils, encodings, keccak, padding proc toText*(c: cstring): string = diff --git a/src/utils/bytes.nim b/src/utils/bytes.nim index 666456bcf1..2923477587 100644 --- a/src/utils/bytes.nim +++ b/src/utils/bytes.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strutils, sequtils # proc toBytes*(value: cstring): seq[byte] = diff --git a/src/utils/header.nim b/src/utils/header.nim index bd9f564258..e62ecba67d 100644 --- a/src/utils/header.nim +++ b/src/utils/header.nim @@ -1,3 +1,11 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + + import ../constants, ttmath, strformat, times, ../validation type @@ -100,7 +108,7 @@ proc generateHeaderFromParentHeader*( result = Header( timestamp: max(getTime(), parent.timestamp + 1.milliseconds), # Note: Py-evm uses +1 second, not ms block_number: (parent.block_number + u256(1)), - # TODO: difficulty: parent.computeDifficulty(parent.timestamp), + # TODO: difficulty: parent.computeDifficulty(parent.timestamp), #[TODO: Make field? Or do we need to keep as a proc? gas_limit: computeGasLimit( parent, diff --git a/src/utils/hexadecimal.nim b/src/utils/hexadecimal.nim index 47789a647e..4b7f71b295 100644 --- a/src/utils/hexadecimal.nim +++ b/src/utils/hexadecimal.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strutils proc encodeHex*(value: string): string = diff --git a/src/utils/keccak.nim b/src/utils/keccak.nim index ec35b24c13..e81ea933d3 100644 --- a/src/utils/keccak.nim +++ b/src/utils/keccak.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import keccak_tiny, strutils @@ -7,4 +14,3 @@ template keccak*(value: string): string = template keccak*(value: cstring): string = ($value).keccak - \ No newline at end of file diff --git a/src/utils/padding.nim b/src/utils/padding.nim index 5641821ab1..5f6c4f0255 100644 --- a/src/utils/padding.nim +++ b/src/utils/padding.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, strutils proc repeat*(b: cstring, count: int): cstring = @@ -95,7 +102,7 @@ proc rStrip*(value: cstring, c: char): cstring = elif z == -1: result = cstring"" else: - result = cstring(($value)[0..z]) + result = cstring(($value)[0..z]) proc strip*(value: cstring, c: char): cstring = result = value.lStrip(c).rStrip(c) diff --git a/src/utils/state.nim b/src/utils/state.nim index bf8d4a8f3b..99849e09db 100644 --- a/src/utils/state.nim +++ b/src/utils/state.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + # import # eth_utils, rlp, trie, evm.db.backends.memory, evm.db.chain diff --git a/src/utils_numeric.nim b/src/utils_numeric.nim index 748c232c8d..af53479f76 100644 --- a/src/utils_numeric.nim +++ b/src/utils_numeric.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ttmath, constants, strformat, strutils, sequtils, endians, macros, utils / padding, rlp # some methods based on py-evm utils/numeric @@ -9,7 +16,7 @@ proc intToBigEndian*(value: UInt256): Bytes = for z in 0 ..< 4: var temp = value.table[z] bigEndian64(result[24 - z * 8].addr, temp.addr) - + proc bigEndianToInt*(value: Bytes): UInt256 = var bytes = value.padLeft(32, 0.byte) result = 0.u256 diff --git a/src/validation.nim b/src/validation.nim index c9ab05eeae..0cfebc6f7f 100644 --- a/src/validation.nim +++ b/src/validation.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, errors, constants, ttmath diff --git a/src/vm/base.nim b/src/vm/base.nim index 7c05b40511..275878e989 100644 --- a/src/vm/base.nim +++ b/src/vm/base.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ../logging, ../constants, ../errors, ../transaction, ../types, ../computation, ../block_obj, ../vm_state, ../vm_state_transactions, ../db/db_chain, ../utils/header diff --git a/src/vm/code_stream.nim b/src/vm/code_stream.nim index 45632dd4d9..b17517c66d 100644 --- a/src/vm/code_stream.nim +++ b/src/vm/code_stream.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, strutils, sequtils, parseutils, sets, macros, ../logging, ../constants, ../opcode_values diff --git a/src/vm/forks/frontier/frontier_block.nim b/src/vm/forks/frontier/frontier_block.nim index 8528f52bb7..468eb27084 100644 --- a/src/vm/forks/frontier/frontier_block.nim +++ b/src/vm/forks/frontier/frontier_block.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ../../../logging, ../../../constants, ../../../errors, ../../../transaction, ../../../block_obj, diff --git a/src/vm/forks/frontier/frontier_headers.nim b/src/vm/forks/frontier/frontier_headers.nim index 7e75bcf212..56cdb85c9a 100644 --- a/src/vm/forks/frontier/frontier_headers.nim +++ b/src/vm/forks/frontier/frontier_headers.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import logging, constants, errors, validation, utils/header, vm / forks / frontier / vm @@ -15,7 +22,7 @@ method computeDifficulty*(parentHeader: Header, timestamp: int): Int256 = # result = if numBombPeriods >= 0: max(baseDifficulty + 2.Int256 ^ numBombPeriods, DIFFICULTY_MINIMUM) else: baseDifficulty result = 0.Int256 -method createHeaderFromParent*(parentHeader: Header): Header = +method createHeaderFromParent*(parentHeader: Header): Header = # TODO result = Header() diff --git a/src/vm/forks/frontier/frontier_validation.nim b/src/vm/forks/frontier/frontier_validation.nim index 4e0b9dad31..7c6ecbf6fe 100644 --- a/src/vm/forks/frontier/frontier_validation.nim +++ b/src/vm/forks/frontier/frontier_validation.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, ttmath, ../../../constants, ../../../errors, ../../../vm_state, ../../../transaction, ../../../utils/header diff --git a/src/vm/forks/frontier/frontier_vm_state.nim b/src/vm/forks/frontier/frontier_vm_state.nim index b0e863dba4..d0cfe96f23 100644 --- a/src/vm/forks/frontier/frontier_vm_state.nim +++ b/src/vm/forks/frontier/frontier_vm_state.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ../../../logging, ../../../constants, ../../../errors, ../../../vm_state, ../../../utils/header, ../../../db/db_chain diff --git a/src/vm/forks/frontier/vm.nim b/src/vm/forks/frontier/vm.nim index 6a711f3810..38a79b2814 100644 --- a/src/vm/forks/frontier/vm.nim +++ b/src/vm/forks/frontier/vm.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ../../../logging, ../../../constants, ../../../errors, ttmath, diff --git a/src/vm/gas_costs.nim b/src/vm/gas_costs.nim index f13239ae79..aff64da783 100644 --- a/src/vm/gas_costs.nim +++ b/src/vm/gas_costs.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, ttmath, ../types, ../constants, ../opcode, ../computation, stack @@ -5,4 +12,4 @@ import proc expGasCost*(computation: var BaseComputation): UInt256 = let arg = computation.stack.getInt(0) result = if arg == 0: 10.u256 else: (10.u256 + 10.u256 * (1.u256 + arg.log256)) - + diff --git a/src/vm/gas_meter.nim b/src/vm/gas_meter.nim index e4e82a96c7..1ae29f1845 100644 --- a/src/vm/gas_meter.nim +++ b/src/vm/gas_meter.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, ../logging, ../errors, ../constants, ttmath diff --git a/src/vm/memory.nim b/src/vm/memory.nim index 4b7a7cf30c..bb45ba966e 100644 --- a/src/vm/memory.nim +++ b/src/vm/memory.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import sequtils, ttmath, ../constants, ../errors, ../logging, ../validation, ../utils_numeric, ../utils/bytes @@ -34,7 +41,7 @@ proc read*(memory: var Memory, startPosition: UInt256, size: UInt256): seq[byte] proc write*(memory: var Memory, startPosition: UInt256, size: UInt256, value: seq[byte]) = if size == 0: return - #echo size + #echo size #echo startPosition #validateGte(startPosition, 0) #validateGte(size, 0) diff --git a/src/vm/message.nim b/src/vm/message.nim index 64ca295fab..354abc11db 100644 --- a/src/vm/message.nim +++ b/src/vm/message.nim @@ -1,10 +1,17 @@ -import +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + +import ../logging, ../constants, ../validation, ttmath type Message* = ref object # A message for VM computation - + # depth = None # code = None @@ -20,7 +27,7 @@ type gas*: UInt256 gasPrice*: UInt256 to*: string - sender*: string + sender*: string value*: UInt256 data*: seq[byte] code*: string @@ -74,11 +81,11 @@ proc newMessage*( data: seq[byte], code: string, options: MessageOptions = newMessageOptions()): Message = - + new(result) result.gas = gas result.gasPrice = gasPrice - + if to != CREATE_CONTRACT_ADDRESS: validateCanonicalAddress(to, title="Message.to") result.to = to diff --git a/src/vm/stack.nim b/src/vm/stack.nim index 3eac36ed46..87e31bc7a7 100644 --- a/src/vm/stack.nim +++ b/src/vm/stack.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, strutils, sequtils, macros, rlp, value, ../errors, ../validation, ../utils_numeric, ../constants, ttmath, ../logging, .. / utils / bytes @@ -68,7 +75,7 @@ proc push*(stack: var Stack, value: Bytes) = stack.values.add(value.toType(UInt256)) proc internalPop(stack: var Stack, numItems: int): seq[UInt256] = - if len(stack) < numItems: + if len(stack) < numItems: result = @[] else: result = stack.values[^numItems .. ^1] @@ -76,9 +83,9 @@ proc internalPop(stack: var Stack, numItems: int): seq[UInt256] = proc internalPop(stack: var Stack, numItems: int, T: typedesc): seq[T] = result = @[] - if len(stack) < numItems: + if len(stack) < numItems: return - + for z in 0 ..< numItems: var value = stack.values.pop() result.add(toType(value, T)) @@ -127,7 +134,7 @@ macro popInt*(stack: typed, numItems: static[int]): untyped = var name = ident(&"internalPopTuple{numItems}") result = quote: `name`(`stack`, UInt256) - + proc popBinary*(stack: var Stack): Bytes = var elements = stack.internalPop(1, Bytes) ensurePop(elements, 1) diff --git a/src/vm/value.nim b/src/vm/value.nim index f93bb5bfb0..2bf236e3fe 100644 --- a/src/vm/value.nim +++ b/src/vm/value.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, strutils, sequtils, ../constants, ttmath diff --git a/src/vm_state.nim b/src/vm_state.nim index 0a6d4f137f..ee63c2b5db 100644 --- a/src/vm_state.nim +++ b/src/vm_state.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import macros, strformat, tables, logging, constants, ttmath, errors, transaction, db/db_chain, utils/state, utils/header diff --git a/src/vm_state_transactions.nim b/src/vm_state_transactions.nim index 2e85632fc6..bb48892142 100644 --- a/src/vm_state_transactions.nim +++ b/src/vm_state_transactions.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import strformat, tables, logging, constants, errors, computation, transaction, types, vm_state, block_obj, db / db_chain, utils / [state, header] diff --git a/tests/all_tests.nim b/tests/all_tests.nim index f42629fa7d..236ce65a46 100644 --- a/tests/all_tests.nim +++ b/tests/all_tests.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import ./test_code_stream, ./test_gas_meter, ./test_memory, diff --git a/tests/fixtures.nim b/tests/fixtures.nim index a947602b13..a354abe17e 100644 --- a/tests/fixtures.nim +++ b/tests/fixtures.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import unittest, strformat, tables, constants, chain, ttmath, vm / forks / frontier / vm, utils / [header, address], db / db_chain, db / backends / memory_backend proc chainWithoutBlockValidation: Chain = diff --git a/tests/test_code_stream.nim b/tests/test_code_stream.nim index 972ac90d6c..1341d8831c 100644 --- a/tests/test_code_stream.nim +++ b/tests/test_code_stream.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import unittest, strutils, sequtils, ../src/opcode_values, ../src/vm/code_stream diff --git a/tests/test_gas_meter.nim b/tests/test_gas_meter.nim index d43b7f13f8..659da3b963 100644 --- a/tests/test_gas_meter.nim +++ b/tests/test_gas_meter.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import unittest, macros, strformat, strutils, sequtils, ttmath, ../src/[constants, opcode_values, errors, logging, vm/gas_meter] diff --git a/tests/test_helpers.nim b/tests/test_helpers.nim index f1853486f1..3710b352a8 100644 --- a/tests/test_helpers.nim +++ b/tests/test_helpers.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import os, macros, json, strformat, strutils, parseutils, ospaths, tables, ttmath, diff --git a/tests/test_memory.nim b/tests/test_memory.nim index 0e2a87bbbd..6997f01a43 100644 --- a/tests/test_memory.nim +++ b/tests/test_memory.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import unittest, macros, strformat, strutils, sequtils, ttmath, ../src/[constants, opcode_values, errors, vm/memory] diff --git a/tests/test_opcode.nim b/tests/test_opcode.nim index 3e4325fc89..3dff6afa79 100644 --- a/tests/test_opcode.nim +++ b/tests/test_opcode.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import unittest, ttmath, tables, parseutils, ../src/[constants, types, errors, logging], diff --git a/tests/test_stack.nim b/tests/test_stack.nim index 1d0b716ea1..e19f9cfb09 100644 --- a/tests/test_stack.nim +++ b/tests/test_stack.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import unittest, macros, strformat, strutils, sequtils, ttmath, ../src/[constants, opcode_values, errors, utils_numeric, vm/stack, vm/value, utils/bytes, utils/padding] diff --git a/tests/test_vm.nim b/tests/test_vm.nim index 3267ca9838..b33bc323e1 100644 --- a/tests/test_vm.nim +++ b/tests/test_vm.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import unittest, test_helpers, .. / src / [db / backends / memory, db / chain, constants, utils / hexadecimal] @@ -10,12 +17,12 @@ suite "vm": txIdx = len(vm.`block`.transactions) recipient = decodeHex("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0c") amount = 100.Int256 - + var from = chain.fundedAddress var tx = newTransaction(vm, from, recipient, amount, chain.fundedAddressPrivateKey) var (computation, _) = vm.applyTransaction(tx) var accessLogs = computation.vmState.accessLogs - + check(not computation.isError) var txGas = tx.gasPrice * constants.GAS_TX diff --git a/tests/test_vm_json.nim b/tests/test_vm_json.nim index 159385e377..b07fab0857 100644 --- a/tests/test_vm_json.nim +++ b/tests/test_vm_json.nim @@ -1,3 +1,10 @@ +# Nimbus +# Copyright (c) 2018 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import unittest, strformat, strutils, sequtils, tables, ttmath, json, test_helpers, constants, errors, logging, ospaths, @@ -21,7 +28,7 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) = blockNumber: fixture{"env"}{"currentNumber"}.getHexadecimalInt.u256, gasLimit: fixture{"env"}{"currentGasLimit"}.getHexadecimalInt.u256, timestamp: fixture{"env"}{"currentTimestamp"}.getHexadecimalInt) - + var code = "" vm.state.db(readOnly=false): setupStateDB(fixture{"pre"}, db) @@ -71,8 +78,8 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) = let expectedGasRemaining = fixture{"gas"}.getHexadecimalInt.u256 let actualGasRemaining = gasMeter.gasRemaining checkpoint(&"{actualGasRemaining} {expectedGasRemaining}") - check(actualGasRemaining == expectedGasRemaining or - computation.code.hasSStore() and + check(actualGasRemaining == expectedGasRemaining or + computation.code.hasSStore() and (actualGasRemaining > expectedGasRemaining and (actualGasRemaining - expectedGasRemaining) mod 15_000 == 0 or expectedGasRemaining > actualGasRemaining and (expectedGasRemaining - actualGasRemaining) mod 15_000 == 0))