Skip to content

Commit

Permalink
Merge pull request #7 from FairBlock/audit
Browse files Browse the repository at this point in the history
non-breaking changes for code review
  • Loading branch information
p0p3yee authored May 28, 2023
2 parents eb9edd1 + d2ddaa4 commit 4659717
Show file tree
Hide file tree
Showing 313 changed files with 10,963 additions and 12,345 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ build/
gentx/
DistributedIBE/
*.json
encrypter
encrypter
ShareGenerator
data/
5 changes: 0 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
FROM --platform=$BUILDPLATFORM golang:1.20-bullseye AS build-env

WORKDIR /src/app/fairyring/DistributedIBE
COPY DistributedIBE/go.mod DistributedIBE/go.sum ./
RUN go mod download
COPY . .

WORKDIR /src/app/fairyring
COPY go.mod go.sum ./
RUN go mod download
Expand Down
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,33 @@ sync-docs:
aws cloudfront create-invalidation --distribution-id ${CF_DISTRIBUTION_ID} --profile terraform --path "/*" ;
.PHONY: sync-docs

###############################################################################
### Integration Tests ###
###############################################################################

integration-test-all: init-test-framework \
test-keyshare-module \
test-pep-module
-@rm -rf ./data
-@killall fairyringd 2>/dev/null

test-keyshare-module:
@echo "Testing KeyShare module..."
./scripts/tests/keyshare.sh

test-pep-module:
@echo "Testing Pep module..."
./scripts/tests/pep.sh

init-test-framework: clean-testing-data install
@echo "Initializing fairyring..."
./scripts/tests/start.sh
@sleep 3

clean-testing-data:
@echo "Killing fairyringd and removing previous data"
-@rm -rf ./data
-@killall fairyringd 2>/dev/null
###############################################################################
### Tests & Simulation ###
###############################################################################
Expand Down
98 changes: 51 additions & 47 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ import (
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

fairblockmodule "fairyring/x/fairblock"
fairblockmodulekeeper "fairyring/x/fairblock/keeper"
fairblockmoduletypes "fairyring/x/fairblock/types"
fairyringmodule "fairyring/x/fairyring"
fairyringmodulekeeper "fairyring/x/fairyring/keeper"
fairyringmoduletypes "fairyring/x/fairyring/types"
keysharemodule "fairyring/x/keyshare"
keysharemodulekeeper "fairyring/x/keyshare/keeper"
keysharemoduletypes "fairyring/x/keyshare/types"
pepmodule "fairyring/x/pep"
pepmodulekeeper "fairyring/x/pep/keeper"
pepmoduletypes "fairyring/x/pep/types"

// this line is used by starport scaffolding # stargate/app/moduleImport

appparams "fairyring/app/params"
Expand Down Expand Up @@ -168,8 +169,8 @@ var (
transfer.AppModuleBasic{},
ica.AppModuleBasic{},
vesting.AppModuleBasic{},
fairyringmodule.AppModuleBasic{},
fairblockmodule.AppModuleBasic{},
keysharemodule.AppModuleBasic{},
pepmodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand Down Expand Up @@ -242,10 +243,10 @@ type App struct {
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedPepKeeper capabilitykeeper.ScopedKeeper

FairyringKeeper fairyringmodulekeeper.Keeper
ScopedFairblockKeeper capabilitykeeper.ScopedKeeper
FairblockKeeper fairblockmodulekeeper.Keeper
KeyshareKeeper keysharemodulekeeper.Keeper
PepKeeper pepmodulekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

// mm is the module manager
Expand Down Expand Up @@ -290,8 +291,8 @@ func New(
paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey,
ibctransfertypes.StoreKey, icahosttypes.StoreKey, capabilitytypes.StoreKey, group.StoreKey,
icacontrollertypes.StoreKey,
fairyringmoduletypes.StoreKey,
fairblockmoduletypes.StoreKey,
keysharemoduletypes.StoreKey,
pepmoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -330,6 +331,8 @@ func New(
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedPepKeeper := app.CapabilityKeeper.ScopeToModule(pepmoduletypes.ModuleName)

// this line is used by starport scaffolding # stargate/app/scopedKeeper

// add keepers
Expand Down Expand Up @@ -509,38 +512,37 @@ func New(
govConfig,
)

app.FairyringKeeper = *fairyringmodulekeeper.NewKeeper(
appCodec,
keys[fairyringmoduletypes.StoreKey],
keys[fairyringmoduletypes.MemStoreKey],
app.GetSubspace(fairyringmoduletypes.ModuleName),
app.StakingKeeper,
)
fairyringModule := fairyringmodule.NewAppModule(
appCodec,
app.FairyringKeeper,
app.AccountKeeper,
app.BankKeeper,
)

scopedFairblockKeeper := app.CapabilityKeeper.ScopeToModule(fairblockmoduletypes.ModuleName)
app.ScopedFairblockKeeper = scopedFairblockKeeper
app.FairblockKeeper = *fairblockmodulekeeper.NewKeeper(
app.PepKeeper = *pepmodulekeeper.NewKeeper(
appCodec,
keys[fairblockmoduletypes.StoreKey],
keys[fairblockmoduletypes.MemStoreKey],
app.GetSubspace(fairblockmoduletypes.ModuleName),
keys[pepmoduletypes.StoreKey],
keys[pepmoduletypes.MemStoreKey],
app.GetSubspace(pepmoduletypes.ModuleName),
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
scopedPepKeeper,
)
fairblockModule := fairblockmodule.NewAppModule(
pepModule := pepmodule.NewAppModule(
appCodec,

app.FairblockKeeper,
app.PepKeeper,
app.AccountKeeper,
app.BankKeeper,
app.MsgServiceRouter(),
encodingConfig.TxConfig,
)

pepIBCModule := pepmodule.NewIBCModule(app.PepKeeper)

app.KeyshareKeeper = *keysharemodulekeeper.NewKeeper(
appCodec,
keys[keysharemoduletypes.StoreKey],
keys[keysharemoduletypes.MemStoreKey],
app.GetSubspace(keysharemoduletypes.ModuleName),
app.PepKeeper,
stakingKeeper,
)
keyshareModule := keysharemodule.NewAppModule(appCodec, app.KeyshareKeeper, app.AccountKeeper, app.BankKeeper, app.PepKeeper)

// this line is used by starport scaffolding # stargate/app/keeperDefinition

// Sealing prevents other modules from creating scoped sub-keepers
Expand All @@ -550,6 +552,7 @@ func New(
ibcRouter := ibcporttypes.NewRouter()
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
ibcRouter.AddRoute(pepmoduletypes.ModuleName, pepIBCModule)

// this line is used by starport scaffolding # ibc/app/router
app.IBCKeeper.SetRouter(ibcRouter)
Expand Down Expand Up @@ -587,8 +590,8 @@ func New(
params.NewAppModule(app.ParamsKeeper),
transferModule,
icaModule,
fairyringModule,
fairblockModule,
keyshareModule,
pepModule,
// this line is used by starport scaffolding # stargate/app/appModule
)

Expand Down Expand Up @@ -618,8 +621,8 @@ func New(
group.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
fairyringmoduletypes.ModuleName,
fairblockmoduletypes.ModuleName,
keysharemoduletypes.ModuleName, // Necessary to run before begin blocker of pep module
pepmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)

Expand All @@ -644,8 +647,8 @@ func New(
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
fairyringmoduletypes.ModuleName,
fairblockmoduletypes.ModuleName,
keysharemoduletypes.ModuleName,
pepmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
)

Expand Down Expand Up @@ -675,8 +678,8 @@ func New(
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
fairyringmoduletypes.ModuleName,
fairblockmoduletypes.ModuleName,
keysharemoduletypes.ModuleName,
pepmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
)

Expand Down Expand Up @@ -706,8 +709,8 @@ func New(
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
transferModule,
fairyringModule,
fairblockModule,
keyshareModule,
pepModule,
// this line is used by starport scaffolding # stargate/app/appModule
)
app.sm.RegisterStoreDecoders()
Expand Down Expand Up @@ -747,6 +750,7 @@ func New(

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.ScopedPepKeeper = scopedPepKeeper
// this line is used by starport scaffolding # stargate/app/beforeInitReturn

return app
Expand Down Expand Up @@ -906,8 +910,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(fairyringmoduletypes.ModuleName)
paramsKeeper.Subspace(fairblockmoduletypes.ModuleName)
paramsKeeper.Subspace(keysharemoduletypes.ModuleName)
paramsKeeper.Subspace(pepmoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down
29 changes: 3 additions & 26 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,19 @@
package app_test

import (
"os"
"testing"
"time"

"fairyring/app"
"github.com/cosmos/cosmos-sdk/simapp"
simulationtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"

"fairyring/app"
"os"
"testing"
)

func init() {
simapp.GetSimulatorFlags()
}

var defaultConsensusParams = &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: 200000,
MaxGas: 2000000,
},
Evidence: &tmproto.EvidenceParams{
MaxAgeNumBlocks: 302400,
MaxAgeDuration: 504 * time.Hour, // 3 weeks is the max duration
MaxBytes: 10000,
},
Validator: &tmproto.ValidatorParams{
PubKeyTypes: []string{
tmtypes.ABCIPubKeyTypeEd25519,
},
},
}

// BenchmarkSimulation run the chain simulation
// Running using starport command:
// `starport chain simulate -v --numBlocks 200 --blockSize 50`
Expand Down
2 changes: 1 addition & 1 deletion cmd/fairyringd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) {
set := func(s *pflag.FlagSet, key, val string) {
if f := s.Lookup(key); f != nil {
f.DefValue = val
f.Value.Set(val)
_ = f.Value.Set(val)
}
}
for key, val := range defaults {
Expand Down
6 changes: 6 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ client:
faucet:
name: bob
coins: ["5token", "100000stake"]
genesis:
app_state:
keyshare:
params:
trusted_addresses: ["cosmos18hl5c9xn5dze2g50uaw0l2mr02ew57zk2fgr8q"]
key_expiry: 200
29 changes: 0 additions & 29 deletions create_multi_sign_account.sh

This file was deleted.

6 changes: 4 additions & 2 deletions destination.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ accounts:
- name: alice
coins:
- 1000token
- 1000000000stake
- 2000000000stake
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"
- name: bob
coins:
- 500token
- 100000000stake
- 200000000stake
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"
faucet:
name: bob
coins:
Expand Down
17 changes: 17 additions & 0 deletions docs/fairy_core/integration/01_overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Overview

This section deals with integrating any chain with FairyRing chain. A chain that leverages the IBE functionality of FairyRing for encrypting, decrypting and executing transactions (the Destination Chain). All Destination Chains require the following to leverage the FairyRing functionalities:

1. A module to store encrypted transactions and queue them based on their target height. The module should also have the functionality to decrypt and execute said transactions when the target height is reached.
2. A functionality to fetch generated aggregated keyshares fast and reliably from the FairyRing chain. These aggrgated keyshares act as the decryption key for the encrypted transactions.

All encrypted transactions are executed on the destination chain itself. The target height for execution is that of the Fairyring chain. This is necessary since aggregated keyshares are generated per block of FairyRing and does not have any bearing with the height of the destination chain(s).

For now, the same aggregated keyshare generated by FairyRing is used by all the destination chains to decrypt their transactions. This is subject to channge, where a set of aggregated keyshares may be generated by FairyRing and destination chains may require one or more of these to decrypt their transactions.

To make integration easier for destination chains, FairBlock provides solutions to both the requirements:

1. The PEP module: Destination chains can simply use the readymade PEP module (also used by the FairyRing chain). The module comes with all the required functionalities, namely a transaction to accept encrypted transactions submitted by users, a queue to store the encrypted transactions indexed by their target height, fetch and store pubkeys from FairyRing via IBC, verify a received aggregated keyshare on-chain as well as an automated decryption and execution system for the encrypted transactions.
2. FairyPort : FairyPort is an ad-hoc solution to the problem of fetching aggregated keyshares from the FairyRing chain in a fast and reliable manner. It's a relayer-like off-chain service which compromises on the authenticity of the data fetched for speed. The key to the success of FairyPort is the fact that aggregated keyshares are verified on-chain by the destination chains, allowing for the meaningful sacrifice.

>NOTE: It is not necessary for destination chains to utilize the solutions provided by FairyRing. They can opt for more customized proprietory solutions. They can still integrate with the FairyRing chain as long as the requirements are met. This section goes into the details of the requirements and also the steps required to integrate the already provided solutions.
Loading

0 comments on commit 4659717

Please sign in to comment.