fixes ECRecover precompiles

This commit is contained in:
andri lim 2019-02-20 15:13:19 +07:00 committed by zah
parent 96ae5ee05a
commit 71e7ee2dae
4 changed files with 19 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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