Skip to content

Commit

Permalink
Bump libocr (#6032)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein authored Feb 18, 2022
1 parent c1c0d1d commit 6af33e3
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 15 deletions.
8 changes: 4 additions & 4 deletions core/cmd/ocr2_keys_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func TestOCR2KeyBundlePresenter_RenderTable(t *testing.T) {

key := cltest.DefaultOCR2Key
pubKeyConfig := key.ConfigEncryptionPublicKey()

pubKey := key.OffchainPublicKey()
p := cmd.OCR2KeyBundlePresenter{
JAID: cmd.JAID{ID: bundleID},
OCR2KeysBundleResource: presenters.OCR2KeysBundleResource{
JAID: presenters.NewJAID(key.ID()),
ChainType: "evm",
OnchainPublicKey: key.OnChainPublicKey(),
OffChainPublicKey: hex.EncodeToString(key.OffchainPublicKey()),
OffChainPublicKey: hex.EncodeToString(pubKey[:]),
ConfigPublicKey: hex.EncodeToString(pubKeyConfig[:]),
},
}
Expand All @@ -48,7 +48,7 @@ func TestOCR2KeyBundlePresenter_RenderTable(t *testing.T) {
assert.Contains(t, output, bundleID)
assert.Contains(t, output, key.ChainType())
assert.Contains(t, output, key.OnChainPublicKey())
assert.Contains(t, output, hex.EncodeToString(key.OffchainPublicKey()))
assert.Contains(t, output, hex.EncodeToString(pubKey[:]))
assert.Contains(t, output, hex.EncodeToString(pubKeyConfig[:]))

// Render many resources
Expand All @@ -59,7 +59,7 @@ func TestOCR2KeyBundlePresenter_RenderTable(t *testing.T) {
output = buffer.String()
assert.Contains(t, output, bundleID)
assert.Contains(t, output, key.OnChainPublicKey())
assert.Contains(t, output, hex.EncodeToString(key.OffchainPublicKey()))
assert.Contains(t, output, hex.EncodeToString(pubKey[:]))
pubKeyConfig = key.ConfigEncryptionPublicKey()
assert.Contains(t, output, hex.EncodeToString(pubKeyConfig[:]))
}
Expand Down
3 changes: 2 additions & 1 deletion core/services/keystore/keys/ocr2key/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ func ToEncryptedJSON(key KeyBundle, password string, scryptParams utils.ScryptPa
return nil, errors.Wrapf(err, "could not encrypt Eth key")
}
pubKeyConfig := key.ConfigEncryptionPublicKey()
pubKey := key.OffchainPublicKey()
encryptedOCRKExport := EncryptedOCRKeyExport{
KeyType: keyTypeIdentifier,
ChainType: key.ChainType(),
ID: key.ID(),
OnchainPublicKey: key.OnChainPublicKey(),
OffChainPublicKey: hex.EncodeToString(key.OffchainPublicKey()),
OffChainPublicKey: hex.EncodeToString(pubKey[:]),
ConfigPublicKey: hex.EncodeToString(pubKeyConfig[:]),
Crypto: cryptoJSON,
}
Expand Down
37 changes: 37 additions & 0 deletions core/services/keystore/keys/ocr2key/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ocr2key

import (
"testing"

"github.com/smartcontractkit/chainlink/core/services/keystore/chaintype"
"github.com/smartcontractkit/chainlink/core/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestExport(t *testing.T) {
var tt = []struct {
chain chaintype.ChainType
}{
{chain: chaintype.EVM},
{chain: chaintype.Terra},
{chain: chaintype.Solana},
}
for _, tc := range tt {
tc := tc
t.Run(string(tc.chain), func(t *testing.T) {
kb, err := New(tc.chain)
require.NoError(t, err)
ej, err := ToEncryptedJSON(kb, "blah", utils.FastScryptParams)
require.NoError(t, err)
kbAfter, err := FromEncryptedJSON(ej, "blah")
assert.Equal(t, kbAfter.ID(), kb.ID())
assert.Equal(t, kbAfter.PublicKey(), kb.PublicKey())
assert.Equal(t, kbAfter.OffchainPublicKey(), kb.OffchainPublicKey())
assert.Equal(t, kbAfter.MaxSignatureLength(), kb.MaxSignatureLength())
assert.Equal(t, kbAfter.Raw(), kb.Raw())
assert.Equal(t, kbAfter.ConfigEncryptionPublicKey(), kb.ConfigEncryptionPublicKey())
assert.Equal(t, kbAfter.ChainType(), kb.ChainType())
})
}
}
4 changes: 3 additions & 1 deletion core/services/keystore/keys/ocr2key/offchain_keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func (ok *OffchainKeyring) ConfigDiffieHellman(point [curve25519.PointSize]byte)
}

func (ok *OffchainKeyring) OffchainPublicKey() ocrtypes.OffchainPublicKey {
return ocrtypes.OffchainPublicKey(ed25519.PrivateKey(ok.signingKey).Public().(ed25519.PublicKey))
var offchainPubKey [ed25519.PublicKeySize]byte
copy(offchainPubKey[:], ok.signingKey.Public().(ed25519.PublicKey)[:])
return offchainPubKey
}

func (ok *OffchainKeyring) ConfigEncryptionPublicKey() ocrtypes.ConfigEncryptionPublicKey {
Expand Down
18 changes: 18 additions & 0 deletions core/services/keystore/keys/ocr2key/offchain_keyring_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ocr2key

import (
"bytes"
"crypto/ed25519"
cryptorand "crypto/rand"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestOffchainKeyring(t *testing.T) {
kr, err := newOffchainKeyring(cryptorand.Reader, cryptorand.Reader)
require.NoError(t, err)
pubKey := kr.OffchainPublicKey()
assert.True(t, bytes.Equal(kr.signingKey.Public().(ed25519.PublicKey), pubKey[:]))
}
3 changes: 2 additions & 1 deletion core/web/presenters/ocr_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ func (r OCR2KeysBundleResource) GetName() string {

func NewOCR2KeysBundleResource(key ocr2key.KeyBundle) *OCR2KeysBundleResource {
configPublic := key.ConfigEncryptionPublicKey()
pubKey := key.OffchainPublicKey()
return &OCR2KeysBundleResource{
JAID: NewJAID(key.ID()),
ChainType: string(key.ChainType()),
OnchainPublicKey: fmt.Sprintf("ocr2on_%s_%s", key.ChainType(), key.OnChainPublicKey()),
OffChainPublicKey: fmt.Sprintf("ocr2off_%s_%s", key.ChainType(), hex.EncodeToString(key.OffchainPublicKey())),
OffChainPublicKey: fmt.Sprintf("ocr2off_%s_%s", key.ChainType(), hex.EncodeToString(pubKey[:])),
ConfigPublicKey: fmt.Sprintf("ocr2cfg_%s_%s", key.ChainType(), hex.EncodeToString(configPublic[:])),
}
}
Expand Down
10 changes: 6 additions & 4 deletions core/web/resolver/ocr2_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func TestResolver_GetOCR2KeyBundles(t *testing.T) {
configPublic := k.ConfigEncryptionPublicKey()
ct, err := ToOCR2ChainType(string(k.ChainType()))
require.NoError(t, err)

pubKey := k.OffchainPublicKey()
expectedBundles = append(expectedBundles, map[string]interface{}{
"id": k.ID(),
"chainType": ct,
"onChainPublicKey": fmt.Sprintf("ocr2on_%s_%s", k.ChainType(), k.OnChainPublicKey()),
"configPublicKey": fmt.Sprintf("ocr2cfg_%s_%s", k.ChainType(), hex.EncodeToString(configPublic[:])),
"offChainPublicKey": fmt.Sprintf("ocr2off_%s_%s", k.ChainType(), hex.EncodeToString(k.OffchainPublicKey())),
"offChainPublicKey": fmt.Sprintf("ocr2off_%s_%s", k.ChainType(), hex.EncodeToString(pubKey[:])),
})
}

Expand Down Expand Up @@ -124,14 +124,15 @@ func TestResolver_CreateOCR2KeyBundle(t *testing.T) {
require.NoError(t, err)

configPublic := fakeKey.ConfigEncryptionPublicKey()
pubKey := fakeKey.OffchainPublicKey()
d, err := json.Marshal(map[string]interface{}{
"createOCR2KeyBundle": map[string]interface{}{
"bundle": map[string]interface{}{
"id": fakeKey.ID(),
"chainType": ct,
"onChainPublicKey": fmt.Sprintf("ocr2on_%s_%s", fakeKey.ChainType(), fakeKey.OnChainPublicKey()),
"configPublicKey": fmt.Sprintf("ocr2cfg_%s_%s", fakeKey.ChainType(), hex.EncodeToString(configPublic[:])),
"offChainPublicKey": fmt.Sprintf("ocr2off_%s_%s", fakeKey.ChainType(), hex.EncodeToString(fakeKey.OffchainPublicKey())),
"offChainPublicKey": fmt.Sprintf("ocr2off_%s_%s", fakeKey.ChainType(), hex.EncodeToString(pubKey[:])),
},
},
})
Expand Down Expand Up @@ -213,14 +214,15 @@ func TestResolver_DeleteOCR2KeyBundle(t *testing.T) {
require.NoError(t, err)

configPublic := fakeKey.ConfigEncryptionPublicKey()
pubKey := fakeKey.OffchainPublicKey()
d, err := json.Marshal(map[string]interface{}{
"deleteOCR2KeyBundle": map[string]interface{}{
"bundle": map[string]interface{}{
"id": fakeKey.ID(),
"chainType": ct,
"onChainPublicKey": fmt.Sprintf("ocr2on_%s_%s", fakeKey.ChainType(), fakeKey.OnChainPublicKey()),
"configPublicKey": fmt.Sprintf("ocr2cfg_%s_%s", fakeKey.ChainType(), hex.EncodeToString(configPublic[:])),
"offChainPublicKey": fmt.Sprintf("ocr2off_%s_%s", fakeKey.ChainType(), hex.EncodeToString(fakeKey.OffchainPublicKey())),
"offChainPublicKey": fmt.Sprintf("ocr2off_%s_%s", fakeKey.ChainType(), hex.EncodeToString(pubKey[:])),
},
},
})
Expand Down
3 changes: 2 additions & 1 deletion core/web/resolver/orc2_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (r OCR2KeyBundleResolver) OnChainPublicKey() string {

// OffChainPublicKey returns the OCR2 Key bundle off-chain public key
func (r OCR2KeyBundleResolver) OffChainPublicKey() string {
return fmt.Sprintf("ocr2off_%s_%s", r.key.ChainType(), hex.EncodeToString(r.key.OffchainPublicKey()))
pubKey := r.key.OffchainPublicKey()
return fmt.Sprintf("ocr2off_%s_%s", r.key.ChainType(), hex.EncodeToString(pubKey[:]))
}

// ConfigPublicKey returns the OCR2 Key bundle config public key
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ require (
github.com/smartcontractkit/chainlink-terra v0.0.8-0.20220216122320-59318dd4d684
github.com/smartcontractkit/helmenv v1.0.36
github.com/smartcontractkit/integrations-framework v1.0.48
github.com/smartcontractkit/libocr v0.0.0-20220125200954-5b957c834276
github.com/smartcontractkit/libocr v0.0.0-20220217180537-449836e6cfec
github.com/smartcontractkit/sqlx v1.3.5-0.20210805004948-4be295aacbeb
github.com/smartcontractkit/terra.go v1.0.3-0.20220108002221-62b39252ee16
github.com/smartcontractkit/wsrpc v0.3.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2306,8 +2306,8 @@ github.com/smartcontractkit/helmenv v1.0.36/go.mod h1:pkScfFRZM9UhMAqeG+Bfxyy7Yj
github.com/smartcontractkit/integrations-framework v1.0.48 h1:yeGBbu+AXlkR4kT4tKound3dItFMDMTczIirdX48lJ4=
github.com/smartcontractkit/integrations-framework v1.0.48/go.mod h1:tWnoNol2k1yDW8ybOqK7QXFp6Xl2wnI6ASn398JPMJA=
github.com/smartcontractkit/libocr v0.0.0-20201203233047-5d9b24f0cbb5/go.mod h1:bfdSuLnBWCkafDvPGsQ1V6nrXhg046gh227MKi4zkpc=
github.com/smartcontractkit/libocr v0.0.0-20220125200954-5b957c834276 h1:sE+0R3qyCnZRiDoEoWT8St+Pmb1ZdRDhyq7xZPrwoZ0=
github.com/smartcontractkit/libocr v0.0.0-20220125200954-5b957c834276/go.mod h1:nq3crM3wVqnyMlM/4ZydTuJ/WyCapAsOt7P94oRgSPg=
github.com/smartcontractkit/libocr v0.0.0-20220217180537-449836e6cfec h1:vkTYAihTA8qQ30LKd0272NWLzOCWWCw78qk0LtIej0A=
github.com/smartcontractkit/libocr v0.0.0-20220217180537-449836e6cfec/go.mod h1:nq3crM3wVqnyMlM/4ZydTuJ/WyCapAsOt7P94oRgSPg=
github.com/smartcontractkit/sqlx v1.3.5-0.20210805004948-4be295aacbeb h1:OMaBUb4X9IFPLbGbCHsMU+kw/BPCrewaVwWGIBc0I4A=
github.com/smartcontractkit/sqlx v1.3.5-0.20210805004948-4be295aacbeb/go.mod h1:HNUu4cJekUdsJbwRBCiOybtkPJEfGRELQPe2tkoDEyk=
github.com/smartcontractkit/terra.go v1.0.3-0.20220108002221-62b39252ee16 h1:k+E0RKzVSG1QpxXakNUtcGUhq4ZMe0MAJ5Awg/l9oSc=
Expand Down

0 comments on commit 6af33e3

Please sign in to comment.