Beispiel #1
0
 def __init__(self, sdl, vars, equation, library):
     self.sdl_data = sdl
     self.vars  = vars
     self.verify = equation
     self.debug  = False
     self.techMap = { 2:Technique2, 3:Technique3, 4:Technique4, 7:Technique7, 8:Technique8 }
     # a quick way to test that a particular technique will transform the equation (pre-check)
     self.techMap2 = { 5:DotProdInstanceFinder, 6:PairInstanceFinder }
     global curve, param_id
     curve, param_id = getBenchmarkInfo(library)
Beispiel #2
0
 def __init__(self, sdl, vars, equation, library):
     self.sdl_data = sdl
     self.vars = vars
     self.verify = equation
     self.debug = False
     self.techMap = {
         2: Technique2,
         3: Technique3,
         4: Technique4,
         7: Technique7,
         8: Technique8
     }
     # a quick way to test that a particular technique will transform the equation (pre-check)
     self.techMap2 = {5: DotProdInstanceFinder, 6: PairInstanceFinder}
     global curve, param_id
     curve, param_id = getBenchmarkInfo(library)
Beispiel #3
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)