Пример #1
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);
        }
Пример #2
0
        public override bool Visit(Identifier ident)
        {
            if (!solidityAST.GetIdToNodeMap().ContainsKey(ident.ReferencedDeclaration))
            {
                return(true);
            }

            ASTNode node = solidityAST.GetASTNodeByID(ident.ReferencedDeclaration);

            if (!(node is VariableDeclaration))
            {
                return(true);
            }

            VariableDeclaration decl = (VariableDeclaration)node;

            results.Remove(decl);
            return(false);
        }
Пример #3
0
        // set of method@contract pairs whose translatin is skipped
        public BoogieAST Translate(AST solidityAST, HashSet <Tuple <string, string> > ignoredMethods, bool generateInlineAttributesInBpl)
        {
            if (generateInlineAttributesInBpl)
            {
                Console.WriteLine($"Warning! Found /noInlineAttrs option...the generated Bpl file cannot be used for unbounded verification");
            }

            SourceUnitList sourceUnits = solidityAST.GetSourceUnits();

            TranslatorContext context = new TranslatorContext(ignoredMethods, generateInlineAttributesInBpl);

            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();

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

            generator.Generate();

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

            sourceUnits.Accept(modifierCollector);

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

            sourceUnits.Accept(procTranslator);

            // generate harness for each contract
            HarnessGenerator harnessGenerator = new HarnessGenerator(context);

            harnessGenerator.Generate();

            return(new BoogieAST(context.Program));
        }
Пример #4
0
        // set of method@contract pairs whose translatin is skipped
        public BoogieAST Translate(AST solidityAST, HashSet <Tuple <string, string> > ignoredMethods, TranslatorFlags _translatorFlags = null)
        {
            bool generateInlineAttributesInBpl = _translatorFlags.GenerateInlineAttributes;

            SourceUnitList sourceUnits = solidityAST.GetSourceUnits();

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

            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();

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

            generator.Generate();

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

            sourceUnits.Accept(modifierCollector);

            // translate procedures
            ProcedureTranslator procTranslator = new ProcedureTranslator(context, 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();
            }

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