diff --git a/src/solidity/types/Address.js b/src/solidity/types/Address.js index 9ff6d84cf6..3492010489 100644 --- a/src/solidity/types/Address.js +++ b/src/solidity/types/Address.js @@ -12,4 +12,12 @@ Address.prototype.decodeFromStorage = function (location, storageContent) { return '0x' + value.toUpperCase() } +Address.prototype.decodeLocals = function (stackHeight, stack, memory) { + if (stack.length < stackHeight) { + return '0x0000000000000000000000000000000000000000' + } else { + return '0x' + util.extractHexByteSlice(stack[stack.length - 1 - stackHeight], this.storageBytes, 0) + } +} + module.exports = Address diff --git a/src/solidity/types/Int.js b/src/solidity/types/Int.js index feee4f0fc8..3d4c1e6a09 100644 --- a/src/solidity/types/Int.js +++ b/src/solidity/types/Int.js @@ -11,4 +11,12 @@ Int.prototype.decodeFromStorage = function (location, storageContent) { return util.decodeInt(location, storageContent, this.storageBytes, true) } +Int.prototype.decodeLocals = function (stackHeight, stack, memory) { + if (stack.length < stackHeight) { + return '0' + } else { + return util.decodeIntFromHex(stack[stack.length - 1 - stackHeight].replace('0x', ''), 32, true) + } +} + module.exports = Int diff --git a/src/solidity/types/Uint.js b/src/solidity/types/Uint.js index eef4d5f302..95fa2880a2 100644 --- a/src/solidity/types/Uint.js +++ b/src/solidity/types/Uint.js @@ -11,4 +11,12 @@ Uint.prototype.decodeFromStorage = function (location, storageContent) { return util.decodeInt(location, storageContent, this.storageBytes, false) } +Uint.prototype.decodeLocals = function (stackHeight, stack, memory) { + if (stack.length < stackHeight) { + return '0' + } else { + return util.decodeIntFromHex(stack[stack.length - 1 - stackHeight].replace('0x', ''), this.storageBytes, false) + } +} + module.exports = Uint diff --git a/src/solidity/types/util.js b/src/solidity/types/util.js index 518e75c7da..aea200d5ed 100644 --- a/src/solidity/types/util.js +++ b/src/solidity/types/util.js @@ -5,7 +5,9 @@ var BN = require('ethereumjs-util').BN module.exports = { readFromStorage: readFromStorage, decodeInt: decodeInt, + decodeIntFromHex: decodeIntFromHex, extractHexValue: extractHexValue, + extractHexByteSlice: extractHexByteSlice, sha3: sha3, toBN: toBN, add: add @@ -14,6 +16,10 @@ module.exports = { function decodeInt (location, storageContent, byteLength, signed) { var slotvalue = readFromStorage(location.slot, storageContent) var value = extractHexByteSlice(slotvalue, byteLength, location.offset) + return decodeIntFromHex(value, byteLength, signed) +} + +function decodeIntFromHex (value, byteLength, signed) { var bigNumber = new BN(value, 16) if (signed) { bigNumber = bigNumber.fromTwos(8 * byteLength)