Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
Public Member Functions | Public Attributes | List of all members
coordinator.phase2_contribution_handler.Phase2ContributionHandler Class Reference
Inheritance diagram for coordinator.phase2_contribution_handler.Phase2ContributionHandler:
Inheritance graph
[legend]
Collaboration diagram for coordinator.phase2_contribution_handler.Phase2ContributionHandler:
Collaboration graph
[legend]

Public Member Functions

def __init__ (self, Phase2ServerConfig phase2_config)
 
str get_current_challenge_file (self, int contributor_idx)
 
bool process_contribution (self, int contribution_idx, str file_name)
 
None on_completed (self)
 

Public Attributes

 mpc
 

Detailed Description

Handler processing phase2 challenges and contributions.

Definition at line 65 of file phase2_contribution_handler.py.

Constructor & Destructor Documentation

◆ __init__()

def coordinator.phase2_contribution_handler.Phase2ContributionHandler.__init__ (   self,
Phase2ServerConfig  phase2_config 
)

Definition at line 70 of file phase2_contribution_handler.py.

70  def __init__(self, phase2_config: Phase2ServerConfig):
71  # Sanity check
72  if not exists(CHALLENGE_0_FILE):
73  raise Exception(f"no {CHALLENGE_0_FILE} found in server dir")
74 
75  # If there is no NEXT_CHALLENGE, there should also be no TRANSCRIPT
76  if not exists(NEXT_CHALLENGE_FILE):
77  if exists(TRANSCRIPT_FILE):
78  raise Exception(f"unexpected {TRANSCRIPT_FILE} in server dir")
79 
80  self.mpc = MPCCommand(phase2_config.mpc_tool)
81 

Member Function Documentation

◆ get_current_challenge_file()

str coordinator.phase2_contribution_handler.Phase2ContributionHandler.get_current_challenge_file (   self,
int  contributor_idx 
)
Return the location of the current challenge to serve.

Reimplemented from coordinator.icontributionhandler.IContributionHandler.

Definition at line 82 of file phase2_contribution_handler.py.

82  def get_current_challenge_file(self, contributor_idx: int) -> str:
83  # If there is no NEXT_CHALLENGE_FILE, use CHALLENGE_0_FILE. (Note,
84  # contributor_idx may be > 0, even if there is no NEXT_CHALLENGE_FILE.
85  # The only condition related to contributor_idx is that, if
86  # contributor_idx is 0, we MUST ONLY have the initial challenge.)
87  have_next_challenge = exists(NEXT_CHALLENGE_FILE)
88  if have_next_challenge:
89  if contributor_idx == 0:
90  raise Exception(
91  f"unexpected {NEXT_CHALLENGE_FILE} for 0-th contributor")
92  return NEXT_CHALLENGE_FILE
93  return CHALLENGE_0_FILE
94 

◆ on_completed()

None coordinator.phase2_contribution_handler.Phase2ContributionHandler.on_completed (   self)
All contributions have been received and the MPC is complete.

Reimplemented from coordinator.icontributionhandler.IContributionHandler.

Definition at line 115 of file phase2_contribution_handler.py.

115  def on_completed(self) -> None:
116  # Confirm that there has been at least one contribution, otherwise the
117  # MPC is invalid.
118  if not exists(NEXT_CHALLENGE_FILE):
119  raise Exception("no contributions made")
120 
121  # Perform a validation of the full transcript
122  mpc_valid = self.mpc.phase2_verify_transcript(
123  CHALLENGE_0_FILE,
124  NEXT_CHALLENGE_FILE,
125  TRANSCRIPT_FILE)
126  if not mpc_valid:
127  raise Exception("error in MPC transcript")
128 
129  # If all is well, move the final challenge file
130  rename(NEXT_CHALLENGE_FILE, FINAL_OUTPUT)
131  rename(TRANSCRIPT_FILE, FINAL_TRANSCRIPT)
132 
133  # Notify that handler execution completed
134  print("Phase 2 coordinator correctly executed.")
135  print("(CTRL-C to stop the server)")

◆ process_contribution()

bool coordinator.phase2_contribution_handler.Phase2ContributionHandler.process_contribution (   self,
int  contribution_idx,
str  file_name 
)
Process the given uploaded file as a contribution. If any errors are
found, throw an exception with an appropriate message, or return false.

Reimplemented from coordinator.icontributionhandler.IContributionHandler.

Definition at line 95 of file phase2_contribution_handler.py.

95  def process_contribution(
96  self, contribution_idx: int, file_name: str) -> bool:
97  orig_challenge = self.get_current_challenge_file(contribution_idx)
98  contribution_valid = self.mpc.phase2_verify_contribution(
99  orig_challenge=orig_challenge,
100  response=file_name,
101  out_new_challenge=NEW_CHALLENGE_FILE,
102  transcript=TRANSCRIPT_FILE)
103 
104  if contribution_valid:
105  if not exists(NEW_CHALLENGE_FILE):
106  raise Exception("unknown error creating new challenge")
107 
108  # Contribution has been recorded in TRANSCRIPT_FILE. Replace
109  # NEXT_CHALLENGE_FILE with NEW_CHALLENGE_FILE.
110  rename(NEW_CHALLENGE_FILE, NEXT_CHALLENGE_FILE)
111  return True
112 
113  return False
114 
Here is the call graph for this function:

Member Data Documentation

◆ mpc

coordinator.phase2_contribution_handler.Phase2ContributionHandler.mpc

Definition at line 80 of file phase2_contribution_handler.py.


The documentation for this class was generated from the following file: