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

Commit

Permalink
chore:update direct dependencies (#445)
Browse files Browse the repository at this point in the history
* Update direct dependencies
* Instead of just changing our tests, make sure eth_sign returns what it used to.
  • Loading branch information
davidmurdoch authored Jul 15, 2019
1 parent 3630b86 commit d4e0018
Show file tree
Hide file tree
Showing 16 changed files with 2,335 additions and 1,360 deletions.
57 changes: 30 additions & 27 deletions lib/blockchain_double.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var to = require("./utils/to.js");
var Account = require("ethereumjs-account");
var Account = require("ethereumjs-account").default;
var Block = require("ethereumjs-block");
var Log = require("./utils/log");
var Receipt = require("./utils/receipt");
Expand All @@ -14,7 +14,7 @@ var EventEmitter = require("events");
var estimateGas = require("./utils/gasEstimation");
var _ = require("lodash");
var promisify = require("util").promisify;
const BN = require("bn.js");
const BN = utils.BN;

function BlockchainDouble(options) {
var self = this;
Expand Down Expand Up @@ -971,9 +971,6 @@ BlockchainDouble.prototype.processTransactionTrace = async function(hash, params
BlockchainDouble.prototype.processStorageTrace = function(structLog, storageStack, event, vm, callback) {
var name = event.opcode.name;

var argsNum = event.opcode.in;
var args = event.stack.slice(-argsNum).map((arg) => to.hex(arg));

if (storageStack.currentDepth > event.depth) {
storageStack.stack.pop();
}
Expand All @@ -987,32 +984,38 @@ BlockchainDouble.prototype.processStorageTrace = function(structLog, storageStac
var value;
switch (name) {
case "SSTORE":
key = to.rpcDataHexString(args[1], 64).replace("0x", "");
value = to.rpcDataHexString(args[0], 64).replace("0x", "");

// use Object.assign to prevent future steps from overwriting this step's storage values
structLog.storage = Object.assign({}, storageStack.stack[storageStack.currentDepth]);
{
const stack = event.stack;
const stackLength = stack.length;
key = to.rpcDataHexString(stack[stackLength - 1], 64).replace("0x", "");
value = to.rpcDataHexString(stack[stackLength - 2], 64).replace("0x", "");
// use Object.assign to prevent future steps from overwriting this step's storage values
structLog.storage = Object.assign({}, storageStack.stack[storageStack.currentDepth]);

callback(null, structLog);
// assign after callback because this storage change actually takes
// effect _after_ this opcode executes
storageStack.stack[storageStack.currentDepth][key] = value;
callback(null, structLog);
// assign after callback because this storage change actually takes
// effect _after_ this opcode executes
storageStack.stack[storageStack.currentDepth][key] = value;
}
break;
case "SLOAD":
// this one's more fun, we need to get the value the contract is loading from current storage
key = to.rpcDataHexString(args[0], 64).replace("0x", "");

vm.stateManager.getContractStorage(event.address, "0x" + key, function(err, result) {
if (err) {
return callback(err);
}
{
const stack = event.stack;
// this one's more fun, we need to get the value the contract is loading from current storage
key = to.rpcDataHexString(stack[stack.length - 1], 64).replace("0x", "");

vm.stateManager.getContractStorage(event.address, "0x" + key, function(err, result) {
if (err) {
return callback(err);
}

value = to.rpcDataHexString(result, 64).replace("0x", "");
storageStack.stack[storageStack.currentDepth][key] = value;
// use Object.assign to prevent future steps from overwriting this step's storage values
structLog.storage = Object.assign({}, storageStack.stack[storageStack.currentDepth]);
callback(null, structLog);
});
value = to.rpcDataHexString(result, 64).replace("0x", "");
storageStack.stack[storageStack.currentDepth][key] = value;
// use Object.assign to prevent future steps from overwriting this step's storage values
structLog.storage = Object.assign({}, storageStack.stack[storageStack.currentDepth]);
callback(null, structLog);
});
}
break;
default:
// use Object.assign to prevent future steps from overwriting this step's storage values
Expand Down
13 changes: 10 additions & 3 deletions lib/statemanager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Account = require("ethereumjs-account");
var Account = require("ethereumjs-account").default;
var RuntimeError = require("./utils/runtimeerror");
var Transaction = require("./utils/transaction");
var utils = require("ethereumjs-util");
Expand All @@ -13,7 +13,7 @@ var Web3 = require("web3");
var sigUtil = require("eth-sig-util");
var _ = require("lodash");
const { BlockOutOfRangeError } = require("./utils/errorhelper");
const BN = require("bn.js");
const BN = utils.BN;

const ZERO_BUFFER = Buffer.from([0]);

Expand Down Expand Up @@ -449,7 +449,14 @@ StateManager.prototype.sign = function(address, dataToSign) {
var msg = to.buffer(dataToSign, "hex");
var msgHash = utils.hashPersonalMessage(msg);
var sgn = utils.ecsign(msgHash, Buffer.from(secretKey));
return utils.toRpcSig(sgn.v, sgn.r, sgn.s);
// ethereumjs-utils changed the behavior of toRpcSig so that the `v` value
// output by `toRpcSig` is always `sgn.v - 27` (basically `0` or `1`). In
// order to avoid a breaking change in Ganache at this time we are calculating
// a chain ID that will always a) validate the v, and b) generate an output v
// of `0` or `1`, like it used to.
const v = sgn.v - 27;
const chainId = (v - 35) / 2;
return utils.toRpcSig(v, sgn.r, sgn.s, chainId);
};

StateManager.prototype.signTypedData = function(address, typedDataToSign) {
Expand Down
2 changes: 1 addition & 1 deletion lib/subproviders/geth_api_double.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ GethApiDouble.prototype.web3_clientVersion = function(callback) {
};

GethApiDouble.prototype.web3_sha3 = function(string, callback) {
callback(null, to.hex(utils.sha3(string)));
callback(null, to.hex(utils.keccak256(string)));
};

GethApiDouble.prototype.net_version = function(callback) {
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/forkedblockchain.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var BlockchainDouble = require("../blockchain_double.js");
var Account = require("ethereumjs-account");
var Account = require("ethereumjs-account").default;
var Block = require("ethereumjs-block");
var Log = require("./log.js");
var Receipt = require("./receipt.js");
Expand All @@ -9,7 +9,7 @@ var Web3 = require("web3");
var to = require("./to.js");
var Transaction = require("./transaction");
var async = require("async");
var BN = require("bn.js");
const BN = utils.BN;

var inherits = require("util").inherits;

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const EthereumJsTransaction = require("ethereumjs-tx");
const EthereumJsFakeTransaction = require("ethereumjs-tx/fake");
const ethUtil = require("ethereumjs-util");
const assert = require("assert");
const rlp = require("rlp");
const rlp = ethUtil.rlp;
const to = require("./to");

const sign = EthereumJsTransaction.prototype.sign;
Expand Down
Loading

0 comments on commit d4e0018

Please sign in to comment.