Skip to content

crypto: add BLS12381 validator key type - #2

Merged
shumkov merged 11 commits into
dashpay:masterfrom
QuantumExplorer:quantumexplorer/switchtobls
Oct 10, 2020
Merged

shumkov merged 11 commits into
dashpay:masterfrom
QuantumExplorer:quantumexplorer/switchtobls

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Description

This pull request adds bls12381 keys to tendermint. The Dash ecosystem heavily relies on BLS keys in the masternode network for threshold signing and distributed key generation. Out of scope of this pull request is all key or signature aggregation and threshold signing.

@alexanderbez alexanderbez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look great so far. I can't speak to the CGO or actual BLS code, but so far it seems to be on the right path 👍

Comment thread crypto/bls12381/bls12381.go Resolved
Comment thread crypto/crypto.go Resolved
Comment thread light/helpers_test.go Resolved
Comment thread light/helpers_test.go Resolved
Comment thread light/verifier_test.go Resolved
Comment thread state/tx_filter.go
func TxPreCheck(state State) mempl.PreCheckFunc {
maxDataBytes := types.MaxDataBytesUnknownEvidence(
state.ConsensusParams.Block.MaxBytes,
crypto.BLS12381,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change necessary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its because signature sizes are different in BLS and ED keys, which will change the max data bytes.
BLS public keys are 48 bytes and sigs are 96 bytes. Ed public keys are 32 bytes and sigs are 64 bytes. So a 16 byte difference for a public key and a 32 byte difference for the signature.

maxEvidenceBytes := int64(maxNumEvidence) * MaxEvidenceBytesForKeyType(keyType) maxDataBytes := maxBytes - MaxOverheadForBlock - MaxHeaderBytes - int64(valsCount)*MaxVoteBytesForKeyType(keyType) - maxEvidenceBytes

The max evidence bytes should then vary by the difference in public key size and signature size, here 48.

The max vote size should vary by the signature size, here 32.

I wrote this a while ago so am not 100% sure of my logic. I guess I should have commented more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Yes, I'd add a small godoc on this explaining how/why.

Comment thread state/tx_filter_test.go
func TestTxFilter(t *testing.T) {
genDoc := randomGenesisDoc()
genDoc.ConsensusParams.Block.MaxBytes = 3000
genDoc.ConsensusParams.Block.MaxBytes = 3080

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasoning for this change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a difference of 48 in the max evidence size and 32 in the max vote size so 80 total for 1 evidence and 1 validator.

Comment thread types/block.go
//
// XXX: Panics on negative result.
func MaxDataBytes(maxBytes int64, valsCount, evidenceCount int) int64 {
func MaxDataBytes(maxBytes int64, keyType crypto.KeyType, valsCount, evidenceCount int) int64 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a key type provided in these?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason as stated above.

alexanderbez
alexanderbez previously approved these changes Sep 23, 2020

@alexanderbez alexanderbez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to approve this 👍

Also, any chance we can get CI tests to pass? I took a very brief look and it seems some of the C++/CGO stuff is missing?

Comment thread CHANGELOG.md Resolved
Comment thread abci/example/kvstore/kvstore_test.go Resolved
Comment thread abci/types/pubkey.go Resolved
Comment thread consensus/replay_test.go Resolved
Comment thread consensus/wal.go Resolved
Comment thread docs/architecture/adr-024-sign-bytes.md Resolved
Comment thread libs/events/README.md Resolved
Comment thread p2p/conn/evil_secret_connection_test.go Resolved
Comment thread privval/socket_listeners.go Resolved
Comment thread scripts/linkify_changelog.py Resolved
@shumkov shumkov changed the title [Improvement] Add BLS12381 keys to Tendermint and use them for validators. crypto: add BLS12381 key type Sep 23, 2020
@shumkov shumkov changed the title crypto: add BLS12381 key type crypto: add BLS12381 validator ey type Sep 23, 2020
@shumkov shumkov changed the title crypto: add BLS12381 validator ey type crypto: add BLS12381 validator key type Sep 23, 2020
@shumkov

shumkov commented Oct 1, 2020

Copy link
Copy Markdown
Collaborator

@QuantumExplorer hey! Why do you update markdown documents formatting in this PR?

@shumkov shumkov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Agreed to disabled some actions due to issue with cgo

@shumkov
shumkov merged commit abe83d5 into dashpay:master Oct 10, 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

Successfully merging this pull request may close these issues.

4 participants