fix debugging proxy contract

pull/3168/head
yann300 2 years ago
parent 877deb68fe
commit d5d3e76a17
  1. 6
      apps/remix-ide/src/blockchain/blockchain.js
  2. 3
      libs/remix-core-plugin/src/lib/compiler-artefacts.ts
  3. 28
      libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts
  4. 6
      libs/remix-core-plugin/src/lib/constants/uups.ts
  5. 2
      libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts
  6. 8
      libs/remix-lib/src/util.ts

@ -11,7 +11,7 @@ import InjectedProvider from './providers/injected.js'
import NodeProvider from './providers/node.js' import NodeProvider from './providers/node.js'
import { execution, EventManager, helpers } from '@remix-project/remix-lib' import { execution, EventManager, helpers } from '@remix-project/remix-lib'
import { etherScanLink } from './helper' import { etherScanLink } from './helper'
import { logBuilder, cancelUpgradeMsg, cancelProxyMsg } from "@remix-ui/helper" import { logBuilder, cancelUpgradeMsg, cancelProxyMsg, addressToString } from "@remix-ui/helper"
const { txFormat, txExecution, typeConversion, txListener: Txlistener, TxRunner, TxRunnerWeb3, txHelper } = execution const { txFormat, txExecution, typeConversion, txListener: Txlistener, TxRunner, TxRunnerWeb3, txHelper } = execution
const { txResultHelper: resultToRemixTx } = helpers const { txResultHelper: resultToRemixTx } = helpers
const packageJson = require('../../../../package.json') const packageJson = require('../../../../package.json')
@ -180,7 +180,7 @@ export class Blockchain extends Plugin {
if (networkInfo.name === 'VM') this.config.set('vm/proxy', address) if (networkInfo.name === 'VM') this.config.set('vm/proxy', address)
else this.config.set(`${networkInfo.name}/${networkInfo.currentFork}/${networkInfo.id}/proxy`, address) else this.config.set(`${networkInfo.name}/${networkInfo.currentFork}/${networkInfo.id}/proxy`, address)
_paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment successful']) _paq.push(['trackEvent', 'blockchain', 'Deploy With Proxy', 'Proxy deployment successful'])
return this.call('udapp', 'resolveContractAndAddInstance', implementationContractObject, address) this.call('udapp', 'addInstance', addressToString(address), implementationContractObject.abi, implementationContractObject.name)
} }
this.runTx(args, confirmationCb, continueCb, promptCb, finalCb) this.runTx(args, confirmationCb, continueCb, promptCb, finalCb)
@ -223,7 +223,7 @@ export class Blockchain extends Plugin {
return this.call('terminal', 'logHtml', log) return this.call('terminal', 'logHtml', log)
} }
_paq.push(['trackEvent', 'blockchain', 'Upgrade With Proxy', 'Upgrade Successful']) _paq.push(['trackEvent', 'blockchain', 'Upgrade With Proxy', 'Upgrade Successful'])
return this.call('udapp', 'resolveContractAndAddInstance', newImplementationContractObject, proxyAddress) this.call('udapp', 'addInstance', addressToString(address), newImplementationContractObject.abi, newImplementationContractObject.name)
} }
this.runTx(args, confirmationCb, continueCb, promptCb, finalCb) this.runTx(args, confirmationCb, continueCb, promptCb, finalCb)
} }

@ -198,8 +198,7 @@ export class CompilerArtefacts extends Plugin {
return this.compilersArtefactsPerFile[file] return this.compilersArtefactsPerFile[file]
} }
// compilerData is a CompilerAbstract object addResolvedContract (address: string, compilerData: CompilerAbstract) {
addResolvedContract (address, compilerData) {
this.compilersArtefacts[address] = compilerData this.compilersArtefacts[address] = compilerData
} }

@ -4,6 +4,7 @@ import { util } from '@remix-project/remix-lib'
import { toChecksumAddress } from 'ethereumjs-util' import { toChecksumAddress } from 'ethereumjs-util'
import { fetchContractFromEtherscan } from './helpers/fetch-etherscan' import { fetchContractFromEtherscan } from './helpers/fetch-etherscan'
import { fetchContractFromSourcify } from './helpers/fetch-sourcify' import { fetchContractFromSourcify } from './helpers/fetch-sourcify'
import { UUPSDeployedByteCode, UUPSCompilerVersion } from './constants/uups'
const profile = { const profile = {
name: 'fetchAndCompile', name: 'fetchAndCompile',
@ -48,6 +49,33 @@ export class FetchAndCompile extends Plugin {
if (resolved) return resolved if (resolved) return resolved
if (this.unresolvedAddresses.includes(contractAddress)) return localCompilation() if (this.unresolvedAddresses.includes(contractAddress)) return localCompilation()
if (codeAtAddress === '0x' + UUPSDeployedByteCode) { // proxy
const settings = {
version: UUPSCompilerVersion,
language: 'Solidity',
evmVersion: null,
optimize: false,
runs: 0
}
const compilationTargets = {
'proxy.sol': { content: 'import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.0/contracts/proxy/ERC1967/ERC1967Proxy.sol";' }
}
const compData = await compile(
compilationTargets,
settings,
async (url, cb) => {
// we first try to resolve the content from the compilation target using a more appropiate path
const path = `${targetPath}/${url}`
if (compilationTargets[path] && compilationTargets[path].content) {
return cb(null, compilationTargets[path].content)
} else {
await this.call('contentImport', 'resolveAndSave', url).then((result) => cb(null, result)).catch((error) => cb(error.message))
}
})
await this.call('compilerArtefacts', 'addResolvedContract', contractAddress, compData)
return compData
}
// sometimes when doing an internal call, the only available artifact is the Solidity interface. // sometimes when doing an internal call, the only available artifact is the Solidity interface.
// resolving addresses of internal call would allow to step over the source code, even if the declaration was made using an Interface. // resolving addresses of internal call would allow to step over the source code, even if the declaration was made using an Interface.

File diff suppressed because one or more lines are too long

@ -119,4 +119,4 @@ export class OpenZeppelinProxy extends Plugin {
newImplementationContractObject.name = proxyName newImplementationContractObject.name = proxyName
this.blockchain.upgradeProxy(proxyAddress, newImplAddress, data, newImplementationContractObject) this.blockchain.upgradeProxy(proxyAddress, newImplAddress, data, newImplementationContractObject)
} }
} }

@ -239,6 +239,10 @@ export function compareByteCode (code1, code2) {
code2 = replaceLibReference(code2, pos) code2 = replaceLibReference(code2, pos)
code1 = replaceLibReference(code1, pos) code1 = replaceLibReference(code1, pos)
} }
code1 = removeImmutableReference(code1)
code2 = removeImmutableReference(code2)
code1 = extractinputParameters(code1) code1 = extractinputParameters(code1)
code1 = extractSwarmHash(code1) code1 = extractSwarmHash(code1)
code1 = extractcborMetadata(code1) code1 = extractcborMetadata(code1)
@ -276,6 +280,10 @@ function replaceLibReference (code, pos) {
return code.substring(0, pos) + '0000000000000000000000000000000000000000' + code.substring(pos + 40) return code.substring(0, pos) + '0000000000000000000000000000000000000000' + code.substring(pos + 40)
} }
function removeImmutableReference (code) {
return code.replace(/7f([0-9a-f]{64})73/g, '')
}
function findCallInternal (index, rootCall, callsPath) { function findCallInternal (index, rootCall, callsPath) {
const calls = Object.keys(rootCall.calls) const calls = Object.keys(rootCall.calls)
const ret = rootCall const ret = rootCall

Loading…
Cancel
Save