You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Checked with @protolambda, we still don't know why it works.
However a change in BLS logic was done to change the domains to pure byte (little-endian repr in practice). @arnetheduck petitionned @djrtwo to have it completely endian-independent.
Testing
We do pass the tests for bls_sign 0.8.3 (which don't use compute_domain and just pass a precomputed domain), so the underlying BLS impl seems OK
G2_cofactor=305502333931268344200999753193121504214466019254188142667664032982267604182971884026507427359259977847832272839041616661285803823378372096355777062779109q=4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787defhash_to_G2(message_hash: Bytes32, domain: Bytes8) ->Tuple[uint384, uint384]:
# Initial candidate x coordinatex_re=int.from_bytes(hash(message_hash+domain+b'\x01'), 'big')
x_im=int.from_bytes(hash(message_hash+domain+b'\x02'), 'big')
x_coordinate=Fq2([x_re, x_im]) # x = x_re + i * x_im# Test candidate y coordinates until a one is foundwhile1:
y_coordinate_squared=x_coordinate**3+Fq2([4, 4]) # The curve is y^2 = x^3 + 4(i + 1)y_coordinate=modular_squareroot(y_coordinate_squared)
ify_coordinateisnotNone: # Check if quadratic residue foundreturnmultiply_in_G2((x_coordinate, y_coordinate), G2_cofactor)
x_coordinate+=Fq2([1, 0]) # Add 1 and try again
The domain is appended in raw representation to message hash
defcompute_domain(domain_type: DomainType, fork_version: Version=Version()) ->Domain:
""" Return the domain for the ``domain_type`` and ``fork_version``. """returnDomain(domain_type+fork_version)
What
When comparing our generated signatures with mocked start:
zcli genesis mock
https://github.com/protolambda/zcliOur signature are wrong for simingly the same inputs:
Expected
A simple change in compute domain to swap to bigEndian will give the propoer output:
From
https://github.com/status-im/nim-beacon-chain/blob/82b9e008d6855a4993cb4a4adfef433f06c50035/beacon_chain/spec/helpers.nim#L142-L149
to
Checked with @protolambda, we still don't know why it works.
However a change in BLS logic was done to change the domains to pure byte (little-endian repr in practice). @arnetheduck petitionned @djrtwo to have it completely endian-independent.
Testing
We do pass the tests for bls_sign 0.8.3 (which don't use compute_domain and just pass a precomputed domain), so the underlying BLS impl seems OK
Interesting facts
hash_to_G2
The domain is appended in raw representation to message hash
compute_domain
and domain (little-endian)
The PR that introduced byte domain in py_ecc: ethereum/py_ecc#77
Especially this part that tests hash_to_G2 in with domain in big-endian to get the x coordinate (ethereum/py_ecc#77 (diff))
The text was updated successfully, but these errors were encountered: