Exemplo n.º 1
0
 def newProdNode(self, key=None, end=None):
     p = SDLParser()
     if key and end:
         new_node = p.parse("prod{"+key+":=0,"+end+"} on x")        
     else:
         new_node = p.parse("prod{z:=0, N} on x")
     return new_node
Exemplo n.º 2
0
 def newProdNode(self, key=None, end=None):
     p = SDLParser()
     if key and end:
         new_node = p.parse("prod{" + key + ":=0," + end + "} on x")
     else:
         new_node = p.parse("prod{z:=0, N} on x")
     return new_node
Exemplo n.º 3
0
def benchBatchVerification(N, equation, sdl_dict, vars, precompute, _verbose):
    rop_batch = RecordOperations(vars)
    rop_batch.visit(equation, {})
    if _verbose:
        print("<====\tBATCH\t====>")
        print("Equation =>", equation)
        print("<===\tOperations count\t===>")
    for i in precompute.keys():
        if type(i) != str:
            if checkForSigs(precompute[i]): data = {'key':['N'], 'N': N }
            else: data = {}
            rop_batch.visit(precompute[i], data)
            if _verbose: print("Precompute:", i, ":=", precompute[i])
        else:
            if i == 'delta': # estimate cost of random small exponents
                rop_batch.ops['prng'] += N
                if _verbose: print("Precompute:", i, ":=", precompute[i])
            else:  # estimate cost of some precomputations
                bp = SDLParser()
                index = BinaryNode( i )
                if 'j' in index.attr_index:
                    compute = bp.parse( "for{z:=1, N} do " + precompute[i] )
                    rop_batch.visit(compute, {})
                    if _verbose: print("Precompute:", i, ":=", compute)
                else:
                    if _verbose: print("TODO: need to account for this: ", i, ":=", precompute[i])
    if _verbose:
        print_results(rop_batch.ops)
    return calculate_times(rop_batch.ops, curve[param_id], N)
Exemplo n.º 4
0
 def newExpNode(self):
     #        exp = BinaryNode(ops.EXP)
     p = SDLParser()
     _node = p.parse("a ^ b_i")
     return _node
Exemplo n.º 5
0
 def newProdNode(self):
     p = SDLParser()
     new_node = p.parse("prod{z:=0, N} on x")
     return new_node
Exemplo n.º 6
0
def run_main(opts, start=None, stop=None):
    """main entry point for generating batch verification algorithms"""
    global singleVE, crypto_library, curve, param_id, assignInfo, varTypes, global_count, delta_count, applied_technique_list
    verbose   = opts['verbose']
    statement = opts['test_stmt']
    file      = opts['sdl_file']
    crypto_library   = opts['library']
    proof_flag = opts['proof']
    benchmark_batcher = opts['benchmark']
    curve, param_id = getBenchmarkInfo(crypto_library)
    if statement:
        debug = levels.all
        parser = SDLParser()
        final = parser.parse(statement)
        print("Final statement(%s): '%s'" % (type(final), final))
        sys.exit(0)
    else:
        # Parse the SDL file into binary tree
#        ast_struct = parseFile(file)
        parseFile(file, verbose, ignoreCloudSourcing=True)
        setting = SDLSetting(verbose)
        setting.parse(getAssignInfo(), getVarTypes()) # check for errors and pass on to user before continuing

    # process single or multiple equations
    verify_eq, N = [], None
    #for n in ast_struct[ OTHER ]:
    if len(setting.getVerifyEq()) == 0:
        print(setting.getVerifyEq())
        sys.exit("Could not locate the individual verification equation. Please edit SDL file.\n");
    
    verifyEqDict = setting.getVerifyEq()
    verifyEqUpdated = {}
    isSingleEquation = {}
    verifyList = list(verifyEqDict.keys())
    verifyList.sort()
    
    for k in verifyList:
#        print("k := ", k, ", v := ", verifyEqDict[k])
        if VERIFY in k:
            (result, singleEq) = handleVerifyEq(verifyEqDict[k].get(VERIFY), delta_count, setting, verbose)
            delta_count += 1 # where we do actual verification on # of eqs
            verifyEqUpdated[ k ] = result
            isSingleEquation[ k ] = singleEq 

    # santiy checks to verify setting makes sense for given equation 
    variables = setting.getTypes()
    for k,v in verifyEqUpdated.items():
        bte = BasicTypeExist( variables )
        ASTVisitor( bte ).preorder( v )
        bte.report( v )
    
    #sys.exit(0)
    # initiate the proof generator 
    if benchmark_batcher and type(start) == list: start[0] = time.clock()   
    print("Single verification equation: ", singleVE)
    genProof = GenerateProof(singleVE)
    # process settings
    i = 1
    finalVerifyList = []
    types = setting.getTypes()
    if len(verifyList) == 2:
        batch_precompute = {}
        sdlOutFile = None
        for k in verifyList:
            loopDetails = None
            if verifyEqDict[ k ][ hasLoop ]:
                try:
                    endValue = str(eval(verifyEqDict[k][endVal], setting.getTypes()))
                    # updates the types section to store the value for estimation purposes
                    setting.getTypes()[verifyEqDict[k][endVal]] = endValue
                except:
                    print("Could not determine loop end value. Please define: ", verifyEqDict[k][endVal])
                    sys.exit(0)
                loopDetails = (verifyEqDict[k][loopVar], verifyEqDict[k][startVal], endValue) 
            genProof.setPrefix('EQ' + str(i + 1))
            (sdlOutFile, sdl_data, verify2, batch_precompute0, var_count) = runBatcher2(opts, genProof, file + str(i), verifyEqUpdated[k], setting, loopDetails, i)
            genProof.changeMode( isSingleEquation[ k ] )
            i += 1
#            print("BATCH EQUATION: ", verify2)
            finalVerifyList.append(verify2)
#            print("FINAL VERIFY LIST: ", finalVerifyList)
#            sdl_data.update(sdl_data0)
#            types.update(types0)
            batch_precompute.update(batch_precompute0)

        eq1, eq2 = finalVerifyList
        finalEq = CombineEqWithoutNewDelta(eq1, eq2)
        if verbose: print("FINAL BATCH EQUATION:\n", finalEq)
        if proof_flag: 
            genProof.setPrefix('')
            genProof.setNextStep('Combine equations 1 and 2, then pairings within final equation (technique 6)', finalEq)

#        buildSDLBatchVerifier(sdlOutFile, sdl_data, types, finalEq, batch_precompute, global_count, setting)
    else:
        for k in verifyList:
            loopDetails = None
            if verifyEqDict[ k ][ hasLoop ]:
                try:
                    endValue = str(eval(verifyEqDict[k][endVal], setting.getTypes()))
                    setting.getTypes()[verifyEqDict[k][endVal]] = endValue
                except:
                    print("Could not determine loop end value. Please define: ", verifyEqDict[k][endVal])
                    sys.exit(0)
                loopDetails = (verifyEqDict[k][loopVar], verifyEqDict[k][startVal], endValue)
            (sdlOutFile, sdl_data, verify2, batch_precompute, global_count) = runBatcher2(opts, genProof, file, verifyEqUpdated[k], setting, loopDetails)
            finalEq = verify2
            #buildSDLBatchVerifier(sdlOutFile, sdl_data, types, finalEq, batch_precompute, global_count, setting)
    if proof_flag:
        genProof.setNextStep('finalbatcheq', None)
        latex_file = types['name'].upper()
        if verbose: print("Generated the proof written to file: verification_gen%s.tex" % latex_file)
        genProof.compileProof(opts['path'], latex_file)
    
    # last step:construct SDL batch verifier
    #print("technique list: ", applied_technique_list)
    stopTime = time.clock() # in case we're benchmarking
    if benchmark_batcher and stop and type(stop) == list: stop[0] = stopTime
    return buildSDLBatchVerifier(opts, sdlOutFile, sdl_data, types, finalEq, batch_precompute, global_count, setting)
Exemplo n.º 7
0
    def newExpNode(self):
#        exp = BinaryNode(ops.EXP)
        p = SDLParser()
        _node = p.parse("a ^ b_i")
        return _node
Exemplo n.º 8
0
 def newProdNode(self):
     p = SDLParser()
     new_node = p.parse("prod{z:=0, N} on x")
     return new_node