Commit 1a54ef52 authored by ben-chain's avatar ben-chain Committed by Kelvin Fichter

fix(regenesis-surgery): prevent collisions between cached EVM and OVM outputs

parent db9526c3
...@@ -173,8 +173,13 @@ export const solcInput = (contract: EtherscanContract) => { ...@@ -173,8 +173,13 @@ export const solcInput = (contract: EtherscanContract) => {
} }
const compilerCache: { const compilerCache: {
[hash: string]: any [target: string]: {
} = {} [hash: string]: any
}
} = {
['OVM']: {},
['EVM']: {},
}
export const compile = (opts: { export const compile = (opts: {
contract: EtherscanContract contract: EtherscanContract
...@@ -195,16 +200,17 @@ export const compile = (opts: { ...@@ -195,16 +200,17 @@ export const compile = (opts: {
const solcInstance = getSolc(version, opts.ovm) const solcInstance = getSolc(version, opts.ovm)
const input = JSON.stringify(solcInput(opts.contract)) const input = JSON.stringify(solcInput(opts.contract))
const inputHash = ethers.utils.solidityKeccak256(['string'], [input]) const inputHash = ethers.utils.solidityKeccak256(['string'], [input])
const compilerTarget = opts.ovm ? 'OVM' : 'EVM'
// Cache the compiler output to speed up repeated compilations of the same contract. If this // Cache the compiler output to speed up repeated compilations of the same contract. If this
// cache is too memory intensive, then we could consider only caching if the contract has been // cache is too memory intensive, then we could consider only caching if the contract has been
// seen more than once. // seen more than once.
let output: any let output: any
if (compilerCache[inputHash]) { if (compilerCache[compilerTarget][inputHash]) {
output = compilerCache[inputHash] output = compilerCache[compilerTarget][inputHash]
} else { } else {
output = JSON.parse(solcInstance.compile(input)) output = JSON.parse(solcInstance.compile(input))
compilerCache[inputHash] = output compilerCache[compilerTarget][inputHash] = output
} }
if (!output.contracts) { if (!output.contracts) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment