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

Public Member Functions

def __init__ (self, Phase1ServerConfig phase1_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

 powersoftau
 
 state
 

Detailed Description

Handler processing phase1 (powersoftau) challenges and contributions. Some
complexity is involved, because we need to track the number of valid
contributions that have been made.

Definition at line 102 of file phase1_contribution_handler.py.

Constructor & Destructor Documentation

◆ __init__()

def coordinator.phase1_contribution_handler.Phase1ContributionHandler.__init__ (   self,
Phase1ServerConfig  phase1_config 
)

Definition at line 109 of file phase1_contribution_handler.py.

109  def __init__(self, phase1_config: Phase1ServerConfig):
110  self.powersoftau = PowersOfTauCommand(
111  phase1_config.powersoftau_path, phase1_config.num_powers)
112 
113  if exists(PHASE1_STATE_FILE):
114  with open(PHASE1_STATE_FILE, "r") as state_f:
115  self.state = _Phase1State.from_json(state_f.read())
116  else:
117  self.state = _Phase1State.new()
118 
119  # Create challenge file if it does not exist.
120  if not exists(CHALLENGE_FILE):
121  assert not exists(NEW_CHALLENGE_FILE)
122  assert not exists(TRANSCRIPT_FILE)
123  print("Phase1: creating initial challenge ...")
124  self.powersoftau.begin()
125  assert exists(CHALLENGE_FILE)
126 

Member Function Documentation

◆ get_current_challenge_file()

str coordinator.phase1_contribution_handler.Phase1ContributionHandler.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 127 of file phase1_contribution_handler.py.

127  def get_current_challenge_file(self, contributor_idx: int) -> str:
128  # Single "challenge" file always contains the next challenge
129  return CHALLENGE_FILE
130 

◆ on_completed()

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

Reimplemented from coordinator.icontributionhandler.IContributionHandler.

Definition at line 154 of file phase1_contribution_handler.py.

154  def on_completed(self) -> None:
155  # Confirm that there has been at least one contribution, otherwise the
156  # MPC is invalid.
157  if not exists(TRANSCRIPT_FILE):
158  raise Exception("no contributions made")
159 
160  # Perform a validation of the full transcript
161  mpc_valid = self.powersoftau.verify_transcript(
162  self.state.num_valid_contributions)
163  if not mpc_valid:
164  raise Exception("error in MPC transcript")
165 
166  # If all is well, move the final challenge file
167  rename(CHALLENGE_FILE, FINAL_OUTPUT)
168  rename(TRANSCRIPT_FILE, FINAL_TRANSCRIPT)
169 
170  # Notify that handler execution completed
171  print("Phase 1 coordinator correctly executed.")
172  print("(CTRL-C to stop the server)")
173 

◆ process_contribution()

bool coordinator.phase1_contribution_handler.Phase1ContributionHandler.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 131 of file phase1_contribution_handler.py.

131  def process_contribution(
132  self, contribution_idx: int, file_name: str) -> bool:
133 
134  rename(file_name, RESPONSE_FILE)
135  contribution_valid = self.powersoftau.verify_contribution()
136  if contribution_valid:
137  if not exists(NEW_CHALLENGE_FILE):
138  raise Exception("unknown error creating new challenge")
139 
140  # concatenate part of response into transcript
141  self.powersoftau.append_response_to_transcript(
142  RESPONSE_FILE, TRANSCRIPT_FILE)
143 
144  # update internal state
145  self.state.on_valid_contribution()
146  self._save_state()
147 
148  # move new_challenge to be the next challenge
149  rename(NEW_CHALLENGE_FILE, CHALLENGE_FILE)
150  return True
151 
152  return False
153 
Here is the call graph for this function:

Member Data Documentation

◆ powersoftau

coordinator.phase1_contribution_handler.Phase1ContributionHandler.powersoftau

Definition at line 110 of file phase1_contribution_handler.py.

◆ state

coordinator.phase1_contribution_handler.Phase1ContributionHandler.state

Definition at line 115 of file phase1_contribution_handler.py.


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