Smart Contract Consistency Verification

This is a tool to help verify the consistency between the source code of a smart contract and its online runtimeCode.

Check it in GitHub


[block:code] { “codes”: [ { “code”: “npm install –save vscc”, “language”: “text” } ] } [/block]


Interface [block:code] { “codes”: [ { “code”: “interface IVerifyContract {\n sourceCode: string, // base64 of contract source code\n isOptimizer?: boolean, // whether optimizer (default: false)\n contractAddress: string, // contract address\n solcVersion?: string, // compiler version (default: solc version)\n params?: string, // contract constructor params encode abi (default: ‘’)\n contractName: string, // contract name for compile\n txId: string, // txid of deployed contract\n runs?: string, // compiler runs (default 200)\n}”, “language”: “text” } ] } [/block]


Verify [block:code] { “codes”: [ { “code”: “import { BlockChain, Utils, Vscc} from ‘vscc’\n\nconst fs = require(‘fs’)\nconst path = require(‘path’)\nconst binPath = path.join(__dirname, ‘./bins’)\n\nasync function testVscc() {\n\n if(!fs.existsSync(bins)) {\n fs.mkdirSync(bins)\n }\n\n const soljson424 = ‘0.4.24’\n const base64Code = Utils.encodeBase64(‘/source code/’)\n const c_addr = ‘/contract address/’\n const txId = ‘/txid/’\n const runs = ‘200’\n const p = {\n sourceCode: base64Code,\n isOptimizer: false,\n contractAddress: c_addr,\n solcVersion: soljson424,\n contractName: ‘/contract name/’,\n txId: txId,\n runs: runs\n }\n\n try {\n const ins = new Vscc(‘/rpc endpoint/’, binPath)\n // return true or false \n const re = await ins.verify(p)\n console.log(‘re: ‘, re)\n } catch (error) {\n console.log(error)\n }\n}”, “language”: “text” } ] } [/block]

Download Compiler

If the target compiler does not exist, download it first. [block:code] { “codes”: [ { “code”: “import { download } from ‘vscc’\n\ntry {\n await download(version, bins)\n} catch (error) {\n console.log(error)\n}”, “language”: “text” } ] } [/block]


[block:code] { “codes”: [ { “code”: “|–Vscc\n| |–verify \n|–BlockChain\n| |–getCode\n| |–deployContractOfCall\n| |–accounts\n| |–getTransaction\n|–DownloadCompiler\n| |–download\n| |–getVersionList\n|–Util\n| |–decodeBase64\n| |–encodeBase64”, “language”: “text” } ] } [/block]


  • GNU v3