Commit 92666bf9 authored by yann300's avatar yann300

use depth change to check for bas return (needed byt the js vm)

parent ba9c610a
...@@ -111,7 +111,7 @@ TraceAnalyser.prototype.buildDepth = function (index, step, tx, callStack, conte ...@@ -111,7 +111,7 @@ TraceAnalyser.prototype.buildDepth = function (index, step, tx, callStack, conte
this.traceCache.pushSteps(index, context.currentCallIndex) this.traceCache.pushSteps(index, context.currentCallIndex)
context.lastCallIndex = context.currentCallIndex context.lastCallIndex = context.currentCallIndex
context.currentCallIndex = 0 context.currentCallIndex = 0
} else if (traceHelper.isReturnInstruction(step) || traceHelper.isStopInstruction(step) || outOfGas) { } else if (traceHelper.isReturnInstruction(step) || traceHelper.isStopInstruction(step) || outOfGas || step.error || step.invalidDepthChange) {
if (index + 1 < this.trace.length) { if (index + 1 < this.trace.length) {
callStack.pop() callStack.pop()
this.traceCache.pushCall(step, index + 1, null, callStack.slice(0), outOfGas) this.traceCache.pushCall(step, index + 1, null, callStack.slice(0), outOfGas)
......
...@@ -2,8 +2,6 @@ var util = require('../helpers/util') ...@@ -2,8 +2,6 @@ var util = require('../helpers/util')
var uiutil = require('../helpers/ui') var uiutil = require('../helpers/ui')
var traceHelper = require('../helpers/traceHelper') var traceHelper = require('../helpers/traceHelper')
var Web3 = require('web3') var Web3 = require('web3')
var fees = require('ethereum-common')
var ethutil = require('ethereumjs-util')
function web3VmProvider () { function web3VmProvider () {
var self = this var self = this
...@@ -14,6 +12,7 @@ function web3VmProvider () { ...@@ -14,6 +12,7 @@ function web3VmProvider () {
this.processingHash this.processingHash
this.processingAddress this.processingAddress
this.processingIndex this.processingIndex
this.previousDepth = 0
this.incr = 0 this.incr = 0
this.eth = {} this.eth = {}
this.debug = {} this.debug = {}
...@@ -48,7 +47,7 @@ web3VmProvider.prototype.releaseCurrentHash = function () { ...@@ -48,7 +47,7 @@ web3VmProvider.prototype.releaseCurrentHash = function () {
return ret return ret
} }
web3VmProvider.prototype.txWillProcess = function (self, data) { web3VmProvider.prototype.txWillProcess = function (self, data) {
self.incr++ self.incr++
self.processingHash = util.hexConvert(data.hash()) self.processingHash = util.hexConvert(data.hash())
self.vmTraces[self.processingHash] = { self.vmTraces[self.processingHash] = {
...@@ -88,13 +87,20 @@ web3VmProvider.prototype.txProcessed = function (self, data) { ...@@ -88,13 +87,20 @@ web3VmProvider.prototype.txProcessed = function (self, data) {
} }
this.processingIndex = null this.processingIndex = null
this.processingAddress = null this.processingAddress = null
this.previousDepth = 0
} }
web3VmProvider.prototype.pushTrace = function (self, data) { web3VmProvider.prototype.pushTrace = function (self, data) {
var depth = data.depth + 1 // geth starts the depth from 1
if (!self.processingHash) { if (!self.processingHash) {
console.log('no tx processing') console.log('no tx processing')
return return
} }
if (this.previousDepth > depth) {
// returning from context, set error it is not STOP, RETURN
var previousopcode = self.vmTraces[self.processingHash].structLogs[this.processingIndex - 1]
previousopcode.invalidDepthChange = previousopcode.op !== 'RETURN' && previousopcode.op !== 'STOP'
}
var step = { var step = {
stack: util.hexListConvert(data.stack), stack: util.hexListConvert(data.stack),
memory: util.formatMemory(data.memory), memory: util.formatMemory(data.memory),
...@@ -102,23 +108,11 @@ web3VmProvider.prototype.pushTrace = function (self, data) { ...@@ -102,23 +108,11 @@ web3VmProvider.prototype.pushTrace = function (self, data) {
op: data.opcode.name, op: data.opcode.name,
pc: data.pc, pc: data.pc,
gasCost: data.opcode.fee.toString(), gasCost: data.opcode.fee.toString(),
gas: data.gasLeft.toString() gas: data.gasLeft.toString(),
} depth: depth,
if (data.opcode.name === 'SSTORE') { error: data.error === false ? undefined : data.error
var currentStorage = this.storageCache[this.processingHash][this.processingAddress]
var key = step.stack[step.stack.length - 1]
var value = step.stack[step.stack.length - 2]
value = util.hexToIntArray(value)
value = ethutil.unpad(value)
if (value.length === 0) {
data.opcode.fee = fees.sstoreResetGas.v
} else if (currentStorage[key] === undefined) {
data.opcode.fee = fees.sstoreSetGas.v
} else {
data.opcode.fee = fees.sstoreResetGas.v
}
step.gasCost = data.opcode.fee
} }
console.log(JSON.stringify(step))
self.vmTraces[self.processingHash].structLogs.push(step) self.vmTraces[self.processingHash].structLogs.push(step)
if (traceHelper.newContextStorage(step)) { if (traceHelper.newContextStorage(step)) {
if (step.op === 'CREATE') { if (step.op === 'CREATE') {
...@@ -134,6 +128,7 @@ web3VmProvider.prototype.pushTrace = function (self, data) { ...@@ -134,6 +128,7 @@ web3VmProvider.prototype.pushTrace = function (self, data) {
} }
} }
this.processingIndex++ this.processingIndex++
this.previousDepth = depth
} }
web3VmProvider.prototype.getCode = function (address, cb) { web3VmProvider.prototype.getCode = function (address, cb) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment