Skip to content
Draft
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
71 changes: 71 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ import (
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
crontypes "github.com/scrtlabs/SecretNetwork/x/cron/types"
tssabci "github.com/scrtlabs/SecretNetwork/x/tss/abci"
tsstypes "github.com/scrtlabs/SecretNetwork/x/tss/types"

"cosmossdk.io/log"
upgradetypes "cosmossdk.io/x/upgrade/types"
Expand Down Expand Up @@ -347,6 +349,23 @@ func NewSecretNetworkApp(
app.AppKeepers.CronKeeper.SetTxConfig(txConfig)

app.AppKeepers.InitCustomKeepers(appCodec, legacyAmino, bApp, bootstrap, homePath, computeConfig)

// Set up TSS module integrations
// 1. Connect TSS keeper to compute keeper for contract callbacks
app.AppKeepers.TssKeeper.SetWasmKeeper(app.AppKeepers.ComputeKeeper)

// 2. Set up TSS vote extension handlers for validator participation in DKG/signing
tssVoteExtHandler := tssabci.NewVoteExtensionHandler(app.AppKeepers.TssKeeper, logger)
tssProposalHandler := tssabci.NewProposalHandler(app.AppKeepers.TssKeeper, logger)

bApp.SetExtendVoteHandler(tssVoteExtHandler.ExtendVote)
bApp.SetVerifyVoteExtensionHandler(tssVoteExtHandler.VerifyVoteExtension)
bApp.SetPrepareProposal(tssProposalHandler.PrepareProposal)
bApp.SetProcessProposal(tssProposalHandler.ProcessProposal)

// 3. Load validator identity from priv_validator_key.json for TSS participation
app.loadValidatorIdentity(homePath)

app.setupUpgradeStoreLoaders()

// NOTE: Any module instantiated in the module manager that is later modified
Expand Down Expand Up @@ -673,6 +692,7 @@ func SetOrderBeginBlockers(app *SecretNetworkApp) {
ibcswitchtypes.ModuleName,
crontypes.ModuleName,
circuittypes.ModuleName,
tsstypes.ModuleName, // TSS processes pending data from vote extensions
)
}

Expand Down Expand Up @@ -707,6 +727,7 @@ func SetOrderInitGenesis(app *SecretNetworkApp) {
feegrant.ModuleName,
crontypes.ModuleName,
circuittypes.ModuleName,
tsstypes.ModuleName,
)
}

Expand All @@ -733,9 +754,59 @@ func SetOrderEndBlockers(app *SecretNetworkApp) {
ibcfeetypes.ModuleName,
packetforwardtypes.ModuleName,
compute.ModuleName,
tsstypes.ModuleName, // TSS EndBlocker MUST come after compute for contract callbacks
reg.ModuleName,
ibcswitchtypes.ModuleName,
crontypes.ModuleName,
circuittypes.ModuleName,
)
}

// loadValidatorIdentity reads the validator's private key from priv_validator_key.json
// and sets it on the TSS keeper for participation in threshold signing
func (app *SecretNetworkApp) loadValidatorIdentity(homePath string) {
privValKeyFile := filepath.Join(homePath, "config", "priv_validator_key.json")

// Check if file exists
if _, err := os.Stat(privValKeyFile); os.IsNotExist(err) {
// Not a validator node, skip
return
}

// Read the file
keyFileBytes, err := os.ReadFile(privValKeyFile)
if err != nil {
fmt.Fprintf(os.Stderr, "Warning: Failed to read priv_validator_key.json for TSS: %v\n", err)
return
}

// Parse the JSON
var keyData struct {
Address string `json:"address"`
PubKey struct {
Type string `json:"type"`
Value string `json:"value"`
} `json:"pub_key"`
PrivKey struct {
Type string `json:"type"`
Value string `json:"value"`
} `json:"priv_key"`
}

if err := tmjson.Unmarshal(keyFileBytes, &keyData); err != nil {
fmt.Fprintf(os.Stderr, "Warning: Failed to parse priv_validator_key.json for TSS: %v\n", err)
return
}

// Decode the private key (base64 encoded)
privKeyBytes, err := base64.StdEncoding.DecodeString(keyData.PrivKey.Value)
if err != nil {
fmt.Fprintf(os.Stderr, "Warning: Failed to decode validator private key for TSS: %v\n", err)
return
}

// Set validator identity on TSS keeper
// Address is already in hex format
app.AppKeepers.TssKeeper.SetValidatorConsensusAddress(keyData.Address)
app.AppKeepers.TssKeeper.SetValidatorPrivateKey(privKeyBytes)
}
17 changes: 17 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ import (

reg "github.com/scrtlabs/SecretNetwork/x/registration"

tsskeeper "github.com/scrtlabs/SecretNetwork/x/tss/keeper"
tsstypes "github.com/scrtlabs/SecretNetwork/x/tss/types"

ibcpacketforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper"
ibcpacketforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types"

Expand Down Expand Up @@ -119,6 +122,9 @@ type SecretAppKeepers struct {

ConsensusParamsKeeper consensusparamkeeper.Keeper

// TSS (Threshold Signature Scheme) keeper for distributed key generation and signing
TssKeeper *tsskeeper.Keeper

// keys to access the substores
keys map[string]*storetypes.KVStoreKey
tKeys map[string]*storetypes.TransientStoreKey
Expand Down Expand Up @@ -250,6 +256,16 @@ func (ak *SecretAppKeepers) InitSdkKeepers(
)
ak.CronKeeper = cronKeeper

// Initialize TSS (Threshold Signature Scheme) keeper
tssKeeper := tsskeeper.NewKeeper(
runtime.NewKVStoreService(ak.keys[tsstypes.StoreKey]),
appCodec,
authcodec.NewBech32Codec(scrt.Bech32PrefixAccAddr),
authtypes.NewModuleAddress(govtypes.ModuleName),
ak.StakingKeeper,
)
ak.TssKeeper = &tssKeeper

feegrantKeeper := feegrantkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(ak.keys[feegrant.StoreKey]),
Expand Down Expand Up @@ -605,6 +621,7 @@ func (ak *SecretAppKeepers) InitKeys() {
ibchookstypes.StoreKey,
circuittypes.StoreKey,
crontypes.StoreKey,
tsstypes.StoreKey,
)

ak.tKeys = storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down
2 changes: 2 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
crontypes "github.com/scrtlabs/SecretNetwork/x/cron/types"
ibcswitch "github.com/scrtlabs/SecretNetwork/x/emergencybutton"
reg "github.com/scrtlabs/SecretNetwork/x/registration"
tssmodule "github.com/scrtlabs/SecretNetwork/x/tss/module"
)

var ModuleAccountPermissions = map[string][]string{
Expand Down Expand Up @@ -92,5 +93,6 @@ func Modules(
ibcfee.NewAppModule(app.AppKeepers.IbcFeeKeeper),
ibcswitch.NewAppModule(app.AppKeepers.IbcSwitchKeeper, app.AppKeepers.GetSubspace(ibcswitch.ModuleName)),
cron.NewAppModule(app.appCodec, *app.AppKeepers.CronKeeper),
tssmodule.NewAppModule(appCodec, *app.AppKeepers.TssKeeper, app.AppKeepers.AccountKeeper, app.AppKeepers.BankKeeper),
}
}
18 changes: 16 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ replace (
cosmossdk.io/api => github.com/scrtlabs/cosmos-sdk-api v0.7.6-secret.0
cosmossdk.io/store => github.com/scrtlabs/cosmos-sdk-store v1.1.1-secret.1
cosmossdk.io/x/tx => github.com/scrtlabs/cosmos-sdk-x-tx v0.13.7-secret.0
github.com/agl/ed25519 => github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412
github.com/cometbft/cometbft => github.com/scrtlabs/tendermint v0.38.19-secret.0
github.com/cosmos/cosmos-sdk => github.com/scrtlabs/cosmos-sdk v0.50.14-secret.4
github.com/cosmos/iavl => github.com/scrtlabs/iavl v1.2.2-secret.0
Expand All @@ -20,6 +21,7 @@ replace (
)

require (
github.com/bnb-chain/tss-lib/v2 v2.0.2
github.com/cometbft/cometbft v0.38.12
github.com/cosmos/cosmos-sdk v0.50.9
github.com/cosmos/go-bip39 v1.0.0
Expand All @@ -39,6 +41,7 @@ require (
github.com/spf13/pflag v1.0.6
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
github.com/taurusgroup/frost-ed25519 v0.0.0-20210707140332-5abc84a4dba7
golang.org/x/crypto v0.33.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
gonum.org/v1/gonum v0.15.1
Expand All @@ -64,10 +67,12 @@ require (
cosmossdk.io/api v0.7.6
cosmossdk.io/client/v2 v2.0.0-beta.3
cosmossdk.io/collections v0.4.0
cosmossdk.io/depinject v1.1.0
cosmossdk.io/math v1.4.0
cosmossdk.io/tools/confix v0.1.2
cosmossdk.io/x/circuit v0.1.1
cosmossdk.io/x/tx v0.13.7
filippo.io/edwards25519 v1.1.0
github.com/btcsuite/btcutil v1.0.2
github.com/cometbft/cometbft-db v0.14.1
github.com/cosmos/cosmos-db v1.1.1
Expand All @@ -88,17 +93,17 @@ require (
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/iam v1.1.9 // indirect
cloud.google.com/go/storage v1.41.0 // indirect
cosmossdk.io/depinject v1.1.0 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/agl/ed25519 v0.0.0-20200225211852-fd4d107ace12 // indirect
github.com/aws/aws-sdk-go v1.44.224 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/bits-and-blooms/bitset v1.8.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
Expand All @@ -120,6 +125,7 @@ require (
github.com/creachadair/tomledit v0.0.24 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v4 v4.2.0 // indirect
Expand Down Expand Up @@ -153,10 +159,12 @@ require (
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.4 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.5.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
Expand All @@ -170,6 +178,8 @@ require (
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-log/v2 v2.1.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.17.11 // indirect
Expand All @@ -189,6 +199,8 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/otiai10/primes v0.0.0-20210501021515-f1b2be525a11 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down Expand Up @@ -218,7 +230,9 @@ require (
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.11.0 // indirect
Expand Down
Loading