Example #1
0
        private string RunCorral(CorralConfiguration corralConfig)
        {
            string corralArguments = GenerateCorralArguments(corralConfig);

            Process p = new Process();

            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardInput  = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError  = true;
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.FileName  = "dotnet";
            p.StartInfo.Arguments = $"{corralPath} {corralArguments}";
            p.Start();

            string corralOutput = p.StandardOutput.ReadToEnd();
            string errorMsg     = p.StandardError.ReadToEnd();

            if (!String.IsNullOrEmpty(errorMsg))
            {
                Console.WriteLine($"Error: {errorMsg}");
            }
            p.StandardOutput.Close();
            p.StandardError.Close();

            // TODO: should set up a timeout here
            // but it seems there is a problem if we execute corral using mono

            return(corralOutput);
        }
Example #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);
        }
Example #3
0
        private string GenerateCorralArguments(CorralConfiguration corralConfig)
        {
            List <string> commands = new List <string>
            {
                // recursion bound
                $"/recursionBound:{corralConfig.RecursionBound}",
                // context bound (k)
                $"/k:{corralConfig.K}",
                // main method
                $"/main:{corralConfig.Main}",
                // Boogie file
                outFile
            };

            return(String.Join(" ", commands));
        }