Merge branch 'nim_v1'

This commit is contained in:
Ștefan Talpalaru 2019-10-29 00:21:08 +01:00
commit ce9e656e91
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
11 changed files with 51 additions and 36 deletions

View File

@ -1,5 +1,7 @@
language: c
dist: bionic
# https://docs.travis-ci.com/user/caching/
cache:
directories:
@ -29,6 +31,7 @@ matrix:
# (also used to get a different cache key than the amd64 one)
before_install:
- export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
- sudo apt-get -q update
- sudo apt-get install -y libpcre3-dev
- os: osx
env:
@ -42,6 +45,7 @@ install:
script:
- set -e # fail fast
- make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}" update # to allow a newer Nim version to be detected
- make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}"
- build/nimbus --help
- make -j${NPROC} NIMFLAGS="--parallelBuild:${NPROC}" test test-reproducibility

View File

@ -247,7 +247,7 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
let
source = send.source.toAddress
destination = send.to.toAddress
data = send.data.string.fromHex
data = nimcrypto.utils.fromHex(send.data.string)
contractCreation = false # TODO: Check if has code
v = 0.byte # TODO
r = 0.u256
@ -322,7 +322,7 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
# if no wallets, remains as ZERO_ADDRESS
# TODO: Wallets
destination = if call.to.isSome: call.to.get.toAddress else: ZERO_ADDRESS
data = if call.data.isSome: call.data.get.string.fromHex else: @[]
data = if call.data.isSome: nimcrypto.utils.fromHex(call.data.get.string) else: @[]
value = if call.value.isSome: call.value.get else: 0.u256
comp = setupComputation(vmState, header.blockNumber, value, data, sender, destination, gasLimit, gasPrice, call.to.isNone)

View File

@ -69,13 +69,13 @@ type
c_isNewAccount*: bool
c_gasBalance*: GasInt
c_contractGas*: Uint256
c_currentMemSize*: Natural
c_memOffset*: Natural
c_memLength*: Natural
c_currentMemSize*: GasNatural
c_memOffset*: GasNatural
c_memLength*: GasNatural
of Create:
cr_currentMemSize*: Natural
cr_memOffset*: Natural
cr_memLength*: Natural
cr_currentMemSize*: GasNatural
cr_memOffset*: GasNatural
cr_memLength*: GasNatural
of SelfDestruct:
sd_condition*: bool
else:
@ -99,7 +99,7 @@ type
of GckDynamic:
d_handler*: proc(value: Uint256): GasInt {.nimcall, gcsafe.}
of GckMemExpansion:
m_handler*: proc(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall, gcsafe.}
m_handler*: proc(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall, gcsafe.}
of GckComplex:
c_handler*: proc(value: Uint256, gasParams: GasParams): GasResult {.nimcall, gcsafe.}
# We use gasCost/gasRefund for:
@ -118,7 +118,7 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
# ############### Helper functions ##############################
func `prefix gasMemoryExpansion`(currentMemSize, memOffset, memLength: Natural): GasInt {.inline.} =
func `prefix gasMemoryExpansion`(currentMemSize, memOffset, memLength: GasNatural): GasInt {.inline.} =
# Input: size (in bytes)
# Yellow Paper:
@ -185,23 +185,23 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
gasParams.cr_memOffset,
gasParams.cr_memLength)
func `prefix gasSha3`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
func `prefix gasSha3`(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall.} =
result = `prefix gasMemoryExpansion`(currentMemSize, memOffset, memLength)
result += static(FeeSchedule[GasSha3]) +
static(FeeSchedule[GasSha3Word]) * (memLength).wordCount
func `prefix gasCopy`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
func `prefix gasCopy`(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall.} =
result = static(FeeSchedule[GasVeryLow]) +
static(FeeSchedule[GasCopy]) * memLength.wordCount
result += `prefix gasMemoryExpansion`(currentMemSize, memOffset, memLength)
func `prefix gasExtCodeCopy`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
func `prefix gasExtCodeCopy`(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall.} =
result = static(FeeSchedule[GasExtCode]) +
static(FeeSchedule[GasCopy]) * memLength.wordCount
result += `prefix gasMemoryExpansion`(currentMemSize, memOffset, memLength)
func `prefix gasLoadStore`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
func `prefix gasLoadStore`(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall.} =
result = static(FeeSchedule[GasVeryLow])
result += `prefix gasMemoryExpansion`(currentMemSize, memOffset, memLength)
@ -223,34 +223,34 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
if value.isZero and not gasParams.s_isStorageEmpty:
result.gasRefund = static(FeeSchedule[RefundSclear])
func `prefix gasLog0`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
func `prefix gasLog0`(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall.} =
result = `prefix gasMemoryExpansion`(currentMemSize, memOffset, memLength)
result += static(FeeSchedule[GasLog]) +
static(FeeSchedule[GasLogData]) * memLength
func `prefix gasLog1`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
func `prefix gasLog1`(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall.} =
result = `prefix gasMemoryExpansion`(currentMemSize, memOffset, memLength)
result += static(FeeSchedule[GasLog]) +
static(FeeSchedule[GasLogData]) * memLength +
static(FeeSchedule[GasLogTopic])
func `prefix gasLog2`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
func `prefix gasLog2`(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall.} =
result = `prefix gasMemoryExpansion`(currentMemSize, memOffset, memLength)
result += static(FeeSchedule[GasLog]) +
static(FeeSchedule[GasLogData]) * memLength +
static(2 * FeeSchedule[GasLogTopic])
func `prefix gasLog3`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
func `prefix gasLog3`(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall.} =
result = `prefix gasMemoryExpansion`(currentMemSize, memOffset, memLength)
result += static(FeeSchedule[GasLog]) +
static(FeeSchedule[GasLogData]) * memLength +
static(3 * FeeSchedule[GasLogTopic])
func `prefix gasLog4`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
func `prefix gasLog4`(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall.} =
result = `prefix gasMemoryExpansion`(currentMemSize, memOffset, memLength)
result += static(FeeSchedule[GasLog]) +
@ -343,7 +343,7 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
if not value.isZero and gasParams.kind in {Call, CallCode}:
result.gasRefund += static(FeeSchedule[GasCallStipend])
func `prefix gasHalt`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
func `prefix gasHalt`(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall.} =
`prefix gasMemoryExpansion`(currentMemSize, memOffset, memLength)
func `prefix gasSelfDestruct`(value: Uint256, gasParams: Gasparams): GasResult {.nimcall.} =
@ -352,13 +352,13 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
if gasParams.sd_condition:
result.gasCost += static(FeeSchedule[GasNewAccount])
func `prefix gasCreate2`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
func `prefix gasCreate2`(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall.} =
result = static(FeeSchedule[GasSha3Word]) * (memLength).wordCount
# ###################################################################################################
# TODO - change this `let` into `const` - pending: https://github.com/nim-lang/Nim/issues/8015
let `ResultGasCostsName`*{.inject.}: GasCosts = block:
let `ResultGasCostsName`*{.inject, compileTime.}: GasCosts = block:
# We use a block expression to avoid name redefinition conflicts
# with "fixed" and "dynamic"
@ -369,7 +369,7 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
func dynamic(handler: proc(value: Uint256): GasInt {.nimcall, gcsafe.}): GasCost =
GasCost(kind: GckDynamic, d_handler: handler)
func memExpansion(handler: proc(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall, gcsafe.}): GasCost =
func memExpansion(handler: proc(currentMemSize, memOffset, memLength: GasNatural): GasInt {.nimcall, gcsafe.}): GasCost =
GasCost(kind: GckMemExpansion, m_handler: handler)
func complex(handler: proc(value: Uint256, gasParams: GasParams): GasResult {.nimcall, gcsafe.}): GasCost =

View File

@ -10,6 +10,11 @@ import
eth/common/eth_types, eth/rlp,
../../../constants
type
# cannot use range for unknown reason
# Nim bug?
GasNatural* = int64 # range[0'i64..high(int64)]
# some methods based on py-evm utils/numeric
func log2*[bits: static int](value: StUint[bits]): Natural {.inline.}=
@ -18,7 +23,7 @@ func log2*[bits: static int](value: StUint[bits]): Natural {.inline.}=
func log256*(value: UInt256): Natural {.inline.}=
value.log2 shr 3 # div 8 (= log2(256), Logb x = Loga x/Loga b)
func ceil32*(value: Natural): Natural {.inline.}=
func ceil32*(value: GasNatural): GasNatural {.inline.}=
# Round input to the nearest bigger multiple of 32
result = value
@ -27,7 +32,7 @@ func ceil32*(value: Natural): Natural {.inline.}=
if remainder != 0:
return value + 32 - remainder
func wordCount*(length: Natural): Natural {.inline.}=
func wordCount*(length: GasNatural): GasNatural {.inline.}=
# Returns the number of EVM words corresponding to a specific size.
# EVM words is rounded up
length.ceil32 shr 5 # equivalent to `div 32` (32 = 2^5)

View File

@ -179,8 +179,8 @@ proc modExpInternal(computation: BaseComputation, base_len, exp_len, mod_len: in
# we should return a 256-bit big-endian byte array
# Force static evaluation
func zero(): static array[T.bits div 8, byte] = discard
func one(): static array[T.bits div 8, byte] =
func zero(): array[T.bits div 8, byte] {.compileTime.} = discard
func one(): array[T.bits div 8, byte] {.compileTime.} =
when cpuEndian == bigEndian:
result[0] = 1
else:

View File

@ -10,7 +10,10 @@ import macros, strutils, os, unittest, osproc
proc executeMyself(numModules: int): int =
let appName = getAppFilename()
for i in 0..<numModules:
result = result or execCmd(appName & " " & $i)
let execResult = execCmd(appName & " " & $i)
if execResult != 0:
stderr.writeLine("subtest no: " & $i & " failed")
result = result or execResult
proc getImportStmt(stmtList: NimNode): NimNode =
result = stmtList[0]

View File

@ -50,7 +50,7 @@ template runTests(name: string, hex: bool, calculator: typed) =
ommersHash: t.parentUncles)
let diff = calculator(times.fromUnix(t.currentTimeStamp), p)
test title:
test name & " " & title:
check diff == t.currentDifficulty
proc difficultyMain*() =
@ -60,3 +60,6 @@ proc difficultyMain*() =
runTests("Homestead", true, calcDifficultyHomestead)
runTests("Frontier", true, calcDifficultyFrontier)
runTests("", false, calcDifficulty)
when isMainModule:
difficultyMain()

2
vendor/nim-eth vendored

@ -1 +1 @@
Subproject commit 88563b8494cc3c9db8b8777d5b67f8dd3f9945e1
Subproject commit aa1f7f2c060119edcf6a45b3e5d1e03503b277c0

2
vendor/nim-stew vendored

@ -1 +1 @@
Subproject commit a81d1fac850119c2ede9f3997332fa9f0a2ad3d8
Subproject commit 2c9ca5dabbee8f7b1eb6e24722033706f0f650dc

2
vendor/nim-stint vendored

@ -1 +1 @@
Subproject commit 9993b9dca4a2dbf76bc432252ad4e8db944ae831
Subproject commit 25c2604b4b41d1b13f4a2740486507fe5f63086e

@ -1 +1 @@
Subproject commit dee348f0fabe518c405fd7bf9180547caaa3a121
Subproject commit 15f531200e5cacb266d30bff76e72e55c0ec5d24