diff --git a/mpc_demo_infra/client_cli/main.py b/mpc_demo_infra/client_cli/main.py index acdbbe0..6a4932a 100644 --- a/mpc_demo_infra/client_cli/main.py +++ b/mpc_demo_infra/client_cli/main.py @@ -25,9 +25,8 @@ CMD_TLSN_PROVER = "./binance_prover" def locate_binance_prover(): - # binance_prover is expected to be in the current working dir or missing. - # if missing, tlsn directory is expected to exist so that binance_prover - # can be built from the source. + # binance_prover is expected to be in the current working dir or + # built from the source binance_provers = [ (Path('.').resolve(), CMD_TLSN_PROVER), (TLSN_BINARY_PATH, CMD_TLSN_PROVER), diff --git a/mpc_demo_infra/client_lib/client.py b/mpc_demo_infra/client_lib/client.py index 32caf99..8e8653c 100644 --- a/mpc_demo_infra/client_lib/client.py +++ b/mpc_demo_infra/client_lib/client.py @@ -46,8 +46,10 @@ def __init__(self, hosts, port_base, client_id, certs_path, cert_file, key_file, for i, hostname in enumerate(hosts): for j in range(10000): try: + logging.info("Establishing socket connection to %s:%d...", hostname, port_base + i) plain_socket = socket.create_connection( (hostname, port_base + i), timeout=timeout) + logging.info("Etablished") break except ConnectionRefusedError: if j < 600: diff --git a/mpc_demo_infra/client_lib/lib.py b/mpc_demo_infra/client_lib/lib.py index 16026e0..169bbac 100644 --- a/mpc_demo_infra/client_lib/lib.py +++ b/mpc_demo_infra/client_lib/lib.py @@ -43,6 +43,7 @@ def run_data_sharing_client( input_value: int, nonce: str, ): + logger.info(f"Setting up data sharing client with {party_hosts=}, {port_base=}...") client = Client(party_hosts, port_base, client_id, certs_path, cert_file, key_file, CLIENT_TIMEOUT) for socket in client.sockets: @@ -50,8 +51,9 @@ def run_data_sharing_client( os.store(0) os.Send(socket) + logger.info("Sending private inputs to computation party servers ...") client.send_private_inputs([input_value, reverse_bytes(hex_to_int(nonce))]) - logger.info("Finish sending private inputs") + logger.info("Finished sending private inputs") outputs = client.receive_outputs(1) logger.info(f"!@# data_sharing_client.py outputs: {outputs}") commitment = outputs[0] @@ -175,7 +177,7 @@ async def share_data( if await validate_computation_key(coordination_server_url, access_key, computation_key) == False: raise Exception(f"Computation key is invalid") else: - logger.info(f"Validated computation key is {computation_key}") + logger.info(f"Validated computation key: {computation_key}") client_id, cert_path, key_path = await generate_client_cert(MAX_CLIENT_ID, all_certs_path, client_id) with open(cert_path, "r") as cert_file: diff --git a/mpc_demo_infra/computation_party_server/routes.py b/mpc_demo_infra/computation_party_server/routes.py index fda6dda..235a78b 100644 --- a/mpc_demo_infra/computation_party_server/routes.py +++ b/mpc_demo_infra/computation_party_server/routes.py @@ -72,7 +72,7 @@ def request_sharing_data_mpc(request: RequestSharingDataMPCRequest, db: Session client_id = request.client_id client_port_base = request.client_port_base client_cert_file = request.client_cert_file - logger.info(f"Requesting sharing data MPC for {secret_index=}") + logger.info(f"Requesting sharing data MPC for {secret_index=}, {client_id=}, {mpc_port_base=}, {client_port_base=}") if secret_index >= MAX_DATA_PROVIDERS: raise HTTPException(status_code=400, detail=f"Secret index {secret_index} exceeds the maximum {MAX_DATA_PROVIDERS}") # 1. Verify TLSN proof @@ -81,9 +81,11 @@ def request_sharing_data_mpc(request: RequestSharingDataMPCRequest, db: Session temp_file.write(tlsn_proof.encode('utf-8')) # Run TLSN proof verifier + logger.info("Verifying TLSN proof...") try: subprocess.run( - f"cd {str(TLSN_VERIFIER_PATH)} && {CMD_VERIFY_TLSN_PROOF} {temp_file.name}", + f"{CMD_VERIFY_TLSN_PROOF} {temp_file.name}", + cwd=TLSN_VERIFIER_PATH, check=True, shell=True, capture_output=True, @@ -91,6 +93,7 @@ def request_sharing_data_mpc(request: RequestSharingDataMPCRequest, db: Session except subprocess.CalledProcessError as e: logger.error(f"Failed to verify TLSN proof: {str(e)}") raise HTTPException(status_code=400, detail="Failed when verifying TLSN proof") + logger.info("TLSN proof is valid") # 2. Backup previous shares backup_shares_path = backup_shares(settings.party_id) @@ -290,6 +293,8 @@ def generate_data_sharing_program( if is_first_run: program_content = '\n'.join([line for line in program_content.split('\n') if "# NOTE: Skipped if it's the first run" not in line]) + logger.info(f"Generated data sharing program from the template with parameters: {secret_index=}, {client_port_base=}, {max_data_providers=}, {is_first_run=}, {input_bytes=}, {tlsn_delta=}, {tlsn_zero_encodings=}") + logger.info(f"Generated program: {program_content}") with open(target_program_path, "w") as program_file: program_file.write(program_content) return circuit_name, target_program_path diff --git a/mpc_demo_infra/coordination_server/routes.py b/mpc_demo_infra/coordination_server/routes.py index 487dbe2..c0a794f 100644 --- a/mpc_demo_infra/coordination_server/routes.py +++ b/mpc_demo_infra/coordination_server/routes.py @@ -91,9 +91,9 @@ async def finish_computation(request: RequestFinishComputationRequest, x: Reques return RequestFinishComputationResponse(is_finished=is_finished) def locate_binance_verifier(): - # binance_verifier is expected to be in the current working dir or missing. - # if missing, tlsn directory is expected to exist so that binance_verifier - # can be built from the source. + # If pre-built binance_verifier exists, it's expected to be in + # the current working dir or TLSN_VERIFIER_PATH. + # Othereise, binance_verifier will be built from the source binance_verifiers = [ (Path('.').resolve(), CMD_TLSN_VERIFIER), (TLSN_VERIFIER_PATH, CMD_TLSN_VERIFIER), @@ -407,4 +407,5 @@ def get_computation_query_mpc_ports() -> tuple[int, int]: next_query_port_base = settings.free_ports_start + 2 * settings.num_parties else: next_query_port_base = client_port_base + settings.num_parties + logger.info(f"Computation party ports: {server_port_base=}, {client_port_base=}") return server_port_base, client_port_base diff --git a/mpc_demo_infra/program/share_data.mpc b/mpc_demo_infra/program/share_data.mpc index 88a7604..9eb244e 100644 --- a/mpc_demo_infra/program/share_data.mpc +++ b/mpc_demo_infra/program/share_data.mpc @@ -74,11 +74,12 @@ def main(): commitment_values.read_from_file(1 + MAX_DATA_PROVIDERS) # NOTE: Skipped if it's the first run # Start listening for client socket connections + print_ln('Calling listen_for_clients(%s)...', PORTNUM) listen_for_clients(PORTNUM) print_ln('Listening for client connections on base port %s', PORTNUM) client_socket_id = accept_client() - print_ln('client_socket_id: %s', client_socket_id) + print_ln('Accepted client connection. client_socket_id: %s', client_socket_id) input_value, input_nonce = client_input(sint, client_socket_id) client_values[SECRET_INDEX] = input_value