Exemple #1
0
        private BoogieStmtList CreateBodyOfSend(List <BoogieVariable> inParams, List <BoogieVariable> outParams, string fbProcName)
        {
            var fromIdExp = new BoogieIdentifierExpr(inParams[0].Name);
            var amtIdExp  = new BoogieIdentifierExpr(inParams[2].Name);
            var guard     = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.GE,
                                                      new BoogieMapSelect(new BoogieIdentifierExpr("Balance"), fromIdExp),
                                                      amtIdExp);

            // call FallbackDispatch(from, to, amount)
            var toIdExpr = new BoogieIdentifierExpr(inParams[1].Name);
            var callStmt = new BoogieCallCmd(
                fbProcName,
                new List <BoogieExpr>()
            {
                fromIdExp, toIdExpr, amtIdExp
            },
                new List <BoogieIdentifierExpr>()
                );

            var thenBody     = new BoogieStmtList();
            var successIdExp = new BoogieIdentifierExpr(outParams[0].Name);

            thenBody.AddStatement(callStmt);
            thenBody.AddStatement(new BoogieAssignCmd(successIdExp, new BoogieLiteralExpr(true)));

            var elseBody = new BoogieAssignCmd(successIdExp, new BoogieLiteralExpr(false));

            return(BoogieStmtList.MakeSingletonStmtList(new BoogieIfCmd(guard, thenBody,
                                                                        BoogieStmtList.MakeSingletonStmtList(elseBody))));
        }
Exemple #2
0
        private BoogieStmtList CreateBodyOfSend(List <BoogieVariable> inParams, List <BoogieVariable> outParams, string fbProcName)
        {
            var fromIdExp = new BoogieIdentifierExpr(inParams[0].Name);
            var amtIdExp  = new BoogieIdentifierExpr(inParams[2].Name);
            var guard     = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.GE,
                                                      new BoogieMapSelect(new BoogieIdentifierExpr("Balance"), fromIdExp),
                                                      amtIdExp);

            // call FallbackDispatch(from, to, amount)
            var toIdExpr = new BoogieIdentifierExpr(inParams[1].Name);
            var callStmt = new BoogieCallCmd(
                fbProcName,
                new List <BoogieExpr>()
            {
                fromIdExp, toIdExpr, amtIdExp
            },
                new List <BoogieIdentifierExpr>()
                );

            var thenBody     = new BoogieStmtList();
            var successIdExp = new BoogieIdentifierExpr(outParams[0].Name);

            thenBody.AddStatement(new BoogieCommentCmd("---- Logic for payable function START "));
            var balFrom = new BoogieMapSelect(new BoogieIdentifierExpr("Balance"), new BoogieIdentifierExpr(inParams[0].Name));
            var balTo   = new BoogieMapSelect(new BoogieIdentifierExpr("Balance"), new BoogieIdentifierExpr(inParams[1].Name));
            var msgVal  = new BoogieIdentifierExpr(inParams[2].Name);

            //balance[msg.sender] = balance[msg.sender] - msg.value
            thenBody.AddStatement(new BoogieAssignCmd(balFrom, new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.SUB, balFrom, msgVal)));
            //balance[this] = balance[this] + msg.value
            thenBody.AddStatement(new BoogieAssignCmd(balTo, new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.ADD, balTo, msgVal)));
            thenBody.AddStatement(new BoogieCommentCmd("---- Logic for payable function END "));

            thenBody.AddStatement(callStmt);
            thenBody.AddStatement(new BoogieAssignCmd(successIdExp, new BoogieLiteralExpr(true)));

            var elseBody = new BoogieAssignCmd(successIdExp, new BoogieLiteralExpr(false));

            return(BoogieStmtList.MakeSingletonStmtList(new BoogieIfCmd(guard, thenBody,
                                                                        BoogieStmtList.MakeSingletonStmtList(elseBody))));
        }