Skip to content

Commit

Permalink
Bounty v2 (#786)
Browse files Browse the repository at this point in the history
* add bounty module

---------

Co-authored-by: yoongbok lee <[email protected]>
Co-authored-by: Xiuming Dou <[email protected]>
Co-authored-by: yuhonghai <[email protected]>
Co-authored-by: Xu Yang <[email protected]>
Co-authored-by: haozhan9 <[email protected]>
Co-authored-by: 0311xuyang <[email protected]>
  • Loading branch information
7 people authored Nov 17, 2023
1 parent 11baca2 commit 9a881da
Show file tree
Hide file tree
Showing 60 changed files with 17,528 additions and 673 deletions.
22 changes: 20 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ import (
authkeeper "github.com/shentufoundation/shentu/v2/x/auth/keeper"
"github.com/shentufoundation/shentu/v2/x/bank"
bankkeeper "github.com/shentufoundation/shentu/v2/x/bank/keeper"
"github.com/shentufoundation/shentu/v2/x/bounty"
bountykeeper "github.com/shentufoundation/shentu/v2/x/bounty/keeper"
bountytypes "github.com/shentufoundation/shentu/v2/x/bounty/types"
"github.com/shentufoundation/shentu/v2/x/cert"
certclient "github.com/shentufoundation/shentu/v2/x/cert/client"
certkeeper "github.com/shentufoundation/shentu/v2/x/cert/keeper"
Expand Down Expand Up @@ -165,6 +168,7 @@ var (
ibc.AppModuleBasic{},
transfer.AppModuleBasic{},
ica.AppModuleBasic{},
bounty.AppModuleBasic{},
)

// module account permissions
Expand All @@ -180,6 +184,7 @@ var (
shieldtypes.ModuleName: {authtypes.Burner},
cvmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
bountytypes.ModuleName: {authtypes.Burner},
}
)

Expand Down Expand Up @@ -219,6 +224,7 @@ type ShentuApp struct {
CVMKeeper cvmkeeper.Keeper
OracleKeeper oraclekeeper.Keeper
ShieldKeeper shieldkeeper.Keeper
BountyKeeper bountykeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -268,6 +274,7 @@ func NewShentuApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
ibctransfertypes.StoreKey,
icahosttypes.StoreKey,
capabilitytypes.StoreKey,
bountytypes.StoreKey,
}

keys := sdk.NewKVStoreKeys(ks...)
Expand Down Expand Up @@ -397,6 +404,13 @@ func NewShentuApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
&app.GovKeeper,
app.GetSubspace(shieldtypes.ModuleName),
)
app.BountyKeeper = bountykeeper.NewKeeper(
appCodec,
keys[bountytypes.StoreKey],
app.CertKeeper,
app.GetSubspace(bountytypes.ModuleName),
)

app.MintKeeper = mintkeeper.NewKeeper(
appCodec, keys[sdkminttypes.StoreKey], app.GetSubspace(sdkminttypes.ModuleName), &stakingKeeper,
app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.ShieldKeeper, authtypes.FeeCollectorName,
Expand Down Expand Up @@ -504,6 +518,7 @@ func NewShentuApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
params.NewAppModule(app.ParamsKeeper),
transferModule,
icaModule,
bounty.NewAppModule(app.BountyKeeper),
)

// NOTE: During BeginBlocker, slashing comes after distr so that
Expand All @@ -513,7 +528,7 @@ func NewShentuApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
slashingtypes.ModuleName, evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, ibctransfertypes.ModuleName,
icatypes.ModuleName, authtypes.ModuleName, sdkbanktypes.ModuleName, sdkgovtypes.ModuleName, genutiltypes.ModuleName,
sdkauthz.ModuleName, sdkfeegrant.ModuleName, crisistypes.ModuleName, shieldtypes.ModuleName, certtypes.ModuleName,
oracletypes.ModuleName, cvmtypes.ModuleName, paramstypes.ModuleName,
oracletypes.ModuleName, cvmtypes.ModuleName, paramstypes.ModuleName, bountytypes.ModuleName,
)

// NOTE: Shield endblocker comes before staking because it queries
Expand All @@ -522,7 +537,7 @@ func NewShentuApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
capabilitytypes.ModuleName, authtypes.ModuleName, sdkbanktypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
sdkminttypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, sdkauthz.ModuleName, sdkfeegrant.ModuleName,
paramstypes.ModuleName, upgradetypes.ModuleName, ibchost.ModuleName, ibctransfertypes.ModuleName, icatypes.ModuleName,
certtypes.ModuleName, oracletypes.ModuleName, cvmtypes.ModuleName,
certtypes.ModuleName, oracletypes.ModuleName, cvmtypes.ModuleName, bountytypes.ModuleName,
)

// NOTE: genutil moodule must occur after staking so that pools
Expand Down Expand Up @@ -550,6 +565,7 @@ func NewShentuApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
sdkfeegrant.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
bountytypes.ModuleName,
)

app.mm.SetOrderExportGenesis(
Expand All @@ -575,6 +591,7 @@ func NewShentuApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
evidencetypes.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
bountytypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -602,6 +619,7 @@ func NewShentuApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
shield.NewAppModule(app.ShieldKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
ibc.NewAppModule(app.IBCKeeper),
transferModule,
bounty.NewAppModule(app.BountyKeeper),
)

app.sm.RegisterStoreDecoders()
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.3
github.com/golangci/golangci-lint v1.50.1
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hyperledger/burrow v0.31.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
Expand Down
136 changes: 136 additions & 0 deletions proto/shentu/bounty/v1/bounty.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
syntax = "proto3";
package shentu.bounty.v1;

import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "google/protobuf/any.proto";

option go_package = "github.com/shentufoundation/shentu/x/bounty/types";

message Program {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string program_id = 1 [(gogoproto.moretags) = "yaml:\"program_id\""];
string name = 2 [(gogoproto.moretags) = "yaml:\"name\""];
// JSON by ProgramDetail
string detail = 3 [(gogoproto.moretags) = "yaml:\"detail\""];
string admin_address = 4 [(gogoproto.moretags) = "yaml:\"admin_address\""];
ProgramStatus status = 5 [(gogoproto.moretags) = "yaml:\"status\""];
google.protobuf.Timestamp create_time = 6
[(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"create_time\""];
}

message Finding {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string program_id = 1 [(gogoproto.moretags) = "yaml:\"program_id\""];
string finding_id = 2 [(gogoproto.moretags) = "yaml:\"finding_id\""];
string title = 3;
string description = 4 [(gogoproto.moretags) = "yaml:\"description\""];
string proof_of_concept = 5 [(gogoproto.moretags) = "yaml:\"proof_of_concept\""];
// hash(description + proof_of_concept + submitter)
string finding_hash = 6 [(gogoproto.moretags) = "yaml:\"finding_hash\""];
string submitter_address = 7 [(gogoproto.moretags) = "yaml:\"submitter_address\""];
SeverityLevel severity_level = 8 [(gogoproto.moretags) = "yaml:\"severity_level\""];
FindingStatus status = 9 [(gogoproto.moretags) = "yaml:\"status\""];
// JSON by FindingDetail
string detail = 10 [(gogoproto.moretags) = "yaml:\"detail\""];
string payment_hash = 11 [(gogoproto.moretags) = "yaml:\"payment_hash\""];
google.protobuf.Timestamp create_time = 12
[(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"create_time\""];
}

message ProgramFingerprint {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string program_id = 1 [(gogoproto.jsontag) = "id", (gogoproto.moretags) = "yaml:\"id\""];
string name = 2 [(gogoproto.moretags) = "yaml:\"name\""];
// JSON by ProgramDetail
string detail = 3 [(gogoproto.moretags) = "yaml:\"detail\""];
string admin_address = 4 [(gogoproto.moretags) = "yaml:\"admin_address\""];
ProgramStatus status = 5 [(gogoproto.moretags) = "yaml:\"status\""];
}

message FindingFingerprint {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string program_id = 1 [(gogoproto.moretags) = "yaml:\"program_id\""];
string finding_id = 2 [(gogoproto.jsontag) = "id", (gogoproto.moretags) = "yaml:\"id\""];
string title = 3;
// hash(description + proof_of_concept + submitter)
string finding_hash = 4 [(gogoproto.moretags) = "yaml:\"finding_hash\""];
SeverityLevel severity_level = 5 [(gogoproto.moretags) = "yaml:\"severity_level\""];
FindingStatus status = 6 [(gogoproto.moretags) = "yaml:\"status\""];
// JSON by FindingDetail
string detail = 7 [(gogoproto.moretags) = "yaml:\"detail\""];
string payment_hash = 8 [(gogoproto.moretags) = "yaml:\"payment_hash\""];
}

enum ProgramStatus {
option (gogoproto.goproto_enum_prefix) = false;

PROGRAM_STATUS_INACTIVE = 0 [(gogoproto.enumvalue_customname) = "ProgramStatusInactive"];
PROGRAM_STATUS_ACTIVE = 1 [(gogoproto.enumvalue_customname) = "ProgramStatusActive"];
PROGRAM_STATUS_CLOSED = 2 [(gogoproto.enumvalue_customname) = "ProgramStatusClosed"];
}

enum SeverityLevel {
option (gogoproto.goproto_enum_prefix) = false;

SEVERITY_LEVEL_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "Unspecified"];
SEVERITY_LEVEL_CRITICAL = 1 [(gogoproto.enumvalue_customname) = "Critical"];
SEVERITY_LEVEL_HIGH = 2 [(gogoproto.enumvalue_customname) = "High"];
SEVERITY_LEVEL_MEDIUM = 3 [(gogoproto.enumvalue_customname) = "Medium"];
SEVERITY_LEVEL_LOW = 4 [(gogoproto.enumvalue_customname) = "Low"];
SEVERITY_LEVEL_INFORMATIONAL = 5 [(gogoproto.enumvalue_customname) = "Informational"];
}

enum FindingStatus {
option (gogoproto.goproto_enum_prefix) = false;

FINDING_STATUS_SUBMITTED = 0 [(gogoproto.enumvalue_customname) = "FindingStatusSubmitted"];
FINDING_STATUS_ACTIVE = 1 [(gogoproto.enumvalue_customname) = "FindingStatusActive"];
FINDING_STATUS_CONFIRMED = 2 [(gogoproto.enumvalue_customname) = "FindingStatusConfirmed"];
FINDING_STATUS_PAID = 3 [(gogoproto.enumvalue_customname) = "FindingStatusPaid"];
FINDING_STATUS_CLOSED = 4 [(gogoproto.enumvalue_customname) = "FindingStatusClosed"];
}

//message BountyLevel {
// option (gogoproto.equal) = false;
// option (gogoproto.goproto_getters) = false;
//
// SeverityLevel severity_level = 1 [(gogoproto.moretags) = "yaml:\"severity_level\""];
// bool poc = 2;
// cosmos.base.v1beta1.Coin min_bounty = 3 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"min_bounty\""];
// cosmos.base.v1beta1.Coin max_bounty = 4 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"max_bounty\""];
//}

//// ProgramDetail defines a program detail.
//type ProgramDetail struct {
// Type string `json:"type"`
// Logo string `json:"logo"`
// Desc string `json:"desc"`
// Targets []string `json:"targets"`
// ScopeRules string `json:"scope_rules"`
// KnownIssues string `json:"known_issues"`
// TotalBounty int `json:"total_bounty"`
// BountyLevels []BountyLevel `json:"bounty_levels"`
// PaymentInfo string `json:"payment_info"`
// PaymentChain string `json:"payment_chain"`
// ProgramSLA []SLAItem `json:"sla"`
//}

//// FindingDetail defines a finding detail.
//type FindingDetail struct{
// ProgramTarget []string `json:"program_target"`
// Impacts []string `json:"impacts"`
// Attachments []string `json:"attachments"`
// ReceiverInfo ReceiverInfo `json:"receiver_info"`
// PaidInfo PaidInfo `json:"paid_info"`
//}
16 changes: 16 additions & 0 deletions proto/shentu/bounty/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";
package shentu.bounty.v1;

import "gogoproto/gogo.proto";

import "shentu/bounty/v1/bounty.proto";

option go_package = "github.com/shentufoundation/shentu/x/bounty/types";

message GenesisState {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

repeated Program programs = 1 [(gogoproto.moretags) = "yaml:\"programs\"", (gogoproto.nullable) = false];
repeated Finding findings = 2 [(gogoproto.moretags) = "yaml:\"findings\"", (gogoproto.nullable) = false];
}
Loading

0 comments on commit 9a881da

Please sign in to comment.