GithubHelp home page GithubHelp logo

redstone-finance / bls-crypto Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sivo4kin/bls-crypto

1.0 0.0 1.0 20.5 MB

BLS signature and multi-signature schemas in Go and Solidity

License: Apache License 2.0

Go 63.79% Makefile 0.22% Solidity 36.00%

bls-crypto's Introduction

BLS signature and multisignature schemas in Go and Solidity

This code demonstrates the following schemas. Sign functions signature are in GoLang, verifies are both in Golang and Solidity using Ethereum precompiled callbacks.

BLS signature scheme.

  1. Alice signs a message.
  2. Everyone verifies it using her public key.
secretKey, publicKey := bls.GenerateRandomKey()
signature := secretKey.Sign(message)
genuine := signature.Verify(publicKey, message)

Refer to sign_test.go for more code.

BLS signature aggregation (n-of-n multisignature).

  1. A group of participants sign a message.
  2. Their signatures are aggregated into one.
  3. Everyone verifies the aggregated signature using the aggregated public key.
sig0 := priv0.Sign(msg)
sig1 := priv1.Sign(msg)
sig2 := priv2.Sign(msg)
genuine := sig0.Aggregate(sig1).Aggregate(sig2).Verify(pub0.Aggregate(pub2).Aggregate(pub1), message)

Refer to aggregated_test.go for more code.

Accountable-Subgroup Multisignatures (threshold signatures, m-of-n multisignatures).

  1. A subgroup of a group of participants sign a message.
  2. Their signatures are aggregated into one.
  3. Everyone verifies the aggregated signature using
    • the aggregated signature,
    • the aggregated public key of the subgroup (who really signed),
    • the aggregated public key of all participants in the group (whether signed or not),
    • the bitmap representing the subgroup (who really signed) - this is what accountable is.
allPub := pub0.Aggregate(pub1).Aggregate(pub2)

// Setup phase - generate membership keys
mk0 := priv0.GenerateMembershipKeyPart(0, allPub, Simple).
    Aggregate(priv1.GenerateMembershipKeyPart(0, allPub, Simple)).
    Aggregate(priv2.GenerateMembershipKeyPart(0, allPub, Simple))
mk1 := priv0.GenerateMembershipKeyPart(1, allPub, Simple).
    Aggregate(priv1.GenerateMembershipKeyPart(1, allPub, Simple)).
    Aggregate(priv2.GenerateMembershipKeyPart(1, allPub, Simple))
mk2 := priv0.GenerateMembershipKeyPart(2, allPub, Simple).
    Aggregate(priv1.GenerateMembershipKeyPart(2, allPub, Simple)).
    Aggregate(priv2.GenerateMembershipKeyPart(2, allPub, Simple))

// Sign only by #0 and #2
mask := big.NewInt(0b101)
sig0 := priv0.Multisign(msg, allPub, mk0)
sig2 := priv2.Multisign(msg, allPub, mk2)
subSig := sig0.Aggregate(sig2)
subPub := pub0.Aggregate(pub2)

genuine := subSig.VerifyMultisig(allPub, subPub, msg, mask)

Refer to multisig_test.go for more code.

Inspired by

References

  1. Dan Boneh, Manu Drijvers, and Gregory Neven. Compact Multi-Signatures for Smaller Blockchains. https://crypto.stanford.edu/~dabo/pubs/abstracts/ASM.html
  2. BLS signatures: better than Schnorr. https://medium.com/cryptoadvance/bls-signatures-better-than-schnorr-5a7fe30ea716
  3. Dan Boneh, Victor Shoup. A Graduate Course in Applied Cryptography. Chapter 15: Elliptic curve cryptography and pairings. http://toc.cryptobook.us/
  4. EIP-196: Precompiled contracts for addition and scalar multiplication on the elliptic curve alt_bn128. https://eips.ethereum.org/EIPS/eip-196

Prerequisites to run tests

  1. Install go compiler: v1.16+ https://golang.org/doc/install

  2. Install solc: v0.8+ https://docs.soliditylang.org/en/v0.8.6/installing-solidity.html

  3. Install abigen:

     cd bls-crypto
     make dep
     cd $GOPATH/pkg/mod/github.com/ethereum/go-ethereum@*
     make devtools
    

Run tests

make test

Test parameters

Note that there are parameters specified in the aggregated_test.go file that affect the gas usage:

  • MESSAGE_SIZE - size of the message being signed in bytes.
  • PARTICIPANTS_NUMBER - total number of participants in a group who sign the message.

bls-crypto's People

Contributors

denisglotov avatar

Stargazers

 avatar

Forkers

manipulation44

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.