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

fix share encryption #5

Merged
merged 5 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions crypto/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ func EncodeRSAPublicKey(pk *rsa.PublicKey) ([]byte, error) {
func Encrypt(pub *rsa.PublicKey, msg []byte) ([]byte, error) {
return rsa.EncryptPKCS1v15(rand.Reader, pub, msg)
}

func Decrypt(pk *rsa.PrivateKey, msg []byte) ([]byte, error) {
return rsa.DecryptPKCS1v15(rand.Reader, pk, msg)
}
2 changes: 1 addition & 1 deletion crypto/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func VerifySignedMessageByOwner(
address := eth_crypto.PubkeyToAddress(*pk)

if common.Address(owner).Cmp(address) != 0 {
return fmt.Errorf("invalid signed reshare signature")
return fmt.Errorf("signature invalid")
}
} else {
// EIP 1271 signature
Expand Down
2 changes: 1 addition & 1 deletion crypto/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestVerifySignedReshare(t *testing.T) {
require.EqualError(t, VerifySignedMessageByOwner(stubClient,
[20]byte{},
plain,
sig), "invalid signed reshare signature")
sig), "signature invalid")
})

t.Run("valid contract signature", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (op *Operator) Init(
depositDataSig := share.SignByte(depositDataRoot[:])

// sign proof
encryptedShare, err := crypto.Encrypt(&sk.PublicKey, share.Serialize())
encryptedShare, err := crypto.Encrypt(&sk.PublicKey, []byte(share.SerializeToHexStr()))
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions result.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"crypto/rsa"
"fmt"

"github.com/ssvlabs/dkg-spec/crypto"

"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ethereum/go-ethereum/common"
eth_crypto "github.com/ethereum/go-ethereum/crypto"
"github.com/herumi/bls-eth-go-binary/bls"
"github.com/ssvlabs/dkg-spec/crypto"
)

func BuildResult(
Expand All @@ -37,7 +36,7 @@ func BuildResult(
depositDataSig := share.SignByte(depositDataRoot[:])

// sign proof
encryptedShare, err := crypto.Encrypt(&sk.PublicKey, share.Serialize())
encryptedShare, err := crypto.Encrypt(&sk.PublicKey, []byte(share.SerializeToHexStr()))
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion testing/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ethereum/go-ethereum/common"
spec "github.com/ssvlabs/dkg-spec"
spec_crypto "github.com/ssvlabs/dkg-spec/crypto"
"github.com/ssvlabs/dkg-spec/testing/fixtures"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -34,8 +35,10 @@ func TestBuildResult(t *testing.T) {
fixtures.TestNonce,
result,
))
decryptedShare, err := spec_crypto.Decrypt(fixtures.OperatorSK(fixtures.TestOperator1SK), result.SignedProof.Proof.EncryptedShare)
require.NoError(t, err)
require.EqualValues(t, []byte(fixtures.ShareSK(fixtures.TestValidator4OperatorsShare1).SerializeToHexStr()), decryptedShare)
})

}

func TestValidateResults(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Reshare struct {

type SignedReshare struct {
Reshare Reshare
// Signature is an ECDSA signature over proof
// Signature is an ECDSA signature over reshare hash
Signature []byte `ssz-max:"1536"` // 64 * 24
}

Expand Down
Loading