fix bigInt validation

pull/3951/head
Oleksii Kosynskyi 1 year ago
parent db972f23b8
commit 07c93ae358
No known key found for this signature in database
GPG Key ID: B4A8D3CCE22EA65E
  1. 3
      libs/remix-lib/package.json
  2. 5
      libs/remix-lib/src/execution/typeConversion.ts
  3. 9
      libs/remix-simulator/src/VmProxy.ts

@ -25,7 +25,8 @@
"from-exponential": "1.1.1",
"solc": "^0.7.4",
"string-similarity": "^4.0.4",
"web3": "^4.0.3"
"web3": "^4.0.3",
"web3-validator": "^1.0.2"
},
"devDependencies": {
"@babel/core": "^7.4.5",

@ -1,11 +1,12 @@
'use strict'
import { BN } from 'bn.js'
import { bufferToHex } from '@ethereumjs/util'
import { isBigInt } from 'web3-validator'
export function toInt (h) {
if (h.indexOf && h.indexOf('0x') === 0) {
return (new BN(h.replace('0x', ''), 16)).toString(10)
} else if ((h.constructor && h.constructor.name === 'BigNumber') || BN.isBN(h)) {
} else if ((h.constructor && h.constructor.name === 'BigNumber') || BN.isBN(h) || isBigInt(h)) {
return h.toString(10)
}
return h
@ -21,7 +22,7 @@ function convertToString (v) {
ret.push(convertToString(v[k]))
}
return ret
} else if (BN.isBN(v) || (v.constructor && v.constructor.name === 'BigNumber')) {
} else if (BN.isBN(v) || (v.constructor && v.constructor.name === 'BigNumber') || isBigInt(v)) {
return v.toString(10)
} else if (v._isBuffer) {
return bufferToHex(v)

@ -4,7 +4,8 @@ import { helpers } from '@remix-project/remix-lib'
const { normalizeHexAddress } = helpers.ui
import { ConsoleLogs, hash } from '@remix-project/remix-lib'
import { toChecksumAddress, bufferToHex, Address, toBuffer } from '@ethereumjs/util'
import utils, {toBigInt} from 'web3-utils'
import utils from 'web3-utils'
import {isBigInt} from 'web3-validator'
import { ethers } from 'ethers'
import { VMContext } from './vm-context'
import type { StateManager } from '@ethereumjs/statemanager'
@ -278,7 +279,7 @@ export class VmProxy {
let consoleArgs = iface.decodeFunctionData(functionDesc, payload)
consoleArgs = consoleArgs.map((value) => {
// Copied from: https://github.com/web3/web3.js/blob/e68194bdc590d811d4bf66dde12f99659861a110/packages/web3-utils/src/utils.js#L48C10-L48C10
if (value && value.constructor && value.constructor.name === 'BigNumber') {
if (value && ((value.constructor && value.constructor.name === 'BigNumber') || isBigInt(value))) {
return value.toString()
}
return value
@ -425,9 +426,9 @@ export class VmProxy {
getSha3Input (stack, memory) {
const memoryStart = toHexPaddedString(stack[stack.length - 1])
const memoryLength = toHexPaddedString(stack[stack.length - 2])
const memStartDec = toBigInt(memoryStart).toString(10)
const memStartDec = utils.toBigInt(memoryStart).toString(10)
const memoryStartInt = parseInt(memStartDec) * 2
const memLengthDec = toBigInt(memoryLength).toString(10)
const memLengthDec = utils.toBigInt(memoryLength).toString(10)
const memoryLengthInt = parseInt(memLengthDec.toString()) * 2
let i = Math.floor(memoryStartInt / 32)

Loading…
Cancel
Save