Last active
October 1, 2015 13:59
-
-
Save chriseth/95e9e149b7775d9eaf3d to your computer and use it in GitHub Desktop.
Bytecode verifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: node verify.js file_with_source_code file_with_hex_bytecode compiler_binary... | |
var fs = require('fs'); | |
var source = fs.readFileSync(process.argv[2]).toString(); | |
var binary = fs.readFileSync(process.argv[3]).toString().replace(/\s+/, ''); | |
if (binary.substring(0, 2) == '0x') | |
binary = binary.substring(2); | |
var matchFound = false; | |
process.argv.forEach(function(compilerFile, i) { | |
if (i < 4) return; | |
var compiler = require('./' + compilerFile); | |
var version = compiler.cwrap('version', 'string'); | |
console.log("Checking against compiler version " + version()); | |
var compile = compiler.cwrap( | |
'compileJSON', | |
'string', | |
['string', 'number'] | |
); | |
for (var optimized in [0, 1]) { | |
var optimizedStr = optimized ? 'optimized ' : 'non-optimized '; | |
var compilerOutput = JSON.parse(compile(source, optimized)); | |
for (var contractName in compilerOutput.contracts) { | |
var contract = compilerOutput.contracts[contractName]; | |
var match = null; | |
if (binary == contract.runtimeBytecode) | |
match = optimizedStr + 'runtime'; | |
if (binary == contract.bytecode) | |
match = optimizedStr + 'creation time'; | |
if (match !== null) | |
{ | |
console.log("Bytecode MATCHES the " + match + " bytecode of the contract " + contractName); | |
matchFound = true; | |
} | |
} | |
} | |
}); | |
if (!matchFound) | |
console.log("NO match found."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment