move exception handler deeper in the EVM
This commit is contained in:
parent
07ac4620d9
commit
4c0ba876ef
|
@ -167,6 +167,24 @@ proc transferBalance(computation: BaseComputation, opCode: static[Op]) =
|
|||
db.subBalance(computation.msg.sender, computation.msg.value)
|
||||
db.addBalance(computation.msg.storageAddress, computation.msg.value)
|
||||
|
||||
template continuation*(comp: BaseComputation, body: untyped) =
|
||||
var tmpNext = comp.nextProc
|
||||
comp.nextProc = proc() =
|
||||
body
|
||||
tmpNext()
|
||||
|
||||
proc postExecuteVM(computation: BaseComputation) =
|
||||
if computation.isSuccess and computation.msg.isCreate:
|
||||
let fork = computation.getFork
|
||||
let contractFailed = not computation.writeContract(fork)
|
||||
if contractFailed and fork == FkHomestead:
|
||||
computation.setError(&"writeContract failed, depth={computation.msg.depth}", true)
|
||||
|
||||
if computation.isSuccess:
|
||||
computation.commit()
|
||||
else:
|
||||
computation.rollback()
|
||||
|
||||
proc executeOpcodes*(computation: BaseComputation) {.gcsafe.}
|
||||
|
||||
proc applyMessage*(computation: BaseComputation, opCode: static[Op]) =
|
||||
|
@ -183,24 +201,8 @@ proc applyMessage*(computation: BaseComputation, opCode: static[Op]) =
|
|||
computation.commit()
|
||||
return
|
||||
|
||||
let fork = computation.getFork
|
||||
|
||||
try:
|
||||
if not computation.execPrecompiles(fork):
|
||||
executeOpcodes(computation)
|
||||
except:
|
||||
let msg = getCurrentExceptionMsg()
|
||||
computation.setError(&"applyMessage Error msg={msg}, depth={computation.msg.depth}", true)
|
||||
|
||||
if computation.isSuccess and computation.msg.isCreate:
|
||||
let contractFailed = not computation.writeContract(fork)
|
||||
if contractFailed and fork == FkHomestead:
|
||||
computation.setError(&"writeContract failed, depth={computation.msg.depth}", true)
|
||||
|
||||
if computation.isSuccess:
|
||||
computation.commit()
|
||||
else:
|
||||
computation.rollback()
|
||||
postExecuteVM(computation)
|
||||
|
||||
proc addChildComputation*(computation: BaseComputation, child: BaseComputation) =
|
||||
if child.isError:
|
||||
|
|
|
@ -231,6 +231,11 @@ proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNo
|
|||
|
||||
# Wrap the case statement in while true + computed goto
|
||||
result = quote do:
|
||||
try:
|
||||
let fork = `computation`.getFork
|
||||
if `computation`.execPrecompiles(fork):
|
||||
return
|
||||
|
||||
if `computation`.tracingEnabled:
|
||||
`computation`.prepareTracer()
|
||||
`computation`.instr = `computation`.code.next()
|
||||
|
@ -239,6 +244,10 @@ proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNo
|
|||
# TODO lots of macro magic here to unravel, with chronicles...
|
||||
# `computation`.logger.log($`computation`.stack & "\n\n", fgGreen)
|
||||
`result`
|
||||
except:
|
||||
let msg = getCurrentExceptionMsg()
|
||||
let errorMsg = "Opcode Dispatch Error msg=" & msg & ", depth=" & $computation.msg.depth
|
||||
`computation`.setError(errorMsg, true)
|
||||
|
||||
macro genFrontierDispatch(computation: BaseComputation): untyped =
|
||||
result = opTableToCaseStmt(FrontierOpDispatch, computation)
|
||||
|
|
|
@ -67,6 +67,7 @@ type
|
|||
dbsnapshot*: Snapshot
|
||||
instr*: Op
|
||||
opIndex*: int
|
||||
nextProc*: proc()
|
||||
|
||||
Error* = ref object
|
||||
info*: string
|
||||
|
|
|
@ -56,10 +56,7 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
|||
createAddress = toAddress))
|
||||
|
||||
var computation = newBaseComputation(vmState, header.blockNumber, message)
|
||||
try:
|
||||
computation.executeOpcodes()
|
||||
except VMError:
|
||||
computation.error = Error(info: getCurrentExceptionMsg())
|
||||
|
||||
if not fixture{"post"}.isNil:
|
||||
# Success checks
|
||||
|
|
Loading…
Reference in New Issue