diff --git a/libs/remix-lib/src/util.ts b/libs/remix-lib/src/util.ts index cc70e786e8..f14e48174a 100644 --- a/libs/remix-lib/src/util.ts +++ b/libs/remix-lib/src/util.ts @@ -1,5 +1,6 @@ 'use strict' import { BN, bufferToHex, keccak, setLengthLeft, toBuffer, addHexPrefix } from 'ethereumjs-util' +import stringSimilarity from 'string-similarity' /* contains misc util: @TODO should be splitted @@ -222,8 +223,9 @@ export function compareByteCode (code1, code2) { code2 = this.extractSwarmHash(code2) code2 = this.extractcborMetadata(code2) - if (code1 && code2 && code1.indexOf(code2) === 0) { - return true + if (code1 && code2) { + const compare = stringSimilarity.compareTwoStrings(code1, code2) + return compare > 0.5 } return false } diff --git a/package-lock.json b/package-lock.json index fa010f1b61..9e028132b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36072,6 +36072,11 @@ } } }, + "string-similarity": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/string-similarity/-/string-similarity-4.0.4.tgz", + "integrity": "sha512-/q/8Q4Bl4ZKAPjj8WerIBJWALKkaPRfrvhfF8k/B23i4nzrlRj2/go1m90In7nG/3XDSbOo0+pu6RvCTM9RGMQ==" + }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", diff --git a/package.json b/package.json index 895639bd6c..07ab9d39e1 100644 --- a/package.json +++ b/package.json @@ -172,6 +172,7 @@ "react-dom": "16.13.1", "selenium": "^2.20.0", "signale": "^1.4.0", + "string-similarity": "^4.0.4", "time-stamp": "^2.2.0", "tslib": "^2.3.0", "web3": "1.2.4",