private void GenerateBoogieRecord(string typeName, BoogieType btype) { // generate the internal one without base constructors string procName = "boogie_si_record_sol2Bpl_" + typeName; var inVar = new BoogieFormalParam(new BoogieTypedIdent("x", btype)); List <BoogieVariable> inParams = new List <BoogieVariable>() { inVar }; List <BoogieVariable> outParams = new List <BoogieVariable>(); BoogieProcedure procedure = new BoogieProcedure(procName, inParams, outParams, null); context.Program.AddDeclaration(procedure); }
private BoogieFunction generateNonlinearModFunction() { string fnName = "nonlinearMod"; var inVar1 = new BoogieFormalParam(new BoogieTypedIdent("x", BoogieType.Int)); var inVar2 = new BoogieFormalParam(new BoogieTypedIdent("y", BoogieType.Int)); var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", BoogieType.Int)); return(new BoogieFunction(fnName, new List <BoogieVariable>() { inVar1, inVar2 }, new List <BoogieVariable>() { outVar })); }
public static BoogieFunction GenerateMultiDimZeroFunction(VariableDeclaration decl) { TypeName curType = decl.TypeName; List <BoogieType> boogieType = new List <BoogieType>(); while (curType is Mapping || curType is ArrayTypeName) { if (curType is Mapping map) { boogieType.Insert(0, TransUtils.GetBoogieTypeFromSolidityTypeName(map.KeyType)); curType = map.ValueType; } else if (curType is ArrayTypeName arr) { boogieType.Insert(0, BoogieType.Int); curType = arr.BaseType; } } BoogieType valType = TransUtils.GetBoogieTypeFromSolidityTypeName(curType); BoogieExpr boogieInit = TransUtils.GetDefaultVal(valType); string smtType = GetSmtType(valType); string smtInit = boogieInit.ToString().Equals("null") ? "0" : boogieInit.ToString(); BoogieType mapType = valType; string fnName = $"{valType.ToString()}Arr"; foreach (BoogieType type in boogieType) { smtType = $"(Array {GetSmtType(type)} {smtType})"; mapType = new BoogieMapType(type, mapType); smtInit = $"((as const {smtType}) {smtInit})"; fnName = $"{type.ToString()}{fnName}"; } var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", mapType)); var smtDefinedAttr = new BoogieAttribute("smtdefined", $"\"{smtInit}\""); return(new BoogieFunction($"zero{fnName}", new List <BoogieVariable>(), new List <BoogieVariable>() { outVar }, new List <BoogieAttribute>() { smtDefinedAttr })); }
private BoogieFunction GenerateZeroRefBoolArrayFunction() { var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", new BoogieMapType(BoogieType.Ref, BoogieType.Bool))); return(new BoogieFunction( "zeroRefBoolArr", new List <BoogieVariable>(), new List <BoogieVariable>() { outVar }, new List <BoogieAttribute>() { new BoogieAttribute("smtdefined", "\"((as const (Array Int Bool)) false)\"") } )); }
//Generate Fresh Procedure Boogie Type and add as new reference to BoogieProgram private void BuildGlobalProcedureFresh() { // generate the internal one without base constructors string procName = "FreshRefGenerator"; List <BoogieVariable> inParams = new List <BoogieVariable>(); var outVar = new BoogieFormalParam(new BoogieTypedIdent("newRef", BoogieType.Ref)); List <BoogieVariable> outParams = new List <BoogieVariable>() { outVar }; List <BoogieAttribute> attributes = new List <BoogieAttribute>(); if (Flags_HelperClass.GenerateInlineAttributes) { attributes.Add(new BoogieAttribute("inline", 1)); } ; BoogieProcedure procedure = new BoogieProcedure(procName, inParams, outParams, attributes); context.getProgram.AddBoogieDeclaration(procedure); List <BoogieVariable> localVars = new List <BoogieVariable>(); BoogieStmtList procBody = new BoogieStmtList(); var outVarIdentifier = new BoogieIdentifierExpr("newRef"); BoogieIdentifierExpr allocIdentExpr = new BoogieIdentifierExpr("Alloc"); // havoc tmp; procBody.AddStatement(new BoogieHavocCmd(outVarIdentifier)); // assume Alloc[tmp] == false; BoogieMapSelect allocMapSelect = new BoogieMapSelect(allocIdentExpr, outVarIdentifier); BoogieExpr allocAssumeExpr = new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.EQ, allocMapSelect, new BoogieLiteralExpr(false)); procBody.AddStatement(new BoogieAssumeCmd(allocAssumeExpr)); // Alloc[tmp] := true; procBody.AddStatement(new BoogieAssignCmd(allocMapSelect, new BoogieLiteralExpr(true))); // assume tmp != null procBody.AddStatement(new BoogieAssumeCmd( new BoogieBinaryOperation(BoogieBinaryOperation.Opcode.NEQ, outVarIdentifier, new BoogieIdentifierExpr("null")))); BoogieImplementation implementation = new BoogieImplementation(procName, inParams, outParams, localVars, procBody); context.getProgram.AddBoogieDeclaration(implementation); }
private BoogieFunction GenerateAbiEncodedFunctionOneArg() { //function for Int to Int var inVar1 = new BoogieFormalParam(new BoogieTypedIdent("x", BoogieType.Int)); var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", BoogieType.Int)); return(new BoogieFunction( "abiEncodePacked1", new List <BoogieVariable>() { inVar1 }, new List <BoogieVariable>() { outVar }, null)); }
private BoogieFunction GenerateKeccakFunction() { //function for Int to Ref var inVar = new BoogieFormalParam(new BoogieTypedIdent("x", BoogieType.Int)); var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", BoogieType.Int)); return(new BoogieFunction( "keccak256", new List <BoogieVariable>() { inVar }, new List <BoogieVariable>() { outVar }, null)); }
private BoogieFunction GenerateVeriSolSumFunction() { //function for [Ref]int to int var inVar = new BoogieFormalParam(new BoogieTypedIdent("x", new BoogieMapType(BoogieType.Ref, BoogieType.Int))); var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", BoogieType.Int)); return(new BoogieFunction( "_SumMapping_VeriSol", new List <BoogieVariable>() { inVar }, new List <BoogieVariable>() { outVar }, null)); }
private BoogieFunction GenerateConstToRefFunction() { //function for Int to Ref var inVar = new BoogieFormalParam(new BoogieTypedIdent("x", BoogieType.Int)); var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", BoogieType.Ref)); return(new BoogieFunction( "ConstantToRef", new List <BoogieVariable>() { inVar }, new List <BoogieVariable>() { outVar }, null)); }
//Function to construct OverSight Sum function builder as part of the BoogieProgram. private BoogieFunction buildOverSightSumFunction() { //function for [Ref]int to int var inputVariables = new BoogieFormalParam(new BoogieTypedIdent("x", new BoogieMapType(BoogieType.Ref, BoogieType.Int))); var outputVriables = new BoogieFormalParam(new BoogieTypedIdent("ret", BoogieType.Int)); return(new BoogieFunction( "_SumMapping_OverSight", new List <BoogieVariable>() { inputVariables }, new List <BoogieVariable>() { outputVriables }, null)); }
private BoogieFunction GenerateRefToInt() { //function for Ref to Int var inVar = new BoogieFormalParam(new BoogieTypedIdent("x", BoogieType.Ref)); var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", BoogieType.Int)); return(new BoogieFunction( "BoogieRefToInt", new List <BoogieVariable>() { inVar }, new List <BoogieVariable>() { outVar }, null)); }
private BoogieFunction GenerateAbiEncodedFunctionTwoArgsOneRef() { //function for Int*Int to Int var inVar1 = new BoogieFormalParam(new BoogieTypedIdent("x", BoogieType.Ref)); var inVar2 = new BoogieFormalParam(new BoogieTypedIdent("y", BoogieType.Int)); var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", BoogieType.Int)); return(new BoogieFunction( "abiEncodePacked2R", new List <BoogieVariable>() { inVar1, inVar2 }, new List <BoogieVariable>() { outVar }, null)); }
public static BoogieFunction GenerateMultiDimInitFunction(BoogieMapType type) { BoogieType curType = type; List <BoogieType> boogieType = new List <BoogieType>(); while (curType is BoogieMapType map) { if (map.Arguments.Count != 1) { throw new Exception("Boogie map must have one argument"); } boogieType.Insert(0, map.Arguments[0]); curType = map.Result; } BoogieVariable arg = new BoogieFormalParam(new BoogieTypedIdent("n", curType)); string smtInit = "n"; string smtType = GetSmtType(curType); string fnName = $"{curType.ToString()}Arr"; foreach (BoogieType dimType in boogieType) { smtType = $"(Array {GetSmtType(dimType)} {smtType})"; smtInit = $"((as const {smtType}) {smtInit})"; fnName = $"{dimType.ToString()}{fnName}"; } var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", type)); var smtDefinedAttr = new BoogieAttribute("smtdefined", $"\"{smtInit}\""); return(new BoogieFunction($"init{fnName}", new List <BoogieVariable>() { arg }, new List <BoogieVariable>() { outVar }, new List <BoogieAttribute>() { smtDefinedAttr })); }
private BoogieFunction GenerateModFunction() { //function for arithmetic "modulo" operation for unsigned integers string functionName = "modBpl"; var inVar1 = new BoogieFormalParam(new BoogieTypedIdent("x", BoogieType.Int)); var inVar2 = new BoogieFormalParam(new BoogieTypedIdent("y", BoogieType.Int)); var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", BoogieType.Int)); return(new BoogieFunction( functionName, new List <BoogieVariable>() { inVar1, inVar2 }, new List <BoogieVariable>() { outVar }, new List <BoogieAttribute> { new BoogieAttribute("bvbuiltin", "\"" + "mod" + "\"") })); }
public static BoogieFunction GenerateMultiDimZeroFunction(BoogieType keyType, BoogieType valType) { BoogieExpr boogieInit = TransUtils.GetDefaultVal(valType); string smtType = GetSmtType(valType); BoogieType mapType = new BoogieMapType(keyType, valType); string fnName = $"zero{keyType.ToString()}{valType.ToString()}Arr"; string smtInit = boogieInit.ToString().Equals("null") ? "0" : boogieInit.ToString(); smtInit = $"((as const (Array {GetSmtType(keyType)} {smtType})) {smtInit})"; var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", mapType)); var smtDefinedAttr = new BoogieAttribute("smtdefined", $"\"{smtInit}\""); return(new BoogieFunction(fnName, new List <BoogieVariable>(), new List <BoogieVariable>() { outVar }, new List <BoogieAttribute>() { smtDefinedAttr })); }
private BoogieFunction GenerateConstToRefFunction() { //function for Int to Ref var inVar = new BoogieFormalParam(new BoogieTypedIdent("x", BoogieType.Int)); var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", BoogieType.Ref)); BoogieAttribute attr = new BoogieAttribute("smtdefined", "\"x\""); return(new BoogieFunction( "ConstantToRef", new List <BoogieVariable>() { inVar }, new List <BoogieVariable>() { outVar }, new List <BoogieAttribute>() { attr })); }