Skip to content

Commit

Permalink
base 1 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nareshmmr committed Nov 26, 2024
1 parent e14f1d4 commit fc263af
Show file tree
Hide file tree
Showing 27 changed files with 3,127 additions and 264 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Go package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build and test plugin
working-directory: ./go/ocr2/decryptionplugin
run: |
go build -v ./...
go test -v ./...
- name: Download npm deps
working-directory: ./js/tdh2
run: npm install

- name: Build and test TDH2
working-directory: ./go/tdh2
run: |
go build -v ./...
go test -v ./...
2 changes: 2 additions & 0 deletions go/go.work.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
github.com/gtank/ristretto255 v0.1.3-0.20210930101514-6bb39798585c/go.mod h1:tDPFhGdt3hJWqtKwx57i9baiB1Cj0yAg22VOPUqm5vY=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
Expand Down
22 changes: 8 additions & 14 deletions go/ocr2/decryptionplugin/config/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package config

import (
"fmt"
"math"

"github.com/goplugin/plugin-libocr/commontypes"
"google.golang.org/protobuf/proto"
)

Expand All @@ -26,16 +22,14 @@ func EncodeReportingPluginConfig(rpConfig *ReportingPluginConfigWrapper) ([]byte
return proto.Marshal(rpConfig.Config)
}

func EncodeOracleIdtoKeyShareIndex(oracleID commontypes.OracleID, keyShareIndex int) *OracleIDtoKeyShareIndex {
return &OracleIDtoKeyShareIndex{
OracleId: uint32(oracleID),
KeyShareIndex: uint32(keyShareIndex),
}
//go:generate mockery --quiet --name ConfigParser --output ./mocks/ --case=underscore
type ConfigParser interface {
ParseConfig(offchainConfig []byte) (*ReportingPluginConfigWrapper, error)
}

func DecodeOracleIdtoKeyShareIndex(oracleIDtoKeyShareIndex *OracleIDtoKeyShareIndex) (commontypes.OracleID, int, error) {
if oracleIDtoKeyShareIndex.OracleId > math.MaxUint8 {
return 0, 0, fmt.Errorf("oracleID is larger than MAX_UINT8")
}
return commontypes.OracleID(oracleIDtoKeyShareIndex.OracleId), int(oracleIDtoKeyShareIndex.KeyShareIndex), nil
type DefaultConfigParser struct {
}

func (p *DefaultConfigParser) ParseConfig(offchainConfig []byte) (*ReportingPluginConfigWrapper, error) {
return DecodeReportingPluginConfig(offchainConfig)
}
61 changes: 13 additions & 48 deletions go/ocr2/decryptionplugin/config/config_types.pb.go

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

3 changes: 0 additions & 3 deletions go/ocr2/decryptionplugin/config/config_types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@ message ReportingPluginConfig {
uint32 request_count_limit = 4;
uint32 request_total_bytes_limit = 5;
bool require_local_request_check = 6;
bytes public_key = 7;
bytes priv_key_share = 8;
repeated OracleIDtoKeyShareIndex oracle_id_to_key_index = 9;
}
54 changes: 54 additions & 0 deletions go/ocr2/decryptionplugin/config/mocks/config_parser.go

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

43 changes: 15 additions & 28 deletions go/ocr2/decryptionplugin/decryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import (
"github.com/goplugin/plugin-libocr/commontypes"
"github.com/goplugin/plugin-libocr/offchainreporting2/types"
"github.com/goplugin/tdh2/go/ocr2/decryptionplugin/config"
"github.com/goplugin/tdh2/go/tdh2easy"
"github.com/goplugin/tdh2/go/tdh2/tdh2easy"
"google.golang.org/protobuf/proto"
)

type DecryptionReportingPluginFactory struct {
DecryptionQueue DecryptionQueuingService
Logger commontypes.Logger
DecryptionQueue DecryptionQueuingService
ConfigParser config.ConfigParser
PublicKey *tdh2easy.PublicKey
PrivKeyShare *tdh2easy.PrivateShare
OracleToKeyShare map[commontypes.OracleID]int
Logger commontypes.Logger
}

type decryptionPlugin struct {
Expand All @@ -30,12 +34,12 @@ type decryptionPlugin struct {

// NewReportingPlugin complies with ReportingPluginFactory.
func (f DecryptionReportingPluginFactory) NewReportingPlugin(rpConfig types.ReportingPluginConfig) (types.ReportingPlugin, types.ReportingPluginInfo, error) {
pluginConfig, err := config.DecodeReportingPluginConfig(rpConfig.OffchainConfig)
pluginConfig, err := f.ConfigParser.ParseConfig(rpConfig.OffchainConfig)
if err != nil {
f.Logger.Error("unable to decode reporting plugin config", commontypes.LogFields{
"configDigest": rpConfig.ConfigDigest.String(),
})
return nil, types.ReportingPluginInfo{}, fmt.Errorf("unalbe to decode reporting plugin config: %w", err)
return nil, types.ReportingPluginInfo{}, fmt.Errorf("unable to decode reporting plugin config: %w", err)
}

info := types.ReportingPluginInfo{
Expand All @@ -49,33 +53,16 @@ func (f DecryptionReportingPluginFactory) NewReportingPlugin(rpConfig types.Repo
},
}

oracleToKeyShare := make(map[commontypes.OracleID]int)
for _, entry := range pluginConfig.Config.OracleIdToKeyIndex {
oID, ksID, err := config.DecodeOracleIdtoKeyShareIndex(entry)
if err != nil {
return nil, types.ReportingPluginInfo{}, fmt.Errorf("unalbe to decode reporting plugin oracle id to key Share index mapping: %w", err)
}
oracleToKeyShare[oID] = ksID
}

plugin := decryptionPlugin{
f.Logger,
f.DecryptionQueue,
&tdh2easy.PublicKey{},
&tdh2easy.PrivateShare{},
oracleToKeyShare,
f.PublicKey,
f.PrivKeyShare,
f.OracleToKeyShare,
&rpConfig,
pluginConfig,
}

if err = plugin.publicKey.Unmarshal(pluginConfig.Config.PublicKey); err != nil {
return nil, info, fmt.Errorf("cannot unmarshal public key: %w", err)
}

if err = plugin.privKeyShare.Unmarshal(pluginConfig.Config.PrivKeyShare); err != nil {
return nil, info, fmt.Errorf("cannot unmarshal private key share: %w", err)
}

return &plugin, info, nil
}

Expand Down Expand Up @@ -261,13 +248,13 @@ func (dp *decryptionPlugin) Report(ctx context.Context, ts types.ReportTimestamp
continue
}

validDecryptionShares[ciphertextID] = append(validDecryptionShares[ciphertextID], validDecryptionShare)
if len(validDecryptionShares[ciphertextID]) >= fPlusOne {
if len(validDecryptionShares[ciphertextID]) < fPlusOne {
validDecryptionShares[ciphertextID] = append(validDecryptionShares[ciphertextID], validDecryptionShare)
} else {
dp.logger.Trace("DecryptionReporting Report: we have already f+1 valid decryption shares", commontypes.LogFields{
"ciphertextID": ciphertextID,
"observer": ob.Observer,
})
break
}
}
}
Expand Down
Loading

0 comments on commit fc263af

Please sign in to comment.