Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function deploy(contractName, { from, args, log }) {
var sources = {
[contractName]: {
content: fs.readFileSync(`${contracts}/${contractName}.sol`).toString()
}
}
var compileOpts = JSON.stringify({ ...solcOpts, sources })
// Compile the contract using solc
var rawOutput = solc.compileStandardWrapper(
compileOpts,
findImportsPath(contracts)
)
var output = JSON.parse(rawOutput)
// If there were any compilation errors, throw them
if (output.errors) {
output.errors.forEach(err => {
if (!err.formattedMessage.match(/Warning:/)) {
throw new SyntaxError(err.formattedMessage)
}
})
}
var { abi, evm: { bytecode } } = output.contracts[contractName][
contractName
outputSelection: {
'*': {
'': [ 'legacyAST' ],
'*': [ 'abi', 'metadata', 'devdoc', 'userdoc', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates' ]
}
}
}
}
inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString()}
console.dir(inputJson)
console.log('compiling...')
let compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson)))
console.dir(Object.keys(compilationData))
var compilation = {}
compilation.data = compilationData
compilation.source = { sources: inputJson.sources }
console.dir(compilation)
console.dir(compilation.data.errors)
var cmdLine = new CmdLine()
cmdLine.connect('http', 'http://localhost:8545')
cmdLine.loadCompilationResult(compilation)
cmdLine.initDebugger()
// var deployContract = function (cb) {
// let _web3 = cmdLine.debugger.debugger.web3
//
// let blockNumber = null
export function mythrilAnalyze() {
const solidityConfig = vscode.workspace.getConfiguration('solidity');
const outputChannel = vscode.window.createOutputChannel('Mythril');
const options = {
apiKey: solidityConfig.mythrilAPIKey,
platforms: ['vscode-solidity'], // client chargeback
userEmail: 'user@example.com',
};
const pathAndCode = solidityPathAndSource();
if (!pathAndCode) {
return;
}
const output = solc.compileStandardWrapper(compilerInput(pathAndCode.code));
const outputJSON = JSON.parse(output);
if ('errors' in outputJSON) {
outputChannel.clear();
outputChannel.show();
outputJSON.array.forEach(element => {
outputChannel.appendLine(element);
});
return;
}
const contractsJSON = outputJSON.contracts['test.sol'];
const contractNames = Object.keys(contractsJSON);
if (contractNames.length === 0) {
showMessage('No contract found');
return;
} else if (contractNames.length !== 1) {
t.test('storage location', function (st) {
var output = compiler.compileStandardWrapper(helpers.compilerInput(contracts))
output = JSON.parse(output)
var stateDec = index.solidity.stateDecoder.extractStateVariables('contractUint', output.sources)
checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].storagelocation, 1, 0)
checkLocation(st, stateDec[2].storagelocation, 2, 0)
checkLocation(st, stateDec[3].storagelocation, 3, 0)
stateDec = index.solidity.stateDecoder.extractStateVariables('contractStructAndArray', output.sources)
checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].storagelocation, 2, 0)
checkLocation(st, stateDec[2].storagelocation, 8, 0)
stateDec = index.solidity.stateDecoder.extractStateVariables('contractArray', output.sources)
checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].storagelocation, 1, 0)
checkLocation(st, stateDec[2].storagelocation, 2, 0)
function test (st, vm, privateKey) {
var output = compiler.compileStandardWrapper(helpers.compilerInput(intLocal.contract))
output = JSON.parse(output)
intLocalTest(st, vm, privateKey, output.contracts['test.sol']['intLocal'].evm.bytecode.object, output, function () {
output = compiler.compileStandardWrapper(helpers.compilerInput(miscLocal.contract))
output = JSON.parse(output)
miscLocalTest(st, vm, privateKey, output.contracts['test.sol']['miscLocal'].evm.bytecode.object, output, function () {
output = compiler.compileStandardWrapper(helpers.compilerInput(miscLocal.contract))
output = JSON.parse(output)
misc2LocalTest(st, vm, privateKey, output.contracts['test.sol']['miscLocal2'].evm.bytecode.object, output, function () {
output = compiler.compileStandardWrapper(helpers.compilerInput(structArrayLocal.contract))
output = JSON.parse(output)
structArrayLocalTest(st, vm, privateKey, output.contracts['test.sol']['structArrayLocal'].evm.bytecode.object, output, function () {})
})
})
})
}
state = index.solidity.astHelper.extractStateDefinitions('test.sol:contractSmallVariable', output.sources)
stateDef = state.stateDefinitions
decodeInfo = index.solidity.decodeInfo.parseType(stateDef[0].attributes.type, states, 'contractSmallVariable')
checkDecodeInfo(st, decodeInfo, 1, 1, 'int8')
decodeInfo = index.solidity.decodeInfo.parseType(stateDef[1].attributes.type, states, 'contractSmallVariable')
checkDecodeInfo(st, decodeInfo, 1, 1, 'uint8')
decodeInfo = index.solidity.decodeInfo.parseType(stateDef[2].attributes.type, states, 'contractSmallVariable')
checkDecodeInfo(st, decodeInfo, 1, 2, 'uint16')
decodeInfo = index.solidity.decodeInfo.parseType(stateDef[3].attributes.type, states, 'contractSmallVariable')
checkDecodeInfo(st, decodeInfo, 1, 4, 'int32')
decodeInfo = index.solidity.decodeInfo.parseType(stateDef[4].attributes.type, states, 'contractSmallVariable')
checkDecodeInfo(st, decodeInfo, 1, 32, 'uint256')
decodeInfo = index.solidity.decodeInfo.parseType(stateDef[5].attributes.type, states, 'contractSmallVariable')
checkDecodeInfo(st, decodeInfo, 1, 2, 'int16')
output = compiler.compileStandardWrapper(helpers.compilerInput(simplecontracts))
output = JSON.parse(output)
state = index.solidity.astHelper.extractStateDefinitions('test.sol:simpleContract', output.sources)
states = index.solidity.astHelper.extractStatesDefinitions(output.sources)
stateDef = state.stateDefinitions
decodeInfo = index.solidity.decodeInfo.parseType(stateDef[2].attributes.type, states, 'simpleContract')
checkDecodeInfo(st, decodeInfo, 2, 32, 'struct simpleContract.structDef')
decodeInfo = index.solidity.decodeInfo.parseType(stateDef[3].attributes.type, states, 'simpleContract')
checkDecodeInfo(st, decodeInfo, 6, 32, 'struct simpleContract.structDef[3]')
decodeInfo = index.solidity.decodeInfo.parseType(stateDef[4].attributes.type, states, 'simpleContract')
checkDecodeInfo(st, decodeInfo, 1, 1, 'enum')
state = index.solidity.astHelper.extractStateDefinitions('test.sol:test2', output.sources)
stateDef = state.stateDefinitions
decodeInfo = index.solidity.decodeInfo.parseType(stateDef[0].attributes.type, states, 'test1')
checkDecodeInfo(st, decodeInfo, 0, 32, 'struct test1.str')
function testStructArrayStorage (st, cb) {
var structArrayStorage = require('./contracts/structArrayStorage')
var output = compiler.compileStandardWrapper(helpers.compilerInput(structArrayStorage.contract))
output = JSON.parse(output)
var mockStorageResolver = new MockStorageResolver(structArrayStorage.storage)
stateDecoder.solidityState(mockStorageResolver, output.sources, 'structArrayStorage').then((decoded) => {
st.equal(decoded['intStructDec'].value['i8'].value, '32')
st.equal(decoded['intStructDec'].value['i16'].value, '-54')
st.equal(decoded['intStructDec'].value['ui32'].value, '128')
st.equal(decoded['intStructDec'].value['i256'].value, '-1243565465756')
st.equal(decoded['intStructDec'].value['ui16'].value, '34556')
st.equal(decoded['intStructDec'].value['i32'].value, '-345446546')
st.equal(decoded['i5'].length, '0x7')
st.equal(decoded['i5'].value[0].value, '-2134')
st.equal(decoded['i5'].value[1].value, '345')
st.equal(decoded['i5'].value[2].value, '-3246')
st.equal(decoded['i5'].value[3].value, '4357')
st.equal(decoded['i5'].value[4].value, '324')
st.equal(decoded['i5'].value[5].value, '-2344')
public compile() {
if (this.reporter) {
this.reporter.onCompileStart(this);
}
const importer = (file: string) => {
file = this.normalizePath(file);
return {
contents: fs.readFileSync(file).toString(),
};
};
const input = JSON.stringify(this.input);
this.output = JSON.parse(
solc.compileStandardWrapper(input, importer)
);
if (this.reporter) {
this.reporter.onCompileEnd(this);
}
return !Array.isArray(this.output.errors);
}
function solidityCompile(filename, lookupIncludeFile) {
const inputBasename = path.basename(filename).toString()
const input = {
language: 'Solidity',
sources: { [inputBasename]: { urls: [filename] } },
settings: {
outputSelection: {
[inputBasename]: {
'*': ['abi', 'evm.bytecode']
}
}
}
}
const solOutput = solc.compileStandardWrapper(
JSON.stringify(input),
lookupIncludeFile
)
return JSON.parse(solOutput)
}