Skip to content

Commit

Permalink
log zkproof #36
Browse files Browse the repository at this point in the history
  • Loading branch information
silvesterdrago committed Aug 13, 2023
1 parent d1f92f2 commit c17b419
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions backend/battleship.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def _zokrates_init_validator(self):
return zokrates_prove(
self._zokrates_executable_location,
self._zokrates_init_handler_dir,
*self.ships_positions
*self.ships_positions,
logger=logger,
)

def call_game_init(self, proof):
Expand Down Expand Up @@ -138,6 +139,7 @@ def _zokrates_move_validator(self, coordinate, digest):
*self.ships_positions,
digest,
coordinate,
logger=logger,
)

def calculate_result(self, guess):
Expand Down Expand Up @@ -173,9 +175,9 @@ def call_move_result(self, move_id, game_id, result, proof):
"""
logger.info(f'Sending transaction with result {result[1]} to contract')
tx = self.contract.functions.moveResult(
self.w3.to_wei(move_id, "wei"), # Convert to type uint256
self.w3.to_wei(game_id, "wei"), # Convert to type uint256
move_id,
result[0], # Status code
game_id,
*parse_proof(proof)
).build_transaction({
"from": self.account.address,
Expand Down
4 changes: 3 additions & 1 deletion backend/zokrates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json


def zokrates_prove(zokrates_path, work_dir, *args):
def zokrates_prove(zokrates_path, work_dir, *args, logger=None):
result = subprocess.run(
" ".join([
f"{zokrates_path}",
Expand All @@ -18,5 +18,7 @@ def zokrates_prove(zokrates_path, work_dir, *args):
cwd=work_dir
)
if result.returncode == 0:
if logger is not None:
logger.info(result.stdout.decode("utf-8"))
with open(work_dir + "/proof.json", "r") as f:
return json.load(f)

0 comments on commit c17b419

Please sign in to comment.