diff --git a/nimbus/p2p/executor.nim b/nimbus/p2p/executor.nim index e3296d476..bdba9e29c 100644 --- a/nimbus/p2p/executor.nim +++ b/nimbus/p2p/executor.nim @@ -43,6 +43,13 @@ proc contractCall(t: Transaction, vmState: BaseVMState, sender: EthAddress, fork vmState.clearLogs() return t.gasLimit.u256 * t.gasPrice.u256 +# this proc should not be here, we need to refactor +# processTransaction +proc isPrecompiles*(address: EthAddress): bool {.inline.} = + for i in 0..18: + if address[i] != 0: return + result = address[19] >= 1.byte and address[19] <= 8.byte + proc processTransaction*(t: Transaction, sender: EthAddress, vmState: BaseVMState): UInt256 = ## Process the transaction, write the results to db. ## Returns amount of ETH to be rewarded to miner @@ -86,7 +93,7 @@ proc processTransaction*(t: Transaction, sender: EthAddress, vmState: BaseVMStat else: let code = db.getCode(t.to) - if code.len == 0: + if code.len == 0 and not isPrecompiles(t.to): # Value transfer trace "Transfer", value = t.value, sender, to = t.to diff --git a/nimbus/vm/computation.nim b/nimbus/vm/computation.nim index f1fed1408..7689004a5 100644 --- a/nimbus/vm/computation.nim +++ b/nimbus/vm/computation.nim @@ -196,7 +196,12 @@ proc applyMessage(computation: var BaseComputation, opCode: static[Op]) = snapshot.commit() except VMError: snapshot.revert(true) - debug "applyMessage failed", + debug "VMError applyMessage failed", + msg = computation.error.info, + depth = computation.msg.depth + except EVMError: + snapshot.revert() # TODO: true or false? + debug "EVMError applyMessage failed", msg = computation.error.info, depth = computation.msg.depth diff --git a/nimbus/vm/interpreter_dispatch.nim b/nimbus/vm/interpreter_dispatch.nim index fb4ae3c26..81ba5df9a 100644 --- a/nimbus/vm/interpreter_dispatch.nim +++ b/nimbus/vm/interpreter_dispatch.nim @@ -255,5 +255,6 @@ proc executeOpcodes*(computation: var BaseComputation) = computation.updateOpcodeExec(fork) except VMError: computation.error = Error(info: getCurrentExceptionMsg()) - debug "executeOpcodes() failed", error = getCurrentExceptionMsg() - + debug "VM Error executeOpcodes() failed", error = getCurrentExceptionMsg() + except EVMError: + debug "EVM Error executeOpcodes() failed", error = getCurrentExceptionMsg() diff --git a/nimbus/vm/precompiles.nim b/nimbus/vm/precompiles.nim index 723a4a1b9..97a83e20d 100644 --- a/nimbus/vm/precompiles.nim +++ b/nimbus/vm/precompiles.nim @@ -28,7 +28,8 @@ proc getSignature*(computation: BaseComputation): (array[32, byte], Signature) = # Note that we need to rearrange to R, S, V bytes[0..63] = data[64..127] let v = data[63] # TODO: Endian - assert v.int in 27..28 + if v.int notin 27..28: + raise newException(ValidationError, "Invalid V in getSignature") bytes[64] = v - 27 if recoverSignature(bytes, result[1]) != EthKeysStatus.Success: