()
| 14 | } |
| 15 | |
| 16 | async function checkClashes() { |
| 17 | console.log(chalk.green("Starting function selector clash check")); |
| 18 | let files = await readFiles(); |
| 19 | let contractFunctions = new Set(); |
| 20 | let functionSelectors = new Map(); |
| 21 | files.forEach(item => { |
| 22 | let ABI = JSON.parse(fs.readFileSync(`./build/contracts/${item}`).toString()).abi; |
| 23 | ABI.forEach(element => { |
| 24 | if (element['type'] == 'function') { |
| 25 | let functionSig = element['name'] + '('; |
| 26 | element['inputs'].forEach(input => { |
| 27 | functionSig = functionSig + input['type'] + ','; |
| 28 | }); |
| 29 | if(functionSig[functionSig.length - 1] == ',') |
| 30 | functionSig = functionSig.slice(0, -1) + ')'; |
| 31 | else |
| 32 | functionSig = functionSig + ')'; |
| 33 | contractFunctions.add(functionSig); |
| 34 | } |
| 35 | }); |
| 36 | }); |
| 37 | let clashesFound = false; |
| 38 | contractFunctions.forEach(functionSig => { |
| 39 | let fnSelector = Web3.utils.sha3(functionSig).slice(0, 10); |
| 40 | if(functionSelectors.has(fnSelector)) { |
| 41 | clashesFound = true; |
| 42 | console.log(chalk.red('Function selector clash found!', functionSelectors.get(fnSelector), 'and', functionSig, 'have the same function selector:', fnSelector)); |
| 43 | functionSelectors.set(fnSelector, functionSelectors.get(fnSelector) + ', ' + functionSig); |
| 44 | } else { |
| 45 | functionSelectors.set(fnSelector, functionSig); |
| 46 | } |
| 47 | }); |
| 48 | if (clashesFound) { |
| 49 | console.log(chalk.yellow("The clash(es) might be in two different contracts and hence not be am Issue.\nThis script can not detect this (yet) because of proxy contracts")); |
| 50 | throw("Clash(es) found! Please fix."); |
| 51 | } |
| 52 | console.log(chalk.green("Clash check finished. No Clashes found.")); |
| 53 | } |
| 54 | |
| 55 | checkClashes(); |
no test coverage detected