Skip to content

Instantly share code, notes, and snippets.

@chriseth
Last active October 1, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriseth/95e9e149b7775d9eaf3d to your computer and use it in GitHub Desktop.
Save chriseth/95e9e149b7775d9eaf3d to your computer and use it in GitHub Desktop.
Bytecode verifier
// 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