apply custody bit fix suggestion from Dankrad

This commit is contained in:
protolambda 2020-01-13 18:57:56 +01:00
parent 4732c7beb1
commit 507a9afbfb
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
1 changed files with 1 additions and 1 deletions

View File

@ -188,7 +188,7 @@ def get_custody_atoms(bytez: bytes) -> Sequence[bytes]:
def compute_custody_bit(key: BLSSignature, data: bytes) -> bit: def compute_custody_bit(key: BLSSignature, data: bytes) -> bit:
full_G2_element = bls.signature_to_G2(key) full_G2_element = bls.signature_to_G2(key)
s = full_G2_element[0].coeffs s = full_G2_element[0].coeffs
bits = [legendre_bit((i + 1) * s[i % 2] + int.from_bytes(atom, "little"), BLS12_381_Q) bits = [legendre_bit(sum(s[i % 2]**i * int.from_bytes(atom, "little")), BLS12_381_Q)
for i, atom in enumerate(get_custody_atoms(data))] for i, atom in enumerate(get_custody_atoms(data))]
# XOR all atom bits # XOR all atom bits
return bit(sum(bits) % 2) return bit(sum(bits) % 2)