Ejemplo n.º 1
0
def analyze_bytecode():
    global args

    x = dtimer()
    helper = InputHelper(InputHelper.BYTECODE, source=args.source,evm = args.evm)
    inp = helper.get_inputs()[0]
    y = dtimer()
    print("*************************************************************")
    print("Compilation time: "+str(y-x)+"s")
    print("*************************************************************")

    r = check_c_translation_dependencies()
    
    if r:
        svc_options={}
        if args.verify:
            svc_options["verify"]=args.verify
        if args.invalid:
            svc_options["invalid"]=args.invalid
        
        result, exit_code = symExec.run(disasm_file=inp['disasm_file'],cfg = args.control_flow_graph,saco = args.saco,debug = args.debug,evm_version = evm_version_modifications,cfile = args.cfile,svc=svc_options,go = args.goto)
        helper.rm_tmp_files()
    else:
        exit_code = -1
        print("Option Error: --verify option is only applied to c translation.\n")
    if global_params.WEB:
        six.print_(json.dumps(result))

    return exit_code
Ejemplo n.º 2
0
    def solve(self, uh, F, tol=1e-8):
        """

        Notes
        -----
        uh 是初值, uh[isBdDof] 中的值已经设为 D 氏边界条件的值, uh[~isBdDof]==0.0
        """

        GD = self.GD
        gdof = self.gdof
        stype = self.stype

        if stype == 'pamg':
            P = LinearOperator((GD*gdof, GD*gdof), matvec=self.pamg_preconditioner)
        elif stype == 'lu':
            P = LinearOperator((GD*gdof, GD*gdof), matvec=self.lu_preconditioner)
        elif stype == 'rm':
            P = LinearOperator((GD*gdof, GD*gdof), matvec=self.rm_preconditioner)
            
        start = dtimer()

        counter = IterationCounter()
        uh.T.flat, info = cg(self.A, F.T.flat, x0=uh.T.flat, M=P, tol=1e-8,
                callback=counter)
        end = dtimer()
        print('time of pcg:', end - start)
        print("Convergence info:", info)
        print("Number of iteration of pcg:", counter.niter)
        return uh 
Ejemplo n.º 3
0
def analyze_solidity(input_type='solidity'):
    global args

    x = dtimer()
    is_runtime = not(args.init)
    print is_runtime
    if input_type == 'solidity':
        helper = InputHelper(InputHelper.SOLIDITY, source=args.source,evm=args.evm,runtime=is_runtime)
    elif input_type == 'standard_json':
        helper = InputHelper(InputHelper.STANDARD_JSON, source=args.source,evm=args.evm, allow_paths=args.allow_paths)
    elif input_type == 'standard_json_output':
        helper = InputHelper(InputHelper.STANDARD_JSON_OUTPUT, source=args.source,evm=args.evm)
    inputs = helper.get_inputs()
    hashes = process_hashes(args.source)
    
    y = dtimer()
    print("*************************************************************")
    print("Compilation time: "+str(y-x)+"s")
    print("*************************************************************")
    results, exit_code = run_solidity_analysis(inputs,hashes)
    helper.rm_tmp_files()

    if global_params.WEB:
        six.print_(json.dumps(results))
    return exit_code
Ejemplo n.º 4
0
def evm2rbr_compiler(blocks_input = None, stack_info = None, block_unbuild = None, nop_opcodes = None,saco_rbr = None, exe = None, contract_name = None, component = None):
    global rbr_blocks
    global stack_index
    
    init_globals()
    stack_index = stack_info
    component_of = component

    begin = dtimer()

    if blocks_input and stack_info:
        blocks = sorted(blocks_input.values(), key = getKey)
        for block in blocks:
            rule = compile_block(block,nop_opcodes)
            rbr_blocks[rule.get_rule_name()]=[rule]
            

        rule_c = create_blocks(block_unbuild)
               
        for rule in rbr_blocks.values():# _blocks.values():
            for r in rule:
#                r.set_bc(bc_in_use)
                component_update_fields(r,component_of)
#                r.update_global_arg(fields_per_block.get(r.get_Id(),[]))
#                r.set_global_vars(max_field_list)
                #r.set_args_local(current_local_var)
                #r.display()

        for rule in rbr_blocks.values():
            for r in rule:
                jumps_to = r.get_call_to()
                
                if jumps_to != -1:
                    f = rbr_blocks["block"+str(jumps_to)][0].build_field_vars()
                    bc = rbr_blocks["block"+str(jumps_to)][0].vars_to_string("data")
                    l = rbr_blocks["block"+str(jumps_to)][0].build_local_vars()
                    r.set_call_to_info((f,bc,l))

                r.update_calls()

        # for r in rule_c:
        #     r.set_bc(bc_in_use)
        #     r.set_global_vars(max_field_list)
        #     r.set_args_local(current_local_var)
        #     rbr_blocks[r.get_rule_name()]=[r]
        
        rbr = sorted(rbr_blocks.values(),key = orderRBR)
        write_rbr(rbr,exe,contract_name)
        
        end = dtimer()
        print("Build RBR: "+str(end-begin)+"s")
        
        if saco_rbr:
            saco.rbr2saco(rbr,exe,contract_name)
    else :
        print ("Error, you have to provide the CFG associated with the solidity file analyzed")
Ejemplo n.º 5
0
def rbr2saco(rbr, execution, cname):
    begin = dtimer()

    new_rules = []
    for rules in rbr:
        for rule in rules:
            new_rule = process_rule_saco(rule)
            new_rules.append(new_rule)

    write(new_rules, execution, cname)
    end = dtimer()
    print("SACO RBR: " + str(end - begin) + "s")
    print("*************************************************************")
Ejemplo n.º 6
0
def rbr2saco(rbr, execution, cname):
    begin = dtimer()

    new_rules = []
    try:
        for rules in rbr:
            for rule in rules:
                new_rule = process_rule_saco(rule)
                new_rules.append(new_rule)

        write(new_rules, execution, cname)
        end = dtimer()
        print("SACO RBR: " + str(end - begin) + "s")

    except:
        raise Exception("Error in SACO translation", 5)
Ejemplo n.º 7
0
def analyze_solidity(input_type='solidity'):
    global args

    x = dtimer()

    if input_type == 'solidity':
        helper = InputHelper(InputHelper.SOLIDITY,
                             source=args.source,
                             evm=args.evm)
    elif input_type == 'standard_json':
        helper = InputHelper(InputHelper.STANDARD_JSON,
                             source=args.source,
                             evm=args.evm,
                             allow_paths=args.allow_paths)
    elif input_type == 'standard_json_output':
        helper = InputHelper(InputHelper.STANDARD_JSON_OUTPUT,
                             source=args.source,
                             evm=args.evm)
    inputs = helper.get_inputs()
    hashes = process_hashes(args.source)

    y = dtimer()
    print("*************************************************************")
    print("Compilation time: " + str(y - x) + "s")
    print("*************************************************************")

    if check_optimize_dependencies():
        i = 0
        found = False
        while (i < len(inputs) and (not found)):
            if inputs[i]["c_name"] == args.contract_name:
                inp = inputs[i]
                found = True
            i += 1
        results, exit_code = run_solidity_analysis_optimized(inp, hashes)
    else:
        results, exit_code = run_solidity_analysis(inputs, hashes)
        helper.rm_tmp_files()

    if global_params.WEB:
        six.print_(json.dumps(results))
    return exit_code
Ejemplo n.º 8
0
def analyze_bytecode():
    global args

    x = dtimer()
    helper = InputHelper(InputHelper.BYTECODE,
                         source=args.source,
                         evm=args.evm)
    inp = helper.get_inputs()[0]
    y = dtimer()
    print("Compilation time: " + str(y - x) + "s")

    result, exit_code = symExec.run(disasm_file=inp['disasm_file'],
                                    cfg=args.control_flow_graph,
                                    nop=args.evm_opcodes,
                                    saco=args.saco)
    helper.rm_tmp_files()

    if global_params.WEB:
        six.print_(json.dumps(result))

    return exit_code
Ejemplo n.º 9
0
    def __init__(self,
                 A,
                 S,
                 I=None,
                 stype='pamg',
                 drop_tol=None,
                 fill_factor=None):
        """

        Notes
        -----

        A : 线弹性矩阵离散矩阵
        S : 刚度矩阵
        I : 刚体运动空间基函数系数矩阵
        """
        self.gdof = S.shape[0]  # 标量自由度个数
        self.GD = A.shape[0] // self.gdof
        self.A = A
        self.I = I
        self.stype = stype

        if stype == 'pamg':
            self.smoother = GaussSeidelSmoother(A)
            start = dtimer()
            self.ml = pyamg.ruge_stuben_solver(S)
            end = dtimer()
            print('time for poisson amg setup:', end - start)
        elif stype == 'lu':
            start = dtimer()
            self.ilu = spilu(A.tocsc(),
                             drop_tol=drop_tol,
                             fill_factor=fill_factor)
            end = dtimer()
            print('time for ILU:', end - start)
        elif stype == 'rm':
            assert I is not None
            self.I = I
            self.AM = inv(I.T @ (A @ I))
            self.smoother = GaussSeidelSmoother(A)
            start = dtimer()
            self.ml = pyamg.ruge_stuben_solver(S)
            end = dtimer()
            print('time for poisson amg setup:', end - start)
Ejemplo n.º 10
0
mayavi_wireframe = False
""" Choose the object """
#exname = "bowl_15_holes"  # "blend_example2_discs" "french_fries_vectorized" "cube_example"
#exname = "blend_example2_discs" #
#exname ="ell_example1" #
#exname = "first_csg"
#exname = "bowl_15_holes"
iobj = example_objects.make_example_vectorized(exname)
#iobj = example_objects.make_example_nonvec(exname)

#import vectorized
#iobj = cube1(vectorized)

print("Starting evaluation of implicit on the Grid.")
sys.stdout.flush()
t1s = dtimer()
vgrid = mc_utils.make_grid(iobj, rng, old=True)
#vgrid = mc_utils.make_grid_pointwise(iobj, rng)
assert vgrid.shape == (len(rng), len(rng), len(rng))
t1 = dtimer() - t1s
print('done grid')
sys.stdout.flush()
""" Use the marching cubes: Usually very fast """
t2s = dtimer()
verts, faces = measure.marching_cubes(vgrid, 0)
#print(verts)
#verts = (verts) * STEPSIZE + RANGE_MIN
#verts = (verts) * (rng[1]-rng[0]) + rng[0]
verts = ((verts) * STEPSIZE + rng[0])
verts = np.concatenate(
    (verts[:, 1, np.newaxis], verts[:, 0, np.newaxis], verts[:, 2,
Ejemplo n.º 11
0
iobj = example_objects.make_example_nonvec(example_nbame)
""" Prepare the grid data arrays """
#STEPSIZE = 0.15
#RANGE_MAX = 4
#RANGE_MIN = -4

#for dice only
STEPSIZE = 0.15 / 2.0 * 2.0
RANGE_MAX = 3
RANGE_MIN = -1
rng = np.arange(RANGE_MIN, RANGE_MAX, STEPSIZE)

print("Starting evaluation of implicit on the Grid")
sys.stdout.flush()
t1s = dtimer()

vgrid = mc_utils.make_grid_pointwise(iobj, rng)

t1 = dtimer() - t1s
print("done grid")
sys.stdout.flush()
if np.sum(np.ravel(vgrid) > 0) == 0:
    print("No point detected")
    raise Error("No point detected")

# Use marching cubes to obtain the surface mesh of these ellipsoids
t2s = dtimer()

verts, faces = measure.marching_cubes(vgrid, 0)
verts = (verts) * STEPSIZE + RANGE_MIN
Ejemplo n.º 12
0
 def run(*args, **kwargs):
     start = dtimer()
     val = func(*args, **kwargs)
     end = dtimer()
     print('run {} with time:'.format(func.__name__), end - start)
     return val