예제 #1
0
 def set_accounts(self, keys: Dict[str, int]):
     lines = []
     for i, k in enumerate(keys.keys()):
         lines += [f'var {k} = accounts[{i}];']
     lines = '\n'.join(lines)
     lines = prepend_to_lines(lines, '\t')
     self.scenario_js = self.scenario_js.replace('$ACCOUNTS', lines)
예제 #2
0
 def set_pk_announce(self, keys: Dict[str, int]):
     lines = []
     for k, v in keys.items():
         lines += [f'await helpers.tx(genPublicKeyInfrastructure, "announcePk", [{v}], {k});']
     lines = '\n'.join(lines)
     lines = prepend_to_lines(lines, '\t')
     self.scenario_js = self.scenario_js.replace('$PK_ANNOUNCE', lines)
예제 #3
0
 def set_verifiers(self):
     verifiers_fetch = []
     verifiers_deploy = []
     verifiers_wait = []
     for c in self.r.compiler_information.used_contracts:
         if 'PublicKeyInfrastructure' not in c.contract_name:
             verifiers_fetch += [f'var {c.state_variable_name} = artifacts.require("{c.contract_name}");']
             verifiers_deploy += [f'await deployer.link(pairing, {c.state_variable_name});\nawait deployer.link(bn256g2, {c.state_variable_name});\nawait helpers.deploy(web3, deployer, {c.state_variable_name}, [], accounts[0]);']
             verifiers_wait += [f'{c.state_variable_name} = await {c.state_variable_name}.deployed();']
     verifiers_fetch = prepend_to_lines('\n'.join(verifiers_fetch), '\t')
     verifiers_deploy = prepend_to_lines('\n'.join(verifiers_deploy), '\t')
     verifiers_wait = prepend_to_lines('\n'.join(verifiers_wait), '\t')
     self.deploy_js = self.deploy_js \
         .replace('$VERIFIERS_FETCH', verifiers_fetch) \
         .replace('$VERIFIERS_DEPLOY', verifiers_deploy)
     self.scenario_js = self.scenario_js.replace('$VERIFIERS_FETCH', verifiers_fetch)
     self.scenario_js = self.scenario_js.replace('$VERIFIERS_WAIT', verifiers_wait)
예제 #4
0
    def run_function(self, function_name: str, me: str, args: List):
        with log_context('nCalls', self.n_calls):
            self.n_calls += 1
            with log_context('runFunction', function_name):
                real_args = run_function(self.r, function_name, me, args)

                args_str = list_to_str(args)
                real_args_str = list_to_str(real_args)

                if function_name == 'constructor':
                    t = f'// {function_name}({args_str})\nargs = [{real_args_str}];\nlet contract_instance = await helpers.deploy_x(web3, contract, args, {me});'
                    t = prepend_to_lines(t, '\t')
                    self.scenario_js = self.scenario_js.replace('$CONTRACT_DEPLOY', t)
                else:
                    t = f'// {function_name}({args_str})\nargs = [{real_args_str}];\nawait helpers.tx(contract_instance, "{function_name}", args, {me});'
                    t = prepend_to_lines(t, '\t')
                    self.transactions += [t]
예제 #5
0
파일: compiler.py 프로젝트: fmerg/zkay
	def code(self):
		if len(self.proof_helper.statements) > 0:
			inputs = ", ".join(self.proof_helper.public_params)
			statements = [f'1 == checkHash([{inputs}], [inputHash0, inputHash1])'] + self.proof_helper.statements + ['return 1']
			s = '\n'.join(statements)
			s = indent(s)
		else:
			return None

		n_public_params = len(self.proof_helper.public_params)

		args = ', '.join(self.proof_helper.zok_params + ['field inputHash0', 'field inputHash1'])
		my_logging.data('nPublicParams', n_public_params)
		docs = '\n'.join([f'{n}: {d}' for n, d in self.proof_helper.param_docs])
		docs = prepend_to_lines(docs, '// ')

		adjusted_zok_helpers = zok_helpers.replace('$NINPUTS', str(n_public_params))
		return f'{adjusted_zok_helpers}\n\n{docs}\ndef main({args}) -> (field):\n{s}'
예제 #6
0
파일: compiler.py 프로젝트: fmerg/zkay
def compile_ast(ast: AST, output_directory: str, output_file: Optional[str], simulate=False):
	"""

	Parameters:
	simulate (bool): Only simulate compilation to determine
	                 how to translate transactions
	"""
	v = SolidityVisitor(output_directory, simulate)
	s = v.visit(ast)

	my_logging.data('newLoc', lines_of_code(s))

	original_code = ast.code()
	original_code = prepend_to_lines(original_code, '// ')

	if simulate:
		return ast, v
	else:
		filename = save_to_file(output_directory, output_file, original_code + '\n\n' + s)
		copy(pki_contract_template, output_directory)
		return filename