Merge branch 'master' into EthTime

This commit is contained in:
coffeepots 2018-04-10 18:16:25 +01:00 committed by GitHub
commit 4a40cac4aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
73 changed files with 603 additions and 54 deletions

21
LICENSE-MIT Normal file
View File

@ -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.

View File

@ -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.

47
appveyor.yml Normal file
View File

@ -0,0 +1,47 @@
version: '{build}'
cache:
- x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z
- i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z
matrix:
fast_finish: true # set this flag to immediately finish build once one of the jobs fails.
environment:
matrix:
- MINGW_DIR: mingw32
MINGW_URL: https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.9.2/threads-win32/dwarf/i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z/download
MINGW_ARCHIVE: i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z
platform: x86
- MINGW_DIR: mingw64
MINGW_URL: https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.9.2/threads-win32/seh/x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z/download
MINGW_ARCHIVE: x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z
platform: x64
install:
- setlocal EnableExtensions EnableDelayedExpansion
- IF not exist "%MINGW_ARCHIVE%" appveyor DownloadFile "%MINGW_URL%" -FileName "%MINGW_ARCHIVE%"
- 7z x -y "%MINGW_ARCHIVE%" > nul
- SET PATH=%CD%\%MINGW_DIR%\bin;%CD%\Nim\bin;%PATH%
- git clone https://github.com/nim-lang/Nim.git
- cd %CD%\Nim
- git remote add statusim https://github.com/status-im/Nim.git
- git fetch statusim
- git config --global user.email "you@example.com"
- git config --global user.name "Your Name"
- for /f "tokens=*" %%G IN ('git branch -a --list ^"statusim/status-autopatch-*^"') DO (git merge %%G)
- git clone --depth 1 https://github.com/nim-lang/csources
- cd csources
- IF "%PLATFORM%" == "x64" ( build64.bat ) else ( build.bat )
- cd ..
- bin\nim c koch
- koch boot -d:release
- koch nimble
build_script:
- cd C:\projects\nimbus
- nimble install -y
test_script:
- nimble test
deploy: off

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,

Binary file not shown.

View File

@ -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

View File

@ -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))

View File

@ -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))

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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))

View File

@ -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

View File

@ -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], ttmath

Binary file not shown.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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`)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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
""
""

View File

@ -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)

View File

@ -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 =

View File

@ -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] =

View File

@ -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
@ -99,7 +107,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,

View File

@ -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 =

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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))

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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,

View File

@ -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 =

View File

@ -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

View File

@ -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]

View File

@ -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,

View File

@ -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]

View File

@ -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],

View File

@ -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]

View File

@ -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

View File

@ -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))