예제 #1
0
    def visitIdentifierExpr(self, ast: IdentifierExpr):
        # Special identifiers
        pki_inst_names = {
            f'{cfg.get_pki_contract_name(params)}_inst': params
            for params in cfg.all_crypto_params()
        }
        if ast.idf.name in pki_inst_names and not ast.is_lvalue():
            crypto_params = pki_inst_names[ast.idf.name]
            return f'{api("get_keystore")}("{crypto_params.crypto_name}")'
        elif ast.idf.name == cfg.field_prime_var_name:
            assert ast.is_rvalue()
            return f'{SCALAR_FIELD_NAME}'

        if self.current_index:
            # This identifier is the beginning of an Index expression e.g. idf[1][2] or idf[me]
            indices, t = list(reversed(
                self.current_index)), self.current_index_t
            self.current_index, self.current_index_t = [], None
            indices = [self.visit(idx) for idx in indices]
        elif self.inside_circuit and isinstance(
                ast.idf, HybridArgumentIdf
        ) and ast.idf.corresponding_priv_expression is not None and self.flatten_hybrid_args:
            return self.visit(ast.idf.corresponding_priv_expression)
        else:
            indices, t = [], ast.target.annotated_type if isinstance(
                ast.target, StateVariableDeclaration) else None

        return self.get_value(ast, indices)
예제 #2
0
파일: final_checker.py 프로젝트: nibau/zkay
 def visitIdentifierExpr(self, ast: IdentifierExpr):
     if ast.is_rvalue() and self.state_vars_assigned is not None:
         if ast.target in self.state_vars_assigned and not self.state_vars_assigned[
                 ast.target]:
             raise TypeException(
                 f'{str(ast)} is reading "final" state variable before writing it',
                 ast)