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
Introduce BLS library into codebase #1823
Labels
Comments
Exalate commented: Issue Created by: blukat29 |
This was referenced Apr 11, 2023
Merged
For BLS key derivation and pop generation, these are the requirements:
In terms of ERC-2333, the For typescript implementation, there is no library that supports both features. Thus,
Sample code) import loadBls from "bls-signatures";
import { deriveKeyFromEntropy } from "@chainsafe/bls-keygen";
type Unpromisify<T> = T extends Promise<infer U> ? U : T;
let BLS: Unpromisify<ReturnType<typeof loadBls>>;
function deriveKey(ikm: Uint8Array) {
return deriveKeyFromEntropy(ikm);
}
function generatePop(privkey: Uint8Array) {
const blskey = BLS.PrivateKey.from_bytes(privkey, true);
const pop = BLS.PopSchemeMPL.pop_prove(blskey);
return pop.serialize();
}
async function main() {
BLS = await loadBls();
const nodekey = Buffer.from(
"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"hex",
);
const blskey = deriveKey(nodekey);
const pop = generatePop(blskey);
console.log("blskey", Buffer.from(blskey).toString("hex"));
console.log("pop", Buffer.from(pop).toString("hex"));
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your request related to a problem? Please describe.
Klaytn needs to bring in BLS algorithm for RANDAO, optimized consensus and EIP-2537.
BLS functionality can be split into two layers:
G1.Add(P,Q)
. An example usage is the EIP-2537 precompiles.Sign()
andAggregateVerify()
. Example usages are RANDAO and block signatures.Klaytn should need both layers.
Describe the solution you'd like
Below are potential Go open sources we can use.
geth/crypto/bls12381
package implements BLS12-381 arithmetic. It has been stable since 2022 and geth implements EIP-2537 using this package. So I think it's a safe bet to use geth's crypto/bls12381 if Klaytn will support EIP-2537.celo/crypto/bls12381
is similar togeth/crypto/bls12381
, but has diverted from geth's since 2021.celo-bls-go
is another package used by celo blockchain for its consensus. celo-bls-go implements BLS12-377 curve. Note that Ethereum uses BLS12-381.prysm/crypto/bls
is a package within prysm consensus layer (CL) client that implements BLS signature. It is a wrapper around thesupranational/blst
package. It is configured as (G1=pub,G2=sig) mode.supranational/blst
package is an independent BLS library. It supports both modes - (G1=pub,G2=sig) and (G1=sig,G2=pub).I propose to combine approaches of geth and prysm.
geth/crypto/bls12381
for BLS12-381 arithmetic.supranational/blst
and writeklaytn/bls
wrapper for BLS signatures.To summarize,
celo-bls-go (BLS12-377)
supranational/blst
supranational/blst
Describe alternatives you've considered
Instead of adding source code to klaytn/klaytn repo, we might simply import geth and prysm internal packages.
Additional context
Other cases:
supranational/blst
.supranational/blst
and miracl crypto lib.supranational/blst
and Apache Milagro crypto libsupranational/blst
and herumi/bls-eth-wasm.supranational/blst
is a popular choice an an underlying crypto library.Benchmark tests
geth/crypto/bls12381
performance is consistent with EIP-2537 gas pricing.supranational/blst
takes up to 2ms to Sign once, Verify once, or AggregateVerify 100 signatures. I think it is enough for consensus purposes.The text was updated successfully, but these errors were encountered: