From c3c24b4fc4a1592a9dc6d42fb57694aae59ee383 Mon Sep 17 00:00:00 2001 From: Dankrad Feist Date: Sun, 5 Apr 2020 15:35:11 +0100 Subject: [PATCH] Fix lint --- specs/phase1/custody-game.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/specs/phase1/custody-game.md b/specs/phase1/custody-game.md index 370972502..c1ed24383 100644 --- a/specs/phase1/custody-game.md +++ b/specs/phase1/custody-game.md @@ -193,11 +193,12 @@ def get_custody_atoms(bytez: bytes) -> Sequence[bytes]: Extract the custody secrets from the signature ```python -def get_custody_secrets(key: BLSSignature): +def get_custody_secrets(key: BLSSignature) -> Sequence[int]: full_G2_element = bls.signature_to_G2(key) signature = full_G2_element[0].coeffs - signature_bytes = sum(x.to_bytes(48, "little") for x in signature) - secrets = [int.from_bytes(x[i:i+BYTES_PER_CUSTODY_ATOM]) for i in range(0, len(signature_bytes), 32)] + signature_bytes = b"".join(x.to_bytes(48, "little") for x in signature) + secrets = [int.from_bytes(signature_bytes[i:i + BYTES_PER_CUSTODY_ATOM], "little") + for i in range(0, len(signature_bytes), 32)] return secrets ``` @@ -208,8 +209,9 @@ def compute_custody_bit(key: BLSSignature, data: bytes) -> bit: secrets = get_custody_secrets(key) custody_atoms = get_custody_atoms(data) n = len(custody_atoms) - uhf = sum(secrets[i % CUSTORY_SECRETS]**i * int.from_bytes(atom, "little") for i, atom in enumerate(custody_atoms)) + secrets[n % CUSTORY_SECRETS]**n - return legendre_bit(uhf + secrets[0], BLS12_381_Q) + uhf = (sum(secrets[i % CUSTODY_SECRETS]**i * int.from_bytes(atom, "little") % CUSTODY_PRIME + for i, atom in enumerate(custody_atoms)) + secrets[n % CUSTODY_SECRETS]**n) % CUSTODY_PRIME + return legendre_bit(uhf + secrets[0], CUSTODY_PRIME) ``` ### `get_randao_epoch_for_custody_period`