Пример #1
0
        private void GenerateSingleMemoryVariable(BoogieType keyType, BoogieType valType)
        {
            BoogieMapType map = new BoogieMapType(keyType, valType);

            map = new BoogieMapType(BoogieType.Ref, map);

            string name = MapArrayHelper.GetMemoryMapName(keyType, valType);

            context.Program.AddDeclaration(new BoogieGlobalVariable(new BoogieTypedIdent(name, map)));
        }
        private void GenerateFunctions()
        {
            context.Program.AddDeclaration(GenerateConstToRefFunction());
            context.Program.AddDeclaration(GenerateRefToInt());
            context.Program.AddDeclaration(GenerateModFunction());
            context.Program.AddDeclaration(GenerateKeccakFunction());
            context.Program.AddDeclaration(GenerateAbiEncodedFunctionOneArg());
            context.Program.AddDeclaration(GenerateVeriSolSumFunction());
            context.Program.AddDeclaration(GenerateAbiEncodedFunctionTwoArgs());
            context.Program.AddDeclaration(GenerateAbiEncodedFunctionOneArgRef());
            context.Program.AddDeclaration(GenerateAbiEncodedFunctionTwoArgsOneRef());

            if (context.TranslateFlags.QuantFreeAllocs)
            {
                if (context.TranslateFlags.UseMultiDim)
                {
                    foreach (VariableDeclaration decl in context.Analysis.Alias.getResults())
                    {
                        TypeName type = decl.TypeName;
                        if (type is Mapping || type is ArrayTypeName)
                        {
                            BoogieFunction initFn = MapArrayHelper.GenerateMultiDimZeroFunction(decl);

                            if (!context.initFns.Contains(initFn.Name))
                            {
                                context.Program.AddDeclaration(initFn);
                                context.initFns.Add(initFn.Name);
                            }
                        }
                    }
                }
                else
                {
                    context.Program.AddDeclaration(GenerateZeroRefIntArrayFunction());
                    context.Program.AddDeclaration(GenerateZeroIntIntArrayFunction());
                    context.Program.AddDeclaration(GenerateZeroRefBoolArrayFunction());
                    context.Program.AddDeclaration(GenerateZeroIntBoolArrayFunction());
                    context.Program.AddDeclaration(GenerateZeroRefRefArrayFunction());
                    context.Program.AddDeclaration(GenerateZeroIntRefArrayFunction());
                }
            }

            if (context.TranslateFlags.NoNonlinearArith)
            {
                context.Program.AddDeclaration(generateNonlinearMulFunction());
                context.Program.AddDeclaration(generateNonlinearDivFunction());
                context.Program.AddDeclaration(generateNonlinearPowFunction());
                context.Program.AddDeclaration(generateNonlinearModFunction());
            }
        }
        private void GenerateSingleMemoryVariable(VariableDeclaration decl, BoogieType keyType, BoogieType valType, HashSet <String> generatedMaps)
        {
            BoogieMapType map = new BoogieMapType(keyType, valType);

            map = new BoogieMapType(BoogieType.Ref, map);

            string name = mapHelper.GetMemoryMapName(decl, keyType, valType);

            if (!generatedMaps.Contains(name))
            {
                BoogieFunction initFn = MapArrayHelper.GenerateMultiDimZeroFunction(keyType, valType);
                if (!context.initFns.Contains(initFn.Name))
                {
                    context.initFns.Add(initFn.Name);
                    context.Program.AddDeclaration(initFn);
                }

                generatedMaps.Add(name);
                context.Program.AddDeclaration(new BoogieGlobalVariable(new BoogieTypedIdent(name, map)));
            }
        }
 public GhostVarAndAxiomGenerator(TranslatorContext context, MapArrayHelper mapHelper)
 {
     this.context   = context;
     this.mapHelper = mapHelper;
 }
Пример #5
0
        // set of method@contract pairs whose translatin is skipped
        public BoogieAST Translate(AST solidityAST, HashSet <Tuple <string, string> > ignoredMethods, TranslatorFlags _translatorFlags = null, String entryPointContract = "")
        {
            bool generateInlineAttributesInBpl = _translatorFlags.GenerateInlineAttributes;

            SourceUnitList sourceUnits = solidityAST.GetSourceUnits();

            TranslatorContext context = new TranslatorContext(solidityAST, ignoredMethods, generateInlineAttributesInBpl, _translatorFlags, entryPointContract);

            context.IdToNodeMap     = solidityAST.GetIdToNodeMap();
            context.SourceDirectory = solidityAST.SourceDirectory;
            // collect the absolute source path and line number for each AST node
            SourceInfoCollector sourceInfoCollector = new SourceInfoCollector(context);

            sourceUnits.Accept(sourceInfoCollector);

            // de-sugar the solidity AST
            // will modify the AST
            SolidityDesugaring desugaring = new SolidityDesugaring(context);

            sourceUnits.Accept(desugaring);

            // collect all contract definitions
            ContractCollector contractCollector = new ContractCollector(context);

            sourceUnits.Accept(contractCollector);

            // collect all sub types for each contract
            InheritanceCollector inheritanceCollector = new InheritanceCollector(context);

            inheritanceCollector.Collect();

            // collect explicit state variables
            StateVariableCollector stateVariableCollector = new StateVariableCollector(context);

            sourceUnits.Accept(stateVariableCollector);

            // resolve state variable declarations and determine the visible ones for each contract
            StateVariableResolver stateVariableResolver = new StateVariableResolver(context);

            stateVariableResolver.Resolve();

            // collect mappings and arrays
            MapArrayCollector mapArrayCollector = new MapArrayCollector(context);

            sourceUnits.Accept(mapArrayCollector);

            // collect constructor definitions
            ConstructorCollector constructorCollector = new ConstructorCollector(context);

            sourceUnits.Accept(constructorCollector);

            // collect explicit function and event definitions
            FunctionEventCollector functionEventCollector = new FunctionEventCollector(context);

            sourceUnits.Accept(functionEventCollector);

            // resolve function and event definitions and determine the actual definition for a dynamic type
            FunctionEventResolver functionEventResolver = new FunctionEventResolver(context);

            functionEventResolver.Resolve();

            // Generate map helper
            MapArrayHelper mapHelper = new MapArrayHelper(context, solidityAST);

            // add types, gobal ghost variables, and axioms
            GhostVarAndAxiomGenerator generator = new GhostVarAndAxiomGenerator(context, mapHelper);

            generator.Generate();

            // collect modifiers information
            ModifierCollector modifierCollector = new ModifierCollector(context);

            sourceUnits.Accept(modifierCollector);

            // collect all using using definitions
            UsingCollector usingCollector = new UsingCollector(context);

            sourceUnits.Accept(usingCollector);

            if (context.TranslateFlags.PerformFunctionSlice)
            {
                FunctionDependencyCollector depCollector = new FunctionDependencyCollector(context, entryPointContract, context.TranslateFlags.SliceFunctionNames);
                context.TranslateFlags.SliceFunctions = depCollector.GetFunctionDeps();
                context.TranslateFlags.SliceModifiers = depCollector.getModifierDeps();
            }

            // translate procedures
            ProcedureTranslator procTranslator = new ProcedureTranslator(context, mapHelper, generateInlineAttributesInBpl);

            sourceUnits.Accept(procTranslator);

            // generate fallbacks
            FallbackGenerator fallbackGenerator = new FallbackGenerator(context);

            fallbackGenerator.Generate();

            // generate harness for each contract
            if (!context.TranslateFlags.NoHarness)
            {
                HarnessGenerator harnessGenerator = new HarnessGenerator(context, procTranslator.ContractInvariants);
                harnessGenerator.Generate();
            }

            if (context.TranslateFlags.ModelReverts)
            {
                RevertLogicGenerator reverGenerator = new RevertLogicGenerator(context);
                reverGenerator.Generate();
            }

            if (context.TranslateFlags.DoModSetAnalysis)
            {
                ModSetAnalysis modSetAnalysis = new ModSetAnalysis(context);
                modSetAnalysis.PerformModSetAnalysis();
            }

            if (context.TranslateFlags.GenerateERC20Spec)
            {
                ERC20SpecGenerator specGen = new ERC20SpecGenerator(context, solidityAST, entryPointContract);
                specGen.GenerateSpec();
            }

            return(new BoogieAST(context.Program));
        }