Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.filenames: List[str] = [
os.path.join(
"tests",
"plots",
"genesis-plots-"
+ str(k)
+ sha256(int.to_bytes(i, 4, "big")).digest().hex()
+ ".dat",
)
for i in range(num_plots)
]
done_filenames = set()
try:
for pn, filename in enumerate(self.filenames):
if not os.path.exists(filename):
plotter = DiskPlotter()
plotter.create_plot_disk(filename, k, b"genesis", plot_seeds[pn])
done_filenames.add(filename)
except KeyboardInterrupt:
for filename in self.filenames:
if filename not in done_filenames and os.path.exists(filename):
os.remove(filename)
sys.exit(1)
def create_genesis_block(challenge_hash=bytes([0]*32)) -> FullBlock:
plot_seed: bytes32 = ProofOfSpace.calculate_plot_seed(pool_pk, plot_pk)
filename: str = "genesis-plot-" + token_hex(10)
plotter = DiskPlotter()
try:
plotter.create_plot_disk(filename, k, b"genesis", plot_seed)
prover = DiskProver(filename)
qualities = prover.get_qualities_for_challenge(challenge_hash)
if len(qualities) == 0:
os.remove(filename)
raise RuntimeError("No proofs for this challenge")
proof_xs: bytes = prover.get_full_proof(challenge_hash, 0)
proof_of_space: ProofOfSpace = ProofOfSpace(pool_pk, plot_pk, k, list(proof_xs))
except KeyboardInterrupt:
os.remove(filename)
sys.exit(1)
# Generate a sk based on the seed, plot size (k), and index
sk: PrivateKey = PrivateKey.from_seed(
sk_seed + args.size.to_bytes(1, "big") + i.to_bytes(4, "big")
)
# The plot seed is based on the pool and plot pks
plot_seed: bytes32 = ProofOfSpace.calculate_plot_seed(
pool_pk, sk.get_public_key()
)
filename: str = f"plot-{i}-{args.size}-{plot_seed}.dat"
full_path: str = os.path.join(plot_root, filename)
if os.path.isfile(full_path):
print(f"Plot {filename} already exists")
else:
# Creates the plot. This will take a long time for larger plots.
plotter: DiskPlotter = DiskPlotter()
plotter.create_plot_disk(full_path, args.size, bytes([]), plot_seed)
# Updates the config if necessary.
if os.path.isfile(plot_config_filename):
plot_config = safe_load(open(plot_config_filename, "r"))
else:
plot_config = {"plots": {}}
plot_config_plots_new = deepcopy(plot_config["plots"])
if filename not in plot_config_plots_new:
plot_config_plots_new[filename] = {
"sk": bytes(sk).hex(),
"pool_pk": bytes(pool_pk).hex(),
}
plot_config["plots"].update(plot_config_plots_new)
# Dumps the new config to disk.