Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4eee7ce
Dev/resharing (#1)
vj3t May 19, 2025
d731d2a
Adds MPC party package
vietddude Jun 6, 2025
fd70149
Refactors MPC party handling into sessions
vietddude Jun 9, 2025
d53a2bd
Refactor MPC package to use node-based architecture
vietddude Jun 10, 2025
78fb104
Refactor signing and event consumer logic for improved clarity
vietddude Jun 11, 2025
7837f90
Refactor event handling and session management in MPC package
vietddude Jun 11, 2025
89eefc6
Implement signing result event handling and add save data methods
vietddude Jun 11, 2025
aa4f3d3
Refactor signature verification in event consumer and session management
vietddude Jun 11, 2025
0e45e35
Update docker-compose and refactor event topics and key path
vietddude Jun 11, 2025
7d9fd5e
Enhance MPC session management and event handling
vietddude Jun 11, 2025
fc0877f
Enhance save data handling in ECDSA and EDDSA parties
vietddude Jun 12, 2025
7c65005
Implement resharing event handling and enhance session management
vietddude Jun 12, 2025
e6fadeb
Enhance logging and save data management in resharing process
vietddude Jun 12, 2025
89b4246
Refactor party ID handling and enhance session message logging
vietddude Jun 12, 2025
0220505
Enhance version management and session handling in MPC package
vietddude Jun 13, 2025
3eb7289
Refactor container names and improve event consumer error handling
vietddude Jun 13, 2025
0627e59
Integrate Viper configuration and update NATS URL handling
vietddude Jun 13, 2025
e1666da
Refactor session initialization and error handling in MPC package
vietddude Jun 13, 2025
6c3de00
Add Close method to Node and defer its call in runNode
vietddude Jun 13, 2025
057d990
Implement PreloadPreParams method and refactor party ID handling
vietddude Jun 13, 2025
81840aa
Refactor key info version handling in event consumer and node
vietddude Jun 14, 2025
2916a71
Update key version for backward compatibility
vietddude Jun 15, 2025
9c3161f
Refactor event handling and message classification in MPC package
vietddude Jun 16, 2025
2a62b9e
Refactor Listen method in session interface and event consumer
vietddude Jun 16, 2025
3494150
Refactor key generation event handling in event consumer
vietddude Jun 16, 2025
52f2438
Implement Close method for PartyInterface and Session to manage resou…
vietddude Jun 17, 2025
8b340fa
Update GetSaveData method to accept party version for improved data m…
vietddude Jun 17, 2025
5dd1082
Improve format, rename finish -> onComplete
anhthii Jun 26, 2025
cda8da2
Rename PartyInterface -> Party
anhthii Jun 26, 2025
5945f8f
Experimental refactoring
anhthii Jun 26, 2025
05c9053
Add tsslimiter queue
anhthii Jun 26, 2025
8d79d1c
Update gen request using jetstream
Poseidon-G Jun 24, 2025
c0f9a11
Refactor key retrieval in GetSaveData method and adjust key generatio…
vietddude Jun 18, 2025
aeb1249
Fix concurrency issue
anhthii Jun 26, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ identity/
event_initiator.identity.json
event_initiator.key
event_initiator.key.age
config.yaml
peers.json
11 changes: 11 additions & 0 deletions Makefile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.PHONY: clean new

clean:
@# only kill the window if it exists
@if tmux list-windows -F "#{window_name}" \
| grep -qw "^mpcium$$"; then \
tmux kill-window -t mpcium; \
fi

new: clean
@tmuxifier load-window mpcium
16 changes: 16 additions & 0 deletions clean_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Directories to clean under
nodes=("node0" "node1" "node2")

for dir in "${nodes[@]}"; do
identity_dir="$dir"
echo "Cleaning .txt files in $identity_dir..."
if [ -d "$identity_dir" ]; then
find "$identity_dir" -type f -name "*.txt" -print -delete
else
echo "Directory $identity_dir not found"
fi
done

echo "✅ Cleanup complete."
23 changes: 19 additions & 4 deletions cmd/mpcium/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/fystack/mpcium/pkg/kvstore"
"github.com/fystack/mpcium/pkg/logger"
"github.com/fystack/mpcium/pkg/messaging"
"github.com/fystack/mpcium/pkg/mpc"
"github.com/fystack/mpcium/pkg/mpc/node"
"github.com/hashicorp/consul/api"
"github.com/nats-io/nats.go"
"github.com/spf13/viper"
Expand Down Expand Up @@ -132,35 +132,44 @@ func runNode(ctx context.Context, c *cli.Command) error {
mqManager := messaging.NewNATsMessageQueueManager("mpc", []string{
"mpc.mpc_keygen_success.*",
event.SigningResultTopic,
"mpc.mpc_resharing_success.*",
}, natsConn)

genkeyRequestQueue := mqManager.NewMessagePullSubscriber("mpc_keygen_request")
defer genkeyRequestQueue.Close()
genKeySuccessQueue := mqManager.NewMessageQueue("mpc_keygen_success")
defer genKeySuccessQueue.Close()
singingResultQueue := mqManager.NewMessageQueue("signing_result")
defer singingResultQueue.Close()
resharingResultQueue := mqManager.NewMessageQueue("mpc_resharing_success")
defer resharingResultQueue.Close()

logger.Info("Node is running", "peerID", nodeID, "name", nodeName)

peerNodeIDs := GetPeerIDs(peers)
peerRegistry := mpc.NewRegistry(nodeID, peerNodeIDs, consulClient.KV())
peerRegistry := node.NewRegistry(nodeID, peerNodeIDs, consulClient.KV())

mpcNode := mpc.NewNode(
mpcNode := node.NewNode(
nodeID,
peerNodeIDs,
pubsub,
directMessaging,
badgerKV,
keyinfoStore,
peerRegistry,
identityStore,
peerRegistry,
consulClient.KV(),
)
// Preload preparams for the first time
mpcNode.PreloadPreParams()
defer mpcNode.Close()

eventConsumer := eventconsumer.NewEventConsumer(
mpcNode,
pubsub,
genKeySuccessQueue,
singingResultQueue,
resharingResultQueue,
identityStore,
)
eventConsumer.Run()
Expand All @@ -174,6 +183,7 @@ func runNode(ctx context.Context, c *cli.Command) error {
timeoutConsumer.Run()
defer timeoutConsumer.Close()
signingConsumer := eventconsumer.NewSigningConsumer(natsConn, signingStream, pubsub)
keygenConsumer := eventconsumer.NewKeygenConsumer(natsConn, genkeyRequestQueue, pubsub)

// Make the node ready before starting the signing consumer
peerRegistry.Ready()
Expand All @@ -188,6 +198,11 @@ func runNode(ctx context.Context, c *cli.Command) error {
cancel()
}()

fmt.Print("Run keygen consumer")
if err := keygenConsumer.Run(appContext); err != nil {
logger.Error("error running keygen consumer:", err)
}

if err := signingConsumer.Run(appContext); err != nil {
logger.Error("error running consumer:", err)
}
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3"

services:
nats-server:
image: nats:latest
Expand Down
30 changes: 23 additions & 7 deletions examples/generate/main.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
package main

import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"time"

"github.com/fystack/mpcium/pkg/client"
"github.com/fystack/mpcium/pkg/config"
"github.com/fystack/mpcium/pkg/event"
"github.com/fystack/mpcium/pkg/logger"
"github.com/fystack/mpcium/pkg/mpc"
"github.com/google/uuid"
"github.com/nats-io/nats.go"
"github.com/spf13/viper"
)

func main() {
const environment = "development"

// Parse the -n flag
numWallets := flag.Int("n", 1, "Number of wallets to generate")
flag.Parse()

config.InitViperConfig()
logger.Init(environment, false)

Expand All @@ -25,25 +32,34 @@ func main() {
if err != nil {
logger.Fatal("Failed to connect to NATS", err)
}
defer natsConn.Drain() // drain inflight msgs
defer natsConn.Drain()
defer natsConn.Close()

mpcClient := client.NewMPCClient(client.Options{
NatsConn: natsConn,
KeyPath: "./event_initiator.key",
})
err = mpcClient.OnWalletCreationResult(func(event mpc.KeygenSuccessEvent) {

err = mpcClient.OnWalletCreationResult(func(event event.KeygenSuccessEvent) {
logger.Info("Received wallet creation result", "event", event)
})
if err != nil {
logger.Fatal("Failed to subscribe to wallet-creation results", err)
}

walletID := uuid.New().String()
if err := mpcClient.CreateWallet(walletID); err != nil {
logger.Fatal("CreateWallet failed", err)
for i := 0; i < *numWallets; i++ {
walletID := uuid.New().String()
if err := mpcClient.CreateWallet(walletID); err != nil {
logger.Error("CreateWallet failed", err)
continue
}
time.Sleep(100 * time.Millisecond)
logger.Info("CreateWallet sent", "walletID", walletID)
}
logger.Info("CreateWallet sent, awaiting result...", "walletID", walletID)

logger.Info("All CreateWallet requests sent, awaiting results...")

// Wait for shutdown signal
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
<-stop
Expand Down
52 changes: 52 additions & 0 deletions examples/reshare/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"fmt"
"os"
"os/signal"
"syscall"

"github.com/fystack/mpcium/pkg/client"
"github.com/fystack/mpcium/pkg/config"
"github.com/fystack/mpcium/pkg/event"
"github.com/fystack/mpcium/pkg/logger"
"github.com/fystack/mpcium/pkg/types"
"github.com/nats-io/nats.go"
"github.com/spf13/viper"
)

func main() {
const environment = "development"
config.InitViperConfig()
logger.Init(environment, false)

natsURL := viper.GetString("nats.url")
natsConn, err := nats.Connect(natsURL)
if err != nil {
logger.Fatal("Failed to connect to NATS", err)
}
defer natsConn.Drain() // drain inflight msgs
defer natsConn.Close()

mpcClient := client.NewMPCClient(client.Options{
NatsConn: natsConn,
KeyPath: "./event_initiator.key",
})
err = mpcClient.OnResharingResult(func(event event.ResharingSuccessEvent) {
logger.Info("Received resharing result", "event", event)
})
if err != nil {
logger.Fatal("Failed to subscribe to resharing results", err)
}

walletID := "892122fd-f2f4-46dc-be25-6fd0b83dff60"
if err := mpcClient.Resharing(walletID, 2, types.KeyTypeSecp256k1); err != nil {
logger.Fatal("Resharing failed", err)
}
logger.Info("Resharing sent, awaiting result...", "walletID", walletID)
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
<-stop

fmt.Println("Shutting down.")
}
6 changes: 3 additions & 3 deletions examples/sign/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ func main() {
dummyTx := []byte("deadbeef") // replace with real transaction bytes

txMsg := &types.SignTxMessage{
KeyType: types.KeyTypeEd25519,
WalletID: "77dd7e23-9d5c-4ff1-8759-f119d1b19b36",
NetworkInternalCode: "solana-devnet",
KeyType: types.KeyTypeSecp256k1,
WalletID: "9af13a60-9aa9-4069-ba3f-bd6d821c8905",
NetworkInternalCode: "ethereum-sepolia",
TxID: txID,
Tx: dummyTx,
}
Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ require (
github.com/bnb-chain/tss-lib/v2 v2.0.2
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3
github.com/dgraph-io/badger/v4 v4.2.0
github.com/golang/protobuf v1.5.4
github.com/google/uuid v1.6.0
github.com/hashicorp/consul/api v1.26.1
github.com/mitchellh/mapstructure v1.5.0
github.com/nats-io/nats.go v1.31.0
github.com/nats-io/nats.go v1.43.0
github.com/rs/zerolog v1.31.0
github.com/samber/lo v1.39.0
github.com/spf13/viper v1.18.0
github.com/stretchr/testify v1.10.0
github.com/urfave/cli/v3 v3.3.2
go.uber.org/mock v0.3.0
golang.org/x/term v0.31.0
google.golang.org/protobuf v1.36.6
)

require (
Expand All @@ -40,7 +41,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.4 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/go-cmp v0.7.0 // indirect
Expand All @@ -56,12 +56,12 @@ require (
github.com/hashicorp/serf v0.10.1 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-log/v2 v2.1.3 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/nats-io/nkeys v0.4.6 // indirect
github.com/nats-io/nkeys v0.4.11 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/otiai10/primes v0.0.0-20210501021515-f1b2be525a11 // indirect
Expand All @@ -86,7 +86,6 @@ require (
golang.org/x/net v0.39.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -256,10 +256,10 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nats-io/nats.go v1.31.0 h1:/WFBHEc/dOKBF6qf1TZhrdEfTmOZ5JzdJ+Y3m6Y/p7E=
github.com/nats-io/nats.go v1.31.0/go.mod h1:di3Bm5MLsoB4Bx61CBTsxuarI36WbhAwOm8QrW39+i8=
github.com/nats-io/nkeys v0.4.6 h1:IzVe95ru2CT6ta874rt9saQRkWfe2nFj1NtvYSLqMzY=
github.com/nats-io/nkeys v0.4.6/go.mod h1:4DxZNzenSVd1cYQoAa8948QY3QDjrHfcfVADymtkpts=
github.com/nats-io/nats.go v1.43.0 h1:uRFZ2FEoRvP64+UUhaTokyS18XBCR/xM2vQZKO4i8ug=
github.com/nats-io/nats.go v1.43.0/go.mod h1:iRWIPokVIFbVijxuMQq4y9ttaBTMe0SFdlZfMDd+33g=
github.com/nats-io/nkeys v0.4.11 h1:q44qGV008kYd9W1b1nEBkNzvnWxtRSQ7A8BoqRrcfa0=
github.com/nats-io/nkeys v0.4.11/go.mod h1:szDimtgmfOi9n25JpfIdGw12tZFYXqhGxjhVxsatHVE=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down Expand Up @@ -373,8 +373,6 @@ go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo=
go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
Expand Down
Loading