Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix: set correct gasCost values in debug_traceTransaction (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman authored Jun 23, 2020
1 parent ad91e80 commit ee8972e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lib/blockchain_double.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,8 @@ BlockchainDouble.prototype.processTransactionTrace = async function(hash, params

const gasLeft = to.number(event.gasLeft);
const totalGasUsedAfterThisStep = to.number(txCurrentlyProcessing.gasLimit) - gasLeft;
const gasUsedThisStep = totalGasUsedAfterThisStep - returnVal.gas;
returnVal.gas += gasUsedThisStep;
const gasUsedPreviousStep = totalGasUsedAfterThisStep - returnVal.gas;
returnVal.gas += gasUsedPreviousStep;

let memory = null;
if (!params.disableMemory) {
Expand All @@ -868,19 +868,24 @@ BlockchainDouble.prototype.processTransactionTrace = async function(hash, params
return to.rpcDataHexString(item, 64).replace("0x", ""); // non-0x prefixed.
});
}

let structLog = {
depth: event.depth,
error: "",
gas: gasLeft,
gasCost: gasUsedThisStep,
gasCost: 0,
memory,
op: event.opcode.name,
pc: event.pc,
stack,
storage: null
};

// The gas difference calculated for each step is indicative of gas consumed in
// the previous step. Gas consumption in the final step will always be zero.
if (returnVal.structLogs.length) {
returnVal.structLogs[returnVal.structLogs.length - 1].gasCost = gasUsedPreviousStep;
}

if (params.disableStorage) {
returnVal.structLogs.push(structLog);
next();
Expand Down
2 changes: 1 addition & 1 deletion test/debug/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function test(forked) {
const lastop = structLogs[structLogs.length - 1];

assert.strictEqual(lastop.op, "STOP");
assert.strictEqual(lastop.gasCost, 1);
assert.strictEqual(lastop.gasCost, 0);
assert.strictEqual(lastop.pc, 235);
assert.strictEqual(
lastop.storage["0000000000000000000000000000000000000000000000000000000000000000"],
Expand Down

0 comments on commit ee8972e

Please sign in to comment.