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

feat: Schnorr signatures for privacy and storage improvements #670

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f6f62ac
added schnorr key signature
bizk Jul 25, 2023
644ab3f
initialization of basic tests
bizk Jul 25, 2023
74cf796
Improvements and test
bizk Jul 27, 2023
eab1de0
modified schnorr key structure to match amino encoding and fixed testing
bizk Jul 27, 2023
6443bb2
Registered public key into codec and added multisig tests
bizk Jul 27, 2023
5de0a68
codec registering
bizk Jul 28, 2023
0338888
Created proto file
bizk Jul 28, 2023
4a3d193
ran linter
bizk Jul 28, 2023
334b64f
merge
bizk Aug 1, 2023
ad5a726
merge with master
bizk Aug 2, 2023
330bd9d
go mod tidy
bizk Aug 2, 2023
ec56012
updated from master
bizk Aug 7, 2023
7397c8a
updated ADR
bizk Aug 7, 2023
8aef17e
added ADR
bizk Aug 7, 2023
7b222f4
fixed signature verification error bug
bizk Aug 7, 2023
d374601
downgraded version of kyber to stable v3
bizk Aug 9, 2023
1ce303c
fixed implementation
bizk Aug 9, 2023
37365b3
tidying modules
bizk Aug 9, 2023
ca8709a
added missing go module variables
bizk Aug 9, 2023
11d4635
generated and added schnorr key proto message
bizk Aug 10, 2023
9b6c2f7
fixed proto message and simplified schnoor signature and verification
bizk Aug 11, 2023
70ccadf
fixed amino encoding/decoding test failure
bizk Aug 13, 2023
7330073
Merge branch 'main' into zondax/feature/schnorr
bizk Aug 13, 2023
295cb9c
lint fix
bizk Aug 13, 2023
64dc3c1
added missing assertion
bizk Aug 13, 2023
6aef544
merge with master
bizk Aug 14, 2023
d72fea0
Merge branch 'main' into zondax/feature/schnorr
bizk Aug 14, 2023
0b787f8
linted
bizk Aug 14, 2023
7433b46
go mod tidy
bizk Aug 14, 2023
a6ee703
fixed tests and registered keys interfaces
bizk Aug 14, 2023
3afcdfa
sync with master
bizk Aug 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crypto/codec/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/keys/schnorr"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
Expand All @@ -22,6 +23,7 @@ func RegisterCrypto(cdc *codec.LegacyAmino) {
secp256k1.PubKeyName, nil)
cdc.RegisterConcrete(&kmultisig.LegacyAminoPubKey{},
kmultisig.PubKeyAminoRoute, nil)
cdc.RegisterConcrete(&schnorr.PubKey{}, schnorr.PubKeyName, nil)

cdc.RegisterInterface((*cryptotypes.PrivKey)(nil), nil)
cdc.RegisterConcrete(sr25519.PrivKey{},
Expand All @@ -30,4 +32,5 @@ func RegisterCrypto(cdc *codec.LegacyAmino) {
ed25519.PrivKeyName, nil)
cdc.RegisterConcrete(&secp256k1.PrivKey{},
secp256k1.PrivKeyName, nil)
cdc.RegisterConcrete(&schnorr.PrivKey{}, schnorr.PrivKeyName, nil)
}
3 changes: 3 additions & 0 deletions crypto/codec/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/keys/schnorr"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256r1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
Expand All @@ -16,10 +17,12 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations(pk, &ed25519.PubKey{})
registry.RegisterImplementations(pk, &secp256k1.PubKey{})
registry.RegisterImplementations(pk, &multisig.LegacyAminoPubKey{})
registry.RegisterImplementations(pk, &schnorr.PubKey{})

var priv *cryptotypes.PrivKey
registry.RegisterInterface("cosmos.crypto.PrivKey", priv)
registry.RegisterImplementations(priv, &secp256k1.PrivKey{})
registry.RegisterImplementations(priv, &ed25519.PrivKey{})
secp256r1.RegisterInterfaces(registry)
registry.RegisterImplementations(priv, &schnorr.PrivKey{})
}
3 changes: 3 additions & 0 deletions crypto/keys/multisig/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/schnorr"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
Expand All @@ -29,4 +30,6 @@ func init() {
secp256k1.PubKeyName, nil)
AminoCdc.RegisterConcrete(&LegacyAminoPubKey{},
PubKeyAminoRoute, nil)
AminoCdc.RegisterConcrete(&schnorr.PubKey{},
schnorr.PubKeyName, nil)
}
20 changes: 18 additions & 2 deletions crypto/keys/multisig/multisig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/keys/schnorr"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
Expand All @@ -28,14 +29,16 @@ import (
func TestNewMultiSig(t *testing.T) {
require := require.New(t)
pk1 := secp256k1.GenPrivKey().PubKey()
pks := []cryptotypes.PubKey{pk1, pk1}
pkSchnorr := schnorr.GenPrivKey().PubKey()
pks := []cryptotypes.PubKey{pk1, pk1, pkSchnorr}

require.NotNil(kmultisig.NewLegacyAminoPubKey(1, pks),
"Should support not unique public keys")
}

func TestAddress(t *testing.T) {
pubKeys := generatePubKeys(5)
pubKeys[1] = schnorr.GenPrivKey().PubKey()
multisigKey := kmultisig.NewLegacyAminoPubKey(2, pubKeys)

require.Len(t, multisigKey.Address().Bytes(), 20)
Expand All @@ -44,8 +47,9 @@ func TestAddress(t *testing.T) {
func TestEquals(t *testing.T) {
pubKey1 := secp256k1.GenPrivKey().PubKey()
pubKey2 := secp256k1.GenPrivKey().PubKey()
pubKey3 := schnorr.GenPrivKey().PubKey()

multisigKey := kmultisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{pubKey1, pubKey2})
multisigKey := kmultisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{pubKey1, pubKey2, pubKey3})
otherMultisigKey := kmultisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{pubKey1, multisigKey})

testCases := []struct {
Expand Down Expand Up @@ -119,6 +123,7 @@ func TestVerifyMultisignature(t *testing.T) {
"wrong size for sig bit array",
func(require *require.Assertions) {
pubKeys := generatePubKeys(3)
pubKeys[1] = schnorr.GenPrivKey().PubKey()
pk = kmultisig.NewLegacyAminoPubKey(3, pubKeys)
sig = multisig.NewMultisig(1)
},
Expand Down Expand Up @@ -214,6 +219,7 @@ func TestVerifyMultisignature(t *testing.T) {
"unable to verify signature",
func(require *require.Assertions) {
pubKeys := generatePubKeys(2)
pubKeys[1] = schnorr.GenPrivKey().PubKey()
_, sigs := generatePubKeysAndSignatures(2, msg)
pk = kmultisig.NewLegacyAminoPubKey(2, pubKeys)
sig = multisig.NewMultisig(2)
Expand Down Expand Up @@ -283,6 +289,7 @@ func TestMultiSigMigration(t *testing.T) {

func TestPubKeyMultisigThresholdAminoToIface(t *testing.T) {
pubkeys := generatePubKeys(5)
pubkeys[1] = schnorr.GenPrivKey().PubKey()
multisigKey := kmultisig.NewLegacyAminoPubKey(2, pubkeys)

ab, err := legacy.Cdc.MarshalLengthPrefixed(multisigKey)
Expand Down Expand Up @@ -315,6 +322,12 @@ func generatePubKeysAndSignatures(n int, msg []byte) (pubKeys []cryptotypes.PubK
sig, _ := privkey.Sign(msg)
signatures[i] = &signing.SingleSignatureData{Signature: sig}
}

privKeySchnorr := schnorr.GenPrivKey()
pubKeys[n-1] = privKeySchnorr.PubKey()
sigSchnorr, _ := privKeySchnorr.Sign(msg)
signatures[n-1] = &signing.SingleSignatureData{Signature: sigSchnorr}

return
}

Expand Down Expand Up @@ -378,6 +391,8 @@ func TestDisplay(t *testing.T) {

func TestAminoBinary(t *testing.T) {
pubkeys := generatePubKeys(2)
pubkeys[1] = schnorr.GenPrivKey().PubKey()

msig := kmultisig.NewLegacyAminoPubKey(2, pubkeys)

// Do a round-trip key->bytes->key.
Expand All @@ -391,6 +406,7 @@ func TestAminoBinary(t *testing.T) {

func TestAminoMarshalJSON(t *testing.T) {
pubkeys := generatePubKeys(2)
pubkeys[1] = schnorr.GenPrivKey().PubKey()
multisigKey := kmultisig.NewLegacyAminoPubKey(2, pubkeys)
bz, err := legacy.Cdc.MarshalJSON(multisigKey)
require.NoError(t, err)
Expand Down
224 changes: 224 additions & 0 deletions crypto/keys/schnorr/keys.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading