From da88d498e30d1e2966901e6eb25cebc261c7ee66 Mon Sep 17 00:00:00 2001 From: andri lim Date: Thu, 21 Mar 2019 23:08:41 +0700 Subject: [PATCH] fix MaxCallDepth comparison --- nimbus/vm/computation.nim | 2 +- nimbus/vm/interpreter/opcodes_impl.nim | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/nimbus/vm/computation.nim b/nimbus/vm/computation.nim index 1d2214c6b..83b717a86 100644 --- a/nimbus/vm/computation.nim +++ b/nimbus/vm/computation.nim @@ -144,7 +144,7 @@ proc writeContract*(computation: var BaseComputation, fork: Fork): bool = result = false proc transferBalance(computation: var BaseComputation, opCode: static[Op]): bool = - if computation.msg.depth >= MaxCallDepth: + if computation.msg.depth > MaxCallDepth: debug "Stack depth limit reached", depth=computation.msg.depth return false diff --git a/nimbus/vm/interpreter/opcodes_impl.nim b/nimbus/vm/interpreter/opcodes_impl.nim index 8bd461a59..ac9d921c0 100644 --- a/nimbus/vm/interpreter/opcodes_impl.nim +++ b/nimbus/vm/interpreter/opcodes_impl.nim @@ -528,7 +528,10 @@ proc canTransfer(computation: BaseComputation, memPos, memLen: int, value: Uint2 debug "Computation Failure", reason = "Insufficient funds available to transfer", required = computation.msg.value, balance = senderBalance return false - if computation.msg.depth >= MaxCallDepth: + # unlike the other MaxCallDepth comparison, + # this one has not been entered child computation + # thats why it has `+ 1` + if computation.msg.depth + 1 > MaxCallDepth: debug "Computation Failure", reason = "Stack too deep", maximumDepth = MaxCallDepth, depth = computation.msg.depth return false