コード例 #1
0
ファイル: VccPlugin.cs プロジェクト: tupipa/vcc
 private Program TranslateToBoogie(Microsoft.FSharp.Collections.FSharpList <BoogieAST.Decl> boogieDecls)
 {
     try {
         swBoogieAST.Start();
         return(BoogieAST.trProgram(boogieDecls));
     } finally {
         swBoogieAST.Stop();
     }
 }
コード例 #2
0
        public BatchExeResult Execute(string filename, out string expected, out string current)
        {
            BatchExeResult result   = BatchExeResult.SolcError;
            string         filePath = Path.Combine(testDirectory, filename);

            // compile the program
            SolidityCompiler compiler       = new SolidityCompiler();
            CompilerOutput   compilerOutput = compiler.Compile(solcPath, filePath);

            if (compilerOutput.ContainsError())
            {
                compilerOutput.PrintErrorsToConsole();
                throw new SystemException("Compilation Error");
            }

            // build the Solidity AST from solc output
            AST solidityAST = new AST(compilerOutput, Path.GetDirectoryName(filePath));

            // translate Solidity to Boogie
            try
            {
                BoogieTranslator translator = new BoogieTranslator();
                var translatorFlags         = new TranslatorFlags();
                translatorFlags.GenerateInlineAttributes = false;
                BoogieAST boogieAST = translator.Translate(solidityAST, new HashSet <Tuple <string, string> >(), translatorFlags);

                // dump the Boogie program to a file
                using (var outWriter = new StreamWriter(outFile))
                {
                    outWriter.WriteLine(boogieAST.GetRoot());
                }
            } catch (Exception e)
            {
                Console.WriteLine($"VeriSol translation error: {e.Message}");
                result   = BatchExeResult.SolToBoogieError;
                expected = current = null;
                return(result);
            }

            // read the corral configuration from Json
            string configJsonPath            = Path.Combine(configDirectory, Path.GetFileNameWithoutExtension(filename) + ".json");
            string jsonString                = File.ReadAllText(configJsonPath);
            CorralConfiguration corralConfig = JsonConvert.DeserializeObject <CorralConfiguration>(jsonString);

            string corralOutput = RunCorral(corralConfig);

            expected = corralConfig.ExpectedResult;
            current  = corralOutput;
            result   = CompareCorralOutput(corralConfig.ExpectedResult, corralOutput);
            return(result);
        }
コード例 #3
0
ファイル: VccPlugin.cs プロジェクト: tupipa/vcc
        internal Boogie.Program GetBoogieProgram(Microsoft.FSharp.Collections.FSharpList <BoogieAST.Decl> boogieDecls)
        {
            var p = BoogieAST.trProgram(boogieDecls);

            try {
                swBoogie.Start();
                var pp = new Boogie.Program();
                pp.TopLevelDeclarations.AddRange(VccCommandLineHost.StandardPrelude(options).TopLevelDeclarations);
                pp.TopLevelDeclarations.AddRange(p.TopLevelDeclarations);
                return(pp);
            } finally {
                swBoogie.Stop();
            }
        }
コード例 #4
0
        //returns a boogieAST reference, containing all captured elements of the sol file in question
        public BoogieAST Translate(AST solidityAST, HashSet <Tuple <string, string> > ignoredMethods, Flags_HelperClass _translatorFlags = null)
        {
            //ignored methods and translator flags need to be remove as not enough time to implement these.

            sourceUnits = solidityAST.GetSourceUnits();

            //create an empty AST_Handler Instance with no ignored method, generate InlineAttributes and no translator flags.
            AST_Handler context = new AST_Handler(ignoredMethods, true, _translatorFlags);

            context.IdToNodeMap     = solidityAST.GetIdToNodeMap();
            context.SourceDirectory = solidityAST.SourceDirectory;

            //assign class instance to temporary instance and use it throughout the rest of the
            //process to populate it.
            classTranslatorContext = context;

            //Execute Collection process from given sol contract.
            //Will enable boogie conversion to occur once specific states/functions/variables have been retrieved from the contract.
            executeSourceInfoCollector();
            executeContractCollection();

            executeInheritanceCollector();
            executeStateVariableCollector();
            executeMapArrayCollector();
            executeConstructorCollector();

            executeFunctionEventCollector();
            executeFunctionEventResolver();

            executeBoogieGenerator();
            executeDefinitionsCollector();

            executeProcessHandler();
            // generate harness for contract
            // non specifiable property, harness is always created and cannot be altered in this code
            OverSight_Harness_Generator harnessGenerator = new OverSight_Harness_Generator();

            harnessGenerator.setTranslatorContext(classTranslatorContext);
            harnessGenerator.createHarness();


            BoogieAST completeAST = new BoogieAST(classTranslatorContext.getProgram);

            Debug.Assert(completeAST != null);

            //returns the BoogieAST containing the root property, where the declarations of the contract are present.
            return(completeAST);
        }
コード例 #5
0
        /**
         * Runs solidity conversion function
         */
        private bool runSolidityToBoogieConversion()
        {
            Console.WriteLine("Starting Solidity Compiler.");

            // compile the program
            Console.WriteLine($"Running Compiler on {contractName}.");

            SolidityCompiler compiler       = new SolidityCompiler();
            CompilerOutput   compilerOutput = compiler.Compile(solidityCompilerPath, solidityFilePath);

            if (compilerOutput.ContainsError())
            {
                compilerOutput.PrintErrorsToConsole();
                throw new SystemException("Compilation Error");
            }

            // build the Solidity AST from solc output
            AST solidityAST = new AST(compilerOutput, Path.GetDirectoryName(solidityFilePath));

            // translate Solidity to Boogie
            try
            {
                // if application reaches this stage, compilation of the program was successful
                // The application now attemps to convert the solidity code to Boogie through the use of collection and syntax trees.

                ConversionToBoogie_Main translator = new ConversionToBoogie_Main();
                Console.WriteLine($"\nAttempting Conversion to Boogie.");
                BoogieAST boogieAST = translator.Translate(solidityAST, ignoreMethods, translatorFlags);

                // dump the Boogie program to a file
                var outFilePath = Path.Combine(solidityFileDir, boogieRepresentationOfSolContract);
                using (var outWriter = new StreamWriter(boogieRepresentationOfSolContract))
                {
                    outWriter.WriteLine(boogieAST.GetRoot());//get all AST components
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"OverSight translation error: {e.Message}");
                return(false);
            }
            return(true);
        }
コード例 #6
0
ファイル: VeriSolExecuter.cs プロジェクト: daejunpark/verisol
        private bool ExecuteSolToBoogie()
        {
            // compile the program
            Console.WriteLine($"\n----- Running Solc on {SpecFilePath}....");

            SolidityCompiler compiler       = new SolidityCompiler();
            CompilerOutput   compilerOutput = compiler.Compile(SolcPath, SpecFilePath);

            if (compilerOutput.ContainsError())
            {
                compilerOutput.PrintErrorsToConsole();
                throw new SystemException("Compilation Error");
            }

            // build the Solidity AST from solc output
            AST solidityAST = new AST(compilerOutput, Path.GetDirectoryName(SpecFilePath));

            // translate Solidity to Boogie
            try
            {
                BoogieTranslator translator = new BoogieTranslator();
                Console.WriteLine($"\n----- Running SolToBoogie....");
                var translatorFlags = new TranslatorFlags();
                translatorFlags.GenerateInlineAttributes = true;
                BoogieAST boogieAST = translator.Translate(solidityAST, ignoreMethods, translatorFlags);

                // dump the Boogie program to a file
                var outFilePath = Path.Combine(SpecFileDir, outFileName);
                using (var outWriter = new StreamWriter(outFileName))
                {
                    outWriter.WriteLine(boogieAST.GetRoot());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"VeriSol translation error: {e.Message}");
                return(false);
            }
            return(true);
        }
コード例 #7
0
        public static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Usage: SolToBoogie <relative path to filename.sol> <workingdir> <relative path to outfile.bpl> [options]");
                Console.WriteLine("\t Options:");
                Console.WriteLine("\t\t /break: Opens the debugger");
                Console.WriteLine("\t\t /ignoreMethod:<method>@<contract>: Ignores translation of the method within contract, and only generates a declaration");
                Console.WriteLine("\t\t\t\t multiple such pairs can be specified, ignored set is the union");
                Console.WriteLine("\t\t\t\t a wild card '*' can be used for method, would mean all the methods of the contract");
                Console.WriteLine("\t\t /noInlineAttrs: do not generate any {:inline x} attributes, to speed Corral");
                return;
            }

            string filePath         = Path.Combine(Directory.GetCurrentDirectory(), args[0]);
            string workingDirectory = args[1];
            string outFile          = Path.Combine(Directory.GetCurrentDirectory(), args[2]);

            string           solcName       = GetSolcNameByOSPlatform();
            string           solcPath       = Path.Combine(workingDirectory, "Tool", solcName);
            SolidityCompiler compiler       = new SolidityCompiler();
            CompilerOutput   compilerOutput = compiler.Compile(solcPath, filePath);
            HashSet <Tuple <string, string> > ignoredMethods = new HashSet <Tuple <string, string> >();

            // Issue with run_verisol_win.cmd it passes "/ignoreMethod:a@b /ignoreMethod:c@d .." as a single string
            var splitArgs = new List <string>();

            args.Select(arg => arg.Split(" "))
            .ToList()
            .ForEach(a => a.ToList().ForEach(b => splitArgs.Add(b)));

            if (splitArgs.Any(x => x.Equals("/break")))
            {
                Debugger.Launch();
            }
            foreach (var arg in splitArgs.Where(x => x.StartsWith("/ignoreMethod:")))
            {
                Debug.Assert(arg.Contains("@"), $"Error: incorrect use of /ignoreMethod in {arg}");
                Debug.Assert(arg.LastIndexOf("@") == arg.IndexOf("@"), $"Error: incorrect use of /ignoreMethod in {arg}");
                var str      = arg.Substring("/ignoreMethod:".Length);
                var method   = str.Substring(0, str.IndexOf("@"));
                var contract = str.Substring(str.IndexOf("@") + 1);
                ignoredMethods.Add(Tuple.Create(method, contract));
            }
            Console.WriteLine($"Ignored method/contract pairs ==> \n\t {string.Join(",", ignoredMethods.Select(x => x.Item1 + "@" + x.Item2))}");

            bool genInlineAttributesInBpl = true;

            if (splitArgs.Any(x => x.Equals("/noInlineAttrs")))
            {
                genInlineAttributesInBpl = false;
            }

            if (compilerOutput.ContainsError())
            {
                PrintErrors(compilerOutput.Errors);
                throw new SystemException("Compilation Error");
            }
            else
            {
                AST solidityAST = new AST(compilerOutput, Path.GetDirectoryName(filePath));

                try
                {
                    BoogieTranslator translator = new BoogieTranslator();
                    BoogieAST        boogieAST  = translator.Translate(solidityAST, ignoredMethods, genInlineAttributesInBpl);

                    using (var outWriter = new StreamWriter(outFile))
                    {
                        outWriter.WriteLine(boogieAST.GetRoot());
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Verisol translation exception: {e.Message}");
                }
            }
        }