imports and some type updated

pull/697/head
aniket-engg 4 years ago committed by Aniket
parent 3f4965e034
commit 2dc8d11a56
  1. 10
      libs/remix-debug/src/code/codeManager.ts
  2. 8
      libs/remix-debug/src/debugger/VmDebugger.ts
  3. 11
      libs/remix-debug/src/debugger/debugger.ts
  4. 12
      libs/remix-debug/src/debugger/solidityLocals.ts
  5. 12
      libs/remix-debug/src/debugger/solidityState.ts
  6. 2
      libs/remix-debug/src/debugger/stepManager.ts
  7. 6
      libs/remix-debug/src/solidity-decoder/types/Address.ts
  8. 23
      libs/remix-debug/src/solidity-decoder/types/ArrayType.ts
  9. 6
      libs/remix-debug/src/solidity-decoder/types/Bool.ts
  10. 20
      libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts
  11. 5
      libs/remix-debug/src/solidity-decoder/types/Enum.ts
  12. 2
      libs/remix-debug/src/solidity-decoder/types/FixedByteArray.ts
  13. 8
      libs/remix-debug/src/solidity-decoder/types/Int.ts
  14. 28
      libs/remix-debug/src/solidity-decoder/types/Mapping.ts
  15. 2
      libs/remix-debug/src/solidity-decoder/types/RefType.ts
  16. 11
      libs/remix-debug/src/solidity-decoder/types/StringType.ts
  17. 9
      libs/remix-debug/src/solidity-decoder/types/Struct.ts
  18. 8
      libs/remix-debug/src/solidity-decoder/types/Uint.ts
  19. 6
      libs/remix-debug/src/solidity-decoder/types/ValueType.ts
  20. 4
      libs/remix-debug/src/solidity-decoder/types/util.ts

@ -1,8 +1,8 @@
'use strict'
const EventManager = require('../eventManager')
const traceHelper = require('../trace/traceHelper')
const SourceMappingDecoder = require('../source/sourceMappingDecoder')
import { EventManager } from '../eventManager'
import { isContractCreation } from '../trace/traceHelper'
import { findNodeAtInstructionIndex } from '../source/sourceMappingDecoder'
import { CodeResolver } from './codeResolver'
/*
@ -70,7 +70,7 @@ export class CodeManager {
* @param {Function} cb - callback function, return the bytecode
*/
async getCode (address) {
if (!traceHelper.isContractCreation(address)) {
if (!isContractCreation(address)) {
const code = await this.codeResolver.resolveCode(address)
return code
}
@ -131,7 +131,7 @@ export class CodeManager {
*/
getFunctionFromPC (address, pc, sourceMap, ast) {
const instIndex = this.codeResolver.getInstructionIndex(address, pc)
return SourceMappingDecoder.findNodeAtInstructionIndex('FunctionDefinition', instIndex, sourceMap, ast)
return findNodeAtInstructionIndex('FunctionDefinition', instIndex, sourceMap, ast)
}
private retrieveCodeAndTrigger (codeMananger, address, stepIndex, tx) {

@ -1,10 +1,10 @@
const EventManager = require('../eventManager')
const StorageResolver = require('../storage/storageResolver')
const StorageViewer = require('../storage/storageViewer')
import { EventManager } from '../eventManager'
import { StorageResolver } from '../storage/storageResolver'
import { StorageViewer } from '../storage/storageViewer'
import { helpers } from '@remix-project/remix-lib'
import { DebuggerSolidityState } from './solidityState'
import { DebuggerSolidityLocals } from './solidityLocals'
const ui = helpers.ui
const { ui } = helpers
export class VmDebuggerLogic {

@ -1,7 +1,7 @@
'use strict'
const Ethdebugger = require('../Ethdebugger')
const EventManager = require('../eventManager')
const traceHelper = require('../trace/traceHelper')
import { Ethdebugger } from '../Ethdebugger'
import { EventManager } from '../eventManager'
import { contractCreationToken } from '../trace/traceHelper'
import { BreakpointManager } from '../code/breakpointManager'
import { DebuggerStepManager } from './stepManager'
import { VmDebuggerLogic } from './VmDebugger'
@ -18,7 +18,6 @@ export class Debugger {
constructor (options) {
this.event = new EventManager()
this.offsetToLineColumnConverter = options.offsetToLineColumnConverter
/*
Returns a compilation result for a given address or the last one available if none are found
@ -96,7 +95,7 @@ export class Debugger {
this.debugger.web3 = web3
}
debug (blockNumber, txNumber, tx, loadingCb) {
debug (blockNumber, txNumber, tx, loadingCb): Promise<void> {
const web3 = this.debugger.web3
return new Promise((resolve, reject) => {
@ -106,7 +105,7 @@ export class Debugger {
if (tx) {
if (!tx.to) {
tx.to = traceHelper.contractCreationToken('0')
tx.to = contractCreationToken('0')
}
this.debugTx(tx, loadingCb)
return resolve()

@ -1,6 +1,6 @@
const EventManager = require('../eventManager')
const localDecoder = require('../solidity-decoder/localDecoder')
const StorageViewer = require('../storage/storageViewer')
import { EventManager } from '../eventManager'
import { solidityLocals } from '../solidity-decoder/localDecoder'
import { StorageViewer } from '../storage/storageViewer'
export class DebuggerSolidityLocals {
@ -73,16 +73,16 @@ export class DebuggerSolidityLocals {
var memory = result[1].value
try {
var storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: result[2].value }, this.storageResolver, this.traceManager)
localDecoder.solidityLocals(this.stepManager.currentStepIndex, this.internalTreeCall, stack, memory, storageViewer, sourceLocation, cursor).then((locals) => {
solidityLocals(this.stepManager.currentStepIndex, this.internalTreeCall, stack, memory, storageViewer, sourceLocation, cursor).then((locals) => {
if (!cursor) {
if (!locals.error) {
if (!locals['error']) {
this.event.trigger('solidityLocals', [locals])
}
if (!Object.keys(locals).length) {
this.event.trigger('solidityLocalsMessage', ['no locals'])
}
} else {
if (!locals.error) {
if (!locals['error']) {
this.event.trigger('solidityLocalsLoadMoreCompleted', [locals])
}
}

@ -1,6 +1,6 @@
const EventManager = require('../eventManager')
const stateDecoder = require('../solidity-decoder/stateDecoder')
const StorageViewer = require('../storage/storageViewer')
import { EventManager } from '../eventManager'
import { decodeState } from '../solidity-decoder/stateDecoder'
import { StorageViewer } from '../storage/storageViewer'
export class DebuggerSolidityState {
@ -76,10 +76,10 @@ export class DebuggerSolidityState {
extractStateVariables (stateVars, address) {
const storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this.traceManager)
stateDecoder.decodeState(stateVars, storageViewer).then((result) => {
decodeState(stateVars, storageViewer).then((result) => {
this.event.trigger('solidityStateMessage', [''])
if (result.error) {
return this.event.trigger('solidityStateMessage', [result.error])
if (result['error']) {
return this.event.trigger('solidityStateMessage', [result['error']])
}
this.event.trigger('solidityState', [result])
})

@ -1,5 +1,5 @@
import { util } from '@remix-project/remix-lib'
const EventManager = require('../eventManager')
import { EventManager } from '../eventManager'
export class DebuggerStepManager {

@ -1,6 +1,6 @@
'use strict'
const util = require('./util')
const ValueType = require('./ValueType')
import { extractHexByteSlice } from './util'
import { ValueType } from './ValueType'
export class Address extends ValueType {
constructor () {
@ -11,6 +11,6 @@ export class Address extends ValueType {
if (!value) {
return '0x0000000000000000000000000000000000000000'
}
return '0x' + util.extractHexByteSlice(value, this.storageBytes, 0).toUpperCase()
return '0x' + extractHexByteSlice(value, this.storageBytes, 0).toUpperCase()
}
}

@ -1,12 +1,15 @@
'use strict'
const util = require('./util')
const remixLib = require('@remix-project/remix-lib')
const sha3256 = remixLib.util.sha3_256
const BN = require('ethereumjs-util').BN
const RefType = require('./RefType')
import { add, toBN, extractHexValue } from './util'
import { util } from '@remix-project/remix-lib'
import { BN } from 'ethereumjs-util'
import { RefType } from './RefType'
const sha3256 = util.sha3_256
export class ArrayType extends RefType {
underlyingType
arraySize
constructor (underlyingType, arraySize, location) {
let storageSlots = null
if (arraySize === 'dynamic') {
@ -30,7 +33,7 @@ export class ArrayType extends RefType {
let size = null
let slotValue
try {
slotValue = await util.extractHexValue(location, storageResolver, this.storageBytes)
slotValue = await extractHexValue(location, storageResolver, this.storageBytes)
} catch (e) {
console.log(e)
return {
@ -43,12 +46,12 @@ export class ArrayType extends RefType {
slot: location.slot
}
if (this.arraySize === 'dynamic') {
size = util.toBN('0x' + slotValue)
size = toBN('0x' + slotValue)
currentLocation.slot = sha3256(location.slot)
} else {
size = new BN(this.arraySize)
}
var k = util.toBN(0)
var k = toBN(0)
for (; k.lt(size) && k.ltn(300); k.iaddn(1)) {
try {
ret.push(await this.underlyingType.decodeFromStorage(currentLocation, storageResolver))
@ -62,10 +65,10 @@ export class ArrayType extends RefType {
currentLocation.offset += this.underlyingType.storageBytes
if (currentLocation.offset + this.underlyingType.storageBytes > 32) {
currentLocation.offset = 0
currentLocation.slot = '0x' + util.add(currentLocation.slot, 1).toString(16)
currentLocation.slot = '0x' + add(currentLocation.slot, 1).toString(16)
}
} else {
currentLocation.slot = '0x' + util.add(currentLocation.slot, this.underlyingType.storageSlots).toString(16)
currentLocation.slot = '0x' + add(currentLocation.slot, this.underlyingType.storageSlots).toString(16)
currentLocation.offset = 0
}
}

@ -1,6 +1,6 @@
'use strict'
const ValueType = require('./ValueType')
const util = require('./util')
import { ValueType } from './ValueType'
import { extractHexByteSlice } from './util'
export class Bool extends ValueType {
constructor () {
@ -11,7 +11,7 @@ export class Bool extends ValueType {
if (!value) {
return false
}
value = util.extractHexByteSlice(value, this.storageBytes, 0)
value = extractHexByteSlice(value, this.storageBytes, 0)
return value !== '00'
}
}

@ -1,9 +1,9 @@
'use strict'
const util = require('./util')
const remixLib = require('@remix-project/remix-lib')
const sha3256 = remixLib.util.sha3_256
const BN = require('ethereumjs-util').BN
const RefType = require('./RefType')
import { extractHexValue, readFromStorage } from './util'
import { util } from '@remix-project/remix-lib'
import { BN } from 'ethereumjs-util'
import { RefType } from './RefType'
const sha3256 = util.sha3_256
export class DynamicByteArray extends RefType {
constructor (location) {
@ -13,29 +13,29 @@ export class DynamicByteArray extends RefType {
async decodeFromStorage (location, storageResolver) {
let value = '0x0'
try {
value = await util.extractHexValue(location, storageResolver, this.storageBytes)
value = await extractHexValue(location, storageResolver, this.storageBytes)
} catch (e) {
console.log(e)
return {value: '<decoding failed - ' + e.message + '>', type: this.typeName}
}
const bn = new BN(value, 16)
if (bn.testn(0)) {
const length = bn.div(new BN(2))
const length: BN = bn.div(new BN(2))
let dataPos = new BN(sha3256(location.slot).replace('0x', ''), 16)
let ret = ''
let currentSlot = '0x'
try {
currentSlot = await util.readFromStorage(dataPos, storageResolver)
currentSlot = await readFromStorage(dataPos, storageResolver)
} catch (e) {
console.log(e)
return {value: '<decoding failed - ' + e.message + '>', type: this.typeName}
}
while (length.gt(ret.length) && ret.length < 32000) {
while (length.gt(new BN(ret.length)) && ret.length < 32000) {
currentSlot = currentSlot.replace('0x', '')
ret += currentSlot
dataPos = dataPos.add(new BN(1))
try {
currentSlot = await util.readFromStorage(dataPos, storageResolver)
currentSlot = await readFromStorage(dataPos, storageResolver)
} catch (e) {
console.log(e)
return {value: '<decoding failed - ' + e.message + '>', type: this.typeName}

@ -1,7 +1,10 @@
'use strict'
const ValueType = require('./ValueType')
import { ValueType } from './ValueType'
export class Enum extends ValueType {
enumDef
constructor (enumDef) {
let storageBytes = 0
let length = enumDef.members.length

@ -1,5 +1,5 @@
'use strict'
const ValueType = require('./ValueType')
import { ValueType } from './ValueType'
export class FixedByteArray extends ValueType {
constructor (storageBytes) {

@ -1,6 +1,6 @@
'use strict'
const util = require('./util')
const ValueType = require('./ValueType')
import { extractHexByteSlice, decodeIntFromHex } from './util'
import { ValueType } from './ValueType'
export class Int extends ValueType {
constructor (storageBytes) {
@ -8,7 +8,7 @@ export class Int extends ValueType {
}
decodeValue (value) {
value = util.extractHexByteSlice(value, this.storageBytes, 0)
return util.decodeIntFromHex(value, this.storageBytes, true)
value = extractHexByteSlice(value, this.storageBytes, 0)
return decodeIntFromHex(value, this.storageBytes, true)
}
}

@ -1,9 +1,15 @@
'use strict'
const RefType = require('./RefType')
const util = require('./util')
const ethutil = require('ethereumjs-util')
import { RefType } from './RefType'
import { normalizeHex } from './util'
import { toBuffer, setLengthLeft, keccak, BN, bufferToHex} from 'ethereumjs-util'
import { intToBuffer } from 'ethjs-util'
export class Mapping extends RefType {
keyType
valueType
initialDecodedState
constructor (underlyingTypes, location, fullType) {
super(1, 32, fullType, 'storage')
this.keyType = underlyingTypes.keyType
@ -38,7 +44,7 @@ export class Mapping extends RefType {
}
async decodeMappingsLocation (preimages, location, storageResolver) {
const mapSlot = util.normalizeHex(ethutil.bufferToHex(location.slot))
const mapSlot = normalizeHex(bufferToHex(location.slot))
if (!preimages[mapSlot]) {
return {}
}
@ -60,14 +66,14 @@ function getMappingLocation (key, position) {
// > the value corresponding to a mapping key k is located at keccak256(k . p) where . is concatenation.
// key should be a hex string, and position an int
const mappingK = ethutil.toBuffer('0x' + key)
let mappingP = ethutil.intToBuffer(position)
mappingP = ethutil.setLengthLeft(mappingP, 32)
const mappingK = toBuffer('0x' + key)
let mappingP = intToBuffer(position)
mappingP = setLengthLeft(mappingP, 32)
const mappingKeyBuf = concatTypedArrays(mappingK, mappingP)
const mappingKeyPreimage = '0x' + mappingKeyBuf.toString('hex')
let mappingStorageLocation = ethutil.keccak(mappingKeyPreimage)
mappingStorageLocation = new ethutil.BN(mappingStorageLocation, 16)
return mappingStorageLocation
const mappingKeyPreimage: string = '0x' + mappingKeyBuf.toString('hex')
let mappingStorageLocation: Buffer = keccak(mappingKeyPreimage)
const mappingStorageLocationinBn: BN = new BN(mappingStorageLocation, 16)
return mappingStorageLocationinBn
}
function concatTypedArrays (a, b) { // a, b TypedArray of same type

@ -1,5 +1,5 @@
'use strict'
const util = require('./util')
import { toBN } from './util'
export class RefType {

@ -1,14 +1,17 @@
'use strict'
const DynamicBytes = require('./DynamicByteArray')
import { DynamicByteArray } from './DynamicByteArray'
export class StringType extends DynamicByteArray {
typeName
export class StringType extends DynamicBytes {
constructor (location) {
super(location)
this.typeName = 'string'
}
async decodeFromStorage (location, storageResolver) {
let decoded = '0x'
let decoded: any = '0x'
try {
decoded = await super.decodeFromStorage(location, storageResolver)
} catch (e) {
@ -20,7 +23,7 @@ export class StringType extends DynamicBytes {
async decodeFromStack (stackDepth, stack, memory) {
try {
return await super.decodeFromStack(stackDepth, stack, memory)
return await super.decodeFromStack(stackDepth, stack, memory, null, null)
} catch (e) {
console.log(e)
return '<decoding failed - ' + e.message + '>'

@ -1,8 +1,11 @@
'use strict'
const util = require('./util')
const RefType = require('./RefType')
import { add } from './util'
import { RefType } from './RefType'
export class Struct extends RefType {
members
constructor (memberDetails, location, fullType) {
super(memberDetails.storageSlots, 32, 'struct ' + fullType, location)
this.members = memberDetails.members
@ -13,7 +16,7 @@ export class Struct extends RefType {
for (var item of this.members) {
const globalLocation = {
offset: location.offset + item.storagelocation.offset,
slot: util.add(location.slot, item.storagelocation.slot)
slot: add(location.slot, item.storagelocation.slot)
}
try {
ret[item.name] = await item.type.decodeFromStorage(globalLocation, storageResolver)

@ -1,6 +1,6 @@
'use strict'
const util = require('./util')
const ValueType = require('./ValueType')
import { extractHexByteSlice, decodeIntFromHex } from './util'
import { ValueType } from './ValueType'
export class Uint extends ValueType {
constructor (storageBytes) {
@ -8,7 +8,7 @@ export class Uint extends ValueType {
}
decodeValue (value) {
value = util.extractHexByteSlice(value, this.storageBytes, 0)
return util.decodeIntFromHex(value, this.storageBytes, false)
value = extractHexByteSlice(value, this.storageBytes, 0)
return decodeIntFromHex(value, this.storageBytes, false)
}
}

@ -1,5 +1,5 @@
'use strict'
var util = require('./util')
import { extractHexValue } from './util'
export class ValueType {
@ -24,7 +24,7 @@ export class ValueType {
*/
async decodeFromStorage (location, storageResolver) {
try {
var value = await util.extractHexValue(location, storageResolver, this.storageBytes)
var value = await extractHexValue(location, storageResolver, this.storageBytes)
return {value: this.decodeValue(value), type: this.typeName}
} catch (e) {
console.log(e)
@ -62,5 +62,3 @@ export class ValueType {
return {value: this.decodeValue(value), type: this.typeName}
}
}
module.exports = ValueType

@ -9,7 +9,7 @@ export function decodeIntFromHex (value, byteLength, signed) {
return bigNumber.toString(10)
}
export function readFromStorage(slot, storageResolver) {
export function readFromStorage(slot, storageResolver): Promise<string> {
const hexSlot = '0x' + normalizeHex(bufferToHex(slot))
return new Promise((resolve, reject) => {
storageResolver.storageSlot(hexSlot, (error, slot) => {
@ -94,7 +94,7 @@ export function extractLocationFromAstVariable (node) {
return 'default' // local variables => storage, function parameters & return values => memory, state => storage
}
export function normalizeHex (hex) {
export function normalizeHex (hex): string {
hex = hex.replace('0x', '')
if (hex.length < 64) {
return (new Array(64 - hex.length + 1).join('0')) + hex

Loading…
Cancel
Save