Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tech debt] Cleanup repo #48

Closed
mratsim opened this issue Apr 9, 2020 · 3 comments
Closed

[Tech debt] Cleanup repo #48

mratsim opened this issue Apr 9, 2020 · 3 comments

Comments

@mratsim
Copy link
Contributor

mratsim commented Apr 9, 2020

Part of the tech debt week status-im/nimbus-eth2#867

With the varying schemes we had we have accumulated some cruft in the repo.
In preparation for auditing, the code paths that are not used should be cleaned up.

For example

@mratsim
Copy link
Contributor Author

mratsim commented Apr 10, 2020

Closed by #49

@mratsim mratsim closed this as completed Apr 10, 2020
@mratsim
Copy link
Contributor Author

mratsim commented May 26, 2020

Reopening

Another cleanup round:

proc hashToG2*(msgctx: sha256, domain: Domain): ECP2_BLS381 =
## Perform transformation of sha2-256 context (which must be already
## updated with ``message``) over domain ``domain`` to point in G2.
## https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/bls_signature.md#hash_to_g2
var
xre, xim: BIG_384
x, one: FP2_BLS381
var ctx1 = msgctx
ctx1.update(domain)
var ctx2 = ctx1
# Update hash context with coordinate marker
ctx1.update([0x01'u8])
ctx2.update([0x02'u8])
# Obtain result hash
var xrehash = ctx1.finish()
var ximhash = ctx2.finish()
discard xre.fromBytes(xrehash.data)
discard xim.fromBytes(ximhash.data)
# Convert (xre, xim) to FP2.
x.fromBigs(xre, xim)
# Set FP2 One
one.setOne()
while true:
# Without normalization of `x` 32bit version will fail
norm(x)
if ECP2_BLS381_setx(addr result, addr x) == 1:
break
# Increment `x` by FP2(1, 0)
x = add(x, one)
# Get biggest Y
let negy = neg(result.y)
# Reverting sign of ``y`` only when ``y`` less then negated one.
if cmp(result.y, negy) < 0:
result.y = negy
# Scale with G2 CoFactor
result = mulCoFactor(result)

was missed.

And when HashToCurve v7 lands and the v5 can be completely retired (probably soon as Schlesi testnet is down), we need to cleanup v5 code.

@mratsim mratsim reopened this May 26, 2020
@mratsim
Copy link
Contributor Author

mratsim commented Jul 22, 2020

Closed by #65

@mratsim mratsim closed this as completed Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant