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

fix: storage value encoding in forked trie. #658

Merged
merged 2 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/forking/forked_storage_trie.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ForkedStorageBaseTrie.prototype.get = function(key, callback) {
return callback(err);
}

value = utils.rlp.encode(value);
value = to.rpcQuantityBuffer(value);

callback(null, value);
}
Expand Down
10 changes: 10 additions & 0 deletions lib/utils/to.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ module.exports = {
return val;
},

rpcQuantityBuffer: function(val) {
val = this._rpcQuantityHexString(val);

if (val === "0x0") {
val = "0x";
}

return utils.rlp.encode(val);
},

rpcDataHexString: function(val, length) {
if (typeof length === "number") {
val = this.hex(val).replace("0x", "");
Expand Down
29 changes: 29 additions & 0 deletions test/local/forking/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const assert = require("assert");
const bootstrap = require("../../helpers/contract/bootstrap");
const generateSend = require("../../helpers/utils/rpc");
const initializeTestProvider = require("../../helpers/web3/initializeTestProvider");
const Common = require("ethereumjs-common").default;

/**
* NOTE: Naming in these tests is a bit confusing. Here, the "main chain"
Expand All @@ -15,6 +16,7 @@ describe("Forking Debugging", () => {
let forkedContext;
let mainContext;
let mainAccounts;
let common;
const logger = {
log: function(msg) {}
};
Expand Down Expand Up @@ -42,6 +44,10 @@ describe("Forking Debugging", () => {
logger,
seed: "forked provider"
});

common = Common.forCustomChain("mainnet", {
name: "ganache"
});
mainAccounts = await mainContext.web3.eth.getAccounts();
});

Expand Down Expand Up @@ -70,4 +76,27 @@ describe("Forking Debugging", () => {
const txReturnValue = parseInt(txMemory[txMemory.length - 1], 16);
assert.strictEqual(txReturnValue, 2);
});

it("successfully manages storage slot creation gas consumption", async() => {
const { bytecode } = forkedContext;
const { web3: mainWeb3 } = mainContext;

const deployedContract = await mainWeb3.eth.sendTransaction({
from: mainAccounts[0],
data: bytecode,
gas: 3141592
});

const send = generateSend(mainWeb3.currentProvider);

const result = await send("debug_traceTransaction", deployedContract.transactionHash, {});

for (let i = 0; i < result.result.structLogs.length; i++) {
if (result.result.structLogs[i].op === "SSTORE") {
// ensure that every SSTORE in contract creation triggers slot creation
const gasCost = common.param("gasPrices", "sstoreInitGasEIP2200", "istanbul");
assert.strictEqual(result.result.structLogs[i].gasCost, gasCost);
}
}
});
});