Skip to content

Commit 018d8ac

Browse files
committed
no web3-utils in remix-simulator
1 parent 868259c commit 018d8ac

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

libs/remix-simulator/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"string-similarity": "^4.0.4",
4141
"time-stamp": "^2.0.0",
4242
"tslib": "^2.3.0",
43-
"web3": "^4.1.1",
44-
"web3-utils": "^4.0.5"
43+
"web3": "^4.1.1"
4544
},
4645
"devDependencies": {
4746
"@babel/core": "^7.4.5",

libs/remix-simulator/src/VmProxy.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { ConsoleLogs, hash, util, helpers } from '@remix-project/remix-lib'
33
const { toHexPaddedString, formatMemory, padHexToEven } = util
44
const { normalizeHexAddress } = helpers.ui
55
import { toChecksumAddress, bytesToHex, toBytes, createAddressFromString, PrefixedHexString } from '@ethereumjs/util'
6-
import utils, { toBigInt } from 'web3-utils'
7-
import { isBigInt } from 'web3-validator'
8-
import { Interface, zeroPadValue } from 'ethers'
6+
import { Interface, zeroPadValue, keccak256, hexlify, toUtf8String, toUtf8Bytes, formatEther, parseEther, isAddress } from 'ethers'
97
import { VMContext } from './vm-context'
108
import type { StateManagerInterface } from '@ethereumjs/common'
119
import type { InterpreterStep } from '@ethereumjs/evm'
@@ -39,7 +37,6 @@ export class VmProxy {
3937
toWei
4038
toBigNumber
4139
isAddress
42-
utils
4340
txsMapBlock
4441
blocks
4542
stateCopy: StateManagerInterface
@@ -77,16 +74,14 @@ export class VmProxy {
7774
this.storageCache = {}
7875
this.sha3Preimages = {}
7976
// util
80-
this.sha3 = (...args) => utils.sha3.apply(this, args)
81-
this.toHex = (...args) => utils.toHex.apply(this, args)
82-
this.toAscii = (...args) => utils.toAscii.apply(this, args)
83-
this.fromAscii = (...args) => utils.fromAscii.apply(this, args)
84-
this.fromDecimal = (...args) => utils.fromDecimal.apply(this, args)
85-
this.fromWei = (...args) => utils.fromWei.apply(this, args)
86-
this.toWei = (...args) => utils.toWei.apply(this, args)
87-
this.toBigNumber = (...args) => toBigInt.apply(this, args)
88-
this.isAddress = (...args) => utils.isAddress.apply(this, args)
89-
this.utils = utils
77+
this.sha3 = (...args) => keccak256.apply(this, args)
78+
this.toHex = (...args) => hexlify.apply(this, args)
79+
this.toAscii = (...args) => toUtf8String.apply(this, args)
80+
this.fromAscii = (...args) => toUtf8Bytes.apply(this, args)
81+
this.fromWei = (...args) => formatEther.apply(this, args)
82+
this.toWei = (...args) => parseEther.apply(this, args)
83+
this.toBigNumber = (...args) => BigInt.apply(this, args)
84+
this.isAddress = (...args) => isAddress.apply(this, args)
9085
this.txsMapBlock = {}
9186
this.blocks = {}
9287
this.lastMemoryUpdate = []
@@ -285,7 +280,7 @@ export class VmProxy {
285280
const consoleArgs = iface.decodeFunctionData(functionDesc, payload)
286281
const consoleArgsMapped = consoleArgs.map((value) => {
287282
// Copied from: https://github.com/web3/web3.js/blob/e68194bdc590d811d4bf66dde12f99659861a110/packages/web3-utils/src/utils.js#L48C10-L48C10
288-
if (value && ((value.constructor && value.constructor.name === 'BigNumber') || isBigInt(value))) {
283+
if (value && ((value.constructor && value.constructor.name === 'BigNumber') || typeof value === 'bigint')) {
289284
return value.toString()
290285
}
291286
return value
@@ -432,9 +427,9 @@ export class VmProxy {
432427
getSha3Input (stack, memory) {
433428
const memoryStart = toHexPaddedString(stack[stack.length - 1])
434429
const memoryLength = toHexPaddedString(stack[stack.length - 2])
435-
const memStartDec = toBigInt(memoryStart).toString(10)
430+
const memStartDec = BigInt(memoryStart).toString(10)
436431
const memoryStartInt = parseInt(memStartDec) * 2
437-
const memLengthDec = toBigInt(memoryLength).toString(10)
432+
const memLengthDec = BigInt(memoryLength).toString(10)
438433
const memoryLengthInt = parseInt(memLengthDec.toString()) * 2
439434

440435
let i = Math.floor(memoryStartInt / 32)

libs/remix-simulator/src/methods/accounts.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { signTypedData, SignTypedDataVersion, TypedMessage, MessageTypes } from '@metamask/eth-sig-util'
22
import { privateToAddress, toChecksumAddress, isValidPrivate, createAddressFromString, toBytes, bytesToHex, Account, intToHex } from '@ethereumjs/util'
33
import type { PrefixedHexString } from '@ethereumjs/util'
4-
import { privateKeyToAccount } from 'web3-eth-accounts'
4+
import { ethers } from 'ethers'
55
import * as crypto from 'crypto'
66

77
type AccountType = {
@@ -121,11 +121,11 @@ export class Web3Accounts {
121121
if (!privateKey) {
122122
return cb(new Error('unknown account'))
123123
}
124-
const account = privateKeyToAccount(privateKey as string)
124+
const account = new ethers.Wallet(privateKey as string)
125125

126-
const data = account.sign(message)
127-
128-
cb(null, data.signature)
126+
account.signMessage(message).then((signature) => {
127+
cb(null, signature)
128+
})
129129
}
130130

131131
eth_chainId (_payload, cb) {

0 commit comments

Comments
 (0)