Skip to content

Commit 9253867

Browse files
committed
minor changes
1 parent 7150c47 commit 9253867

File tree

9 files changed

+224
-176
lines changed

9 files changed

+224
-176
lines changed

blockbuster/lanes/base/mempool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ func NewDefaultMempool(txEncoder sdk.TxEncoder) *DefaultMempool {
5353
}
5454
}
5555

56-
// Insert inserts a transaction into the mempool based on the transaction type (normal or auction).
56+
// Insert inserts a transaction into the mempool based on the transaction type (normal or keyshare).
5757
func (am *DefaultMempool) Insert(ctx context.Context, tx sdk.Tx) error {
5858
if err := am.index.Insert(ctx, tx); err != nil {
59-
return fmt.Errorf("failed to insert tx into auction index: %w", err)
59+
return fmt.Errorf("failed to insert tx into keyshare index: %w", err)
6060
}
6161

6262
_, txHashStr, err := utils.GetTxHashStr(am.txEncoder, tx)
@@ -69,7 +69,7 @@ func (am *DefaultMempool) Insert(ctx context.Context, tx sdk.Tx) error {
6969
return nil
7070
}
7171

72-
// Remove removes a transaction from the mempool based on the transaction type (normal or auction).
72+
// Remove removes a transaction from the mempool based on the transaction type (normal or keyshare).
7373
func (am *DefaultMempool) Remove(tx sdk.Tx) error {
7474
am.removeTx(am.index, tx)
7575
return nil

config.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
version: 1
22
accounts:
3-
- name: alice
4-
coins:
5-
- 20000token
6-
- 200000000stake
7-
- name: bob
8-
coins:
9-
- 10000token
10-
- 100000000stake
3+
- name: alice
4+
coins:
5+
- 1000000000token
6+
- 2000000000stake
7+
mnemonic: "thought awake grace need recipe erode bullet dust salt breeze rural desk camp deal devote wisdom rotate pledge repair garbage aspect find lens afraid"
8+
- name: bob
9+
coins:
10+
- 500000000token
11+
- 200000000stake
12+
mnemonic: "south arm eager adjust dish aware rocket logic winter enlist idle reflect slogan urge clump angle input mechanic setup blue distance setup retreat rain"
13+
1114
validators:
1215
- name: alice
1316
bonded: 100000000stake
@@ -28,5 +31,14 @@ genesis:
2831
app_state:
2932
keyshare:
3033
params:
31-
trusted_addresses: ["fairy1yudcuejnt2knsxu0kqc8jzt9nc6t9rs7ujcsg8"]
34+
trusted_addresses: [
35+
"fairy14afvm0yfs27a00hnr85064r69lpg46zjncasuv",
36+
"fairy12hxz66z2tu0lec9cqjf8q4732v8mepffqm4tyl",
37+
]
3238
key_expiry: 200
39+
pep:
40+
params:
41+
trusted_addresses: [
42+
"fairy14afvm0yfs27a00hnr85064r69lpg46zjncasuv",
43+
"fairy12hxz66z2tu0lec9cqjf8q4732v8mepffqm4tyl",
44+
]

docs/static/openapi.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35865,6 +35865,10 @@ paths:
3586535865
type: string
3586635866
channel_id:
3586735867
type: string
35868+
trusted_addresses:
35869+
type: array
35870+
items:
35871+
type: string
3586835872
channel_id:
3586935873
type: string
3587035874
description: >-
@@ -72103,6 +72107,10 @@ definitions:
7210372107
type: string
7210472108
channel_id:
7210572109
type: string
72110+
trusted_addresses:
72111+
type: array
72112+
items:
72113+
type: string
7210672114
channel_id:
7210772115
type: string
7210872116
description: Params defines the parameters for the module.
@@ -72274,6 +72282,10 @@ definitions:
7227472282
type: string
7227572283
channel_id:
7227672284
type: string
72285+
trusted_addresses:
72286+
type: array
72287+
items:
72288+
type: string
7227772289
channel_id:
7227872290
type: string
7227972291
description: QueryParamsResponse is response type for the Query/Params RPC method.

proto/fairyring/pep/params.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ option go_package = "fairyring/x/pep/types";
99
message Params {
1010
option (gogoproto.goproto_stringer) = false;
1111
repeated TrustedCounterParty trusted_counter_parties = 1;
12-
string channel_id = 2;
12+
repeated string trusted_addresses = 2;
13+
string channel_id = 3;
1314
}
1415

1516
message TrustedCounterParty {
Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,110 @@
11
package keeper
22

33
import (
4+
"bytes"
45
"context"
6+
"encoding/hex"
7+
"errors"
58
"fairyring/x/pep/types"
9+
"fmt"
10+
"strconv"
11+
12+
enc "github.com/FairBlock/DistributedIBE/encryption"
13+
sdk "github.com/cosmos/cosmos-sdk/types"
14+
bls "github.com/drand/kyber-bls12381"
615
)
716

817
func (k msgServer) CreateAggregatedKeyShare(goCtx context.Context, msg *types.MsgCreateAggregatedKeyShare) (*types.MsgCreateAggregatedKeyShareResponse, error) {
9-
// No execution of this message is done here.
10-
// Validation and actual execution happens in the beginblock directly from the mempool
18+
ctx := sdk.UnwrapSDKContext(goCtx)
19+
20+
params := k.GetParams(ctx)
21+
var trusted bool = false
22+
23+
for _, trustedAddr := range params.TrustedAddresses {
24+
if trustedAddr == msg.Creator {
25+
trusted = true
26+
break
27+
}
28+
}
29+
30+
if !trusted {
31+
return nil, errors.New("msg not from trusted source")
32+
}
33+
34+
var dummyData = "test data"
35+
var encryptedDataBytes bytes.Buffer
36+
var dummyDataBuffer bytes.Buffer
37+
dummyDataBuffer.Write([]byte(dummyData))
38+
var decryptedDataBytes bytes.Buffer
39+
40+
ak, found := k.GetActivePubKey(ctx)
41+
if !found {
42+
k.Logger(ctx).Error("Active key not found")
43+
return nil, errors.New("active key not found")
44+
}
45+
46+
keyByte, _ := hex.DecodeString(msg.Data)
47+
publicKeyByte, _ := hex.DecodeString(ak.PublicKey)
48+
49+
suite := bls.NewBLS12381Suite()
50+
publicKeyPoint := suite.G1().Point()
51+
if err := publicKeyPoint.UnmarshalBinary(publicKeyByte); err != nil {
52+
return nil, err
53+
}
54+
55+
skPoint := suite.G2().Point()
56+
if err := skPoint.UnmarshalBinary(keyByte); err != nil {
57+
return nil, err
58+
}
59+
60+
processHeightStr := strconv.FormatUint(msg.Height, 10)
61+
if err := enc.Encrypt(publicKeyPoint, []byte(processHeightStr), &encryptedDataBytes, &dummyDataBuffer); err != nil {
62+
return nil, err
63+
}
64+
65+
err := enc.Decrypt(publicKeyPoint, skPoint, &decryptedDataBytes, &encryptedDataBytes)
66+
if err != nil {
67+
k.Logger(ctx).Error("Decryption error when verifying aggregated keyshare")
68+
k.Logger(ctx).Error(err.Error())
69+
ctx.EventManager().EmitEvent(
70+
sdk.NewEvent(types.KeyShareVerificationType,
71+
sdk.NewAttribute(types.KeyShareVerificationCreator, msg.Creator),
72+
sdk.NewAttribute(types.KeyShareVerificationHeight, strconv.FormatUint(msg.Height, 10)),
73+
sdk.NewAttribute(types.KeyShareVerificationReason, err.Error()),
74+
),
75+
)
76+
return nil, err
77+
}
78+
79+
if decryptedDataBytes.String() != dummyData {
80+
k.Logger(ctx).Error("Decrypted data does not match original data")
81+
k.Logger(ctx).Error(err.Error())
82+
ctx.EventManager().EmitEvent(
83+
sdk.NewEvent(types.KeyShareVerificationType,
84+
sdk.NewAttribute(types.KeyShareVerificationCreator, msg.Creator),
85+
sdk.NewAttribute(types.KeyShareVerificationHeight, strconv.FormatUint(msg.Height, 10)),
86+
sdk.NewAttribute(types.KeyShareVerificationReason, "decrypted data does not match original data"),
87+
),
88+
)
89+
return nil, err
90+
}
91+
92+
k.SetAggregatedKeyShare(ctx, types.AggregatedKeyShare{
93+
Height: msg.Height,
94+
Data: msg.Data,
95+
Creator: msg.Creator,
96+
})
97+
98+
latestHeight, err := strconv.ParseUint(k.GetLatestHeight(ctx), 10, 64)
99+
if err != nil {
100+
latestHeight = 0
101+
}
102+
103+
if latestHeight < msg.Height {
104+
k.SetLatestHeight(ctx, strconv.FormatUint(msg.Height, 10))
105+
}
106+
107+
k.Logger(ctx).Info(fmt.Sprintf("[ProcessUnconfirmedTxs] Aggregated Key Added, height: %d", msg.Height))
11108

12109
return &types.MsgCreateAggregatedKeyShareResponse{}, nil
13110
}

x/pep/keeper/unconfirmed_txs.go

Lines changed: 0 additions & 130 deletions
This file was deleted.

x/pep/module.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"fairyring/x/pep/keeper"
2727
"fairyring/x/pep/types"
2828

29-
tmcore "github.com/cometbft/cometbft/rpc/core"
3029
"github.com/cosmos/cosmos-sdk/client"
3130
"github.com/cosmos/cosmos-sdk/codec"
3231
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
@@ -171,17 +170,17 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
171170
lastExecutedHeight = 0
172171
}
173172

174-
utxs, err := tmcore.UnconfirmedTxs(nil, nil)
175-
if err != nil {
176-
am.keeper.Logger(ctx).Error("Error on getting unconfirmed txs")
177-
am.keeper.Logger(ctx).Error(err.Error())
178-
}
179-
if utxs != nil {
180-
if err := am.keeper.ProcessUnconfirmedTxs(ctx, utxs); err != nil {
181-
am.keeper.Logger(ctx).Error("Process unconfirmed txs error")
182-
am.keeper.Logger(ctx).Error(err.Error())
183-
}
184-
}
173+
// utxs, err := tmcore.UnconfirmedTxs(nil, nil)
174+
// if err != nil {
175+
// am.keeper.Logger(ctx).Error("Error on getting unconfirmed txs")
176+
// am.keeper.Logger(ctx).Error(err.Error())
177+
// }
178+
// if utxs != nil {
179+
// if err := am.keeper.ProcessUnconfirmedTxs(ctx, utxs); err != nil {
180+
// am.keeper.Logger(ctx).Error("Process unconfirmed txs error")
181+
// am.keeper.Logger(ctx).Error(err.Error())
182+
// }
183+
// }
185184

186185
strHeight := am.keeper.GetLatestHeight(ctx)
187186
height, err := strconv.ParseUint(strHeight, 10, 64)
@@ -515,7 +514,7 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
515514
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
516515
err := am.keeper.QueryFairyringCurrentKeys(ctx)
517516
if err != nil {
518-
am.keeper.Logger(ctx).Error("Beginblocker get keys err", err)
517+
am.keeper.Logger(ctx).Error("Endblocker get keys err", err)
519518
am.keeper.Logger(ctx).Error(err.Error())
520519
}
521520

0 commit comments

Comments
 (0)