Esempio n. 1
0
        private BoogieStmtList GenerateHavocBlock(ContractDefinition contract, List <BoogieVariable> localVars)
        {
            BoogieStmtList stmtList = new BoogieStmtList();

            foreach (BoogieVariable localVar in localVars)
            {
                string varName = localVar.TypedIdent.Name;
                if (!varName.Equals("this"))
                {
                    stmtList.AddStatement(new BoogieHavocCmd(new BoogieIdentifierExpr(varName)));
                }
            }

            if (context.TranslateFlags.InstrumentGas)
            {
                TransUtils.havocGas(stmtList);
            }

            var nowVar    = new BoogieIdentifierExpr("now");
            var tmpNowVar = new BoogieIdentifierExpr("tmpNow");

            stmtList.AddStatement(new BoogieAssignCmd(tmpNowVar, nowVar));
            stmtList.AddStatement(new BoogieHavocCmd(nowVar));
            stmtList.AddStatement(new BoogieAssumeCmd(new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.GT, nowVar, tmpNowVar)));
            stmtList.AddStatement(new BoogieAssumeCmd(new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.NEQ, new BoogieIdentifierExpr("msgsender_MSG"), new BoogieIdentifierExpr("null"))));

            if (context.TranslateFlags.NoTxnsFromContract)
            {
                foreach (var contractDef in context.ContractDefinitions)
                {
                    BoogieIdentifierExpr contractIdent = new BoogieIdentifierExpr(contractDef.Name);
                    stmtList.AddStatement(new BoogieAssumeCmd(new BoogieBinaryOperation(
                                                                  BoogieBinaryOperation.Opcode.NEQ,
                                                                  new BoogieMapSelect(new BoogieIdentifierExpr("DType"),
                                                                                      new BoogieIdentifierExpr("msgsender_MSG")),
                                                                  contractIdent)));
                }

                stmtList.AddStatement((new BoogieAssignCmd(new BoogieMapSelect(new BoogieIdentifierExpr("Alloc"), new BoogieIdentifierExpr("msgsender_MSG")), new BoogieLiteralExpr(true))));
            }

            return(stmtList);
        }
Esempio n. 2
0
        private List <BoogieCmd> GenerateConstructorCall(ContractDefinition contract)
        {
            List <BoogieCmd>  localStmtList = new List <BoogieCmd>();
            string            callee        = TransUtils.GetCanonicalConstructorName(contract);
            List <BoogieExpr> inputs        = new List <BoogieExpr>()
            {
                new BoogieIdentifierExpr("this"),
                new BoogieIdentifierExpr("msgsender_MSG"),
                new BoogieIdentifierExpr("msgvalue_MSG"),
            };

            if (context.IsConstructorDefined(contract))
            {
                FunctionDefinition ctor = context.GetConstructorByContract(contract);
                foreach (VariableDeclaration param in ctor.Parameters.Parameters)
                {
                    string name = TransUtils.GetCanonicalLocalVariableName(param);
                    inputs.Add(new BoogieIdentifierExpr(name));

                    if (param.TypeName is ArrayTypeName array)
                    {
                        localStmtList.Add(new BoogieCallCmd(
                                              "FreshRefGenerator",
                                              new List <BoogieExpr>(), new List <BoogieIdentifierExpr>()
                        {
                            new BoogieIdentifierExpr(name)
                        }));
                    }
                }
            }

            if (context.TranslateFlags.InstrumentGas)
            {
                TransUtils.havocGas(localStmtList);
            }

            localStmtList.Add(new BoogieCallCmd(callee, inputs, null));
            return(localStmtList);
        }