Skip to content

Commit

Permalink
x/protocols wasm plus revert allowlist
Browse files Browse the repository at this point in the history
  • Loading branch information
trevormil committed Jan 15, 2024
1 parent 36d6038 commit 549b791
Show file tree
Hide file tree
Showing 28 changed files with 810 additions and 274 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func New(
}

customEncoderOptions := GetCustomMsgEncodersOptions()
customQueryOptions := GetCustomMsgQueryOptions(app.BadgesKeeper)
customQueryOptions := GetCustomMsgQueryOptions(app.BadgesKeeper, app.ProtocolsKeeper)
wasmOpts := append(customEncoderOptions, customQueryOptions...)
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,bitbadges"

Expand Down
25 changes: 22 additions & 3 deletions app/wasm_custom_bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ import (
wasmKeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
badgeCustomBindings "github.com/bitbadges/bitbadgeschain/x/badges/custom-bindings"
badgeKeeper "github.com/bitbadges/bitbadgeschain/x/badges/keeper"

protocolCustomBindings "github.com/bitbadges/bitbadgeschain/x/protocols/custom-bindings"
protocolKeeper "github.com/bitbadges/bitbadgeschain/x/protocols/keeper"
)

func GetCustomMsgEncodersOptions() []wasmKeeper.Option {
badgeEncodingOptions := wasmKeeper.WithMessageEncoders(badgeMsgEncoders())
return []wasm.Option{badgeEncodingOptions}
protocolEncodingOptions := wasmKeeper.WithMessageEncoders(protocolMsgEncoders())
return []wasm.Option{badgeEncodingOptions, protocolEncodingOptions}
}

func GetCustomMsgQueryOptions(keeper badgeKeeper.Keeper) []wasmKeeper.Option {
func GetCustomMsgQueryOptions(keeper badgeKeeper.Keeper, keeper2 protocolKeeper.Keeper) []wasmKeeper.Option {
badgeQueryOptions := wasmKeeper.WithQueryPlugins(badgeQueryPlugins(keeper))
return []wasm.Option{badgeQueryOptions}
protocolQueryOptions := wasmKeeper.WithQueryPlugins(protocolQueryPlugins(keeper2))
return []wasm.Option{badgeQueryOptions, protocolQueryOptions}
}

func badgeMsgEncoders() *wasmKeeper.MessageEncoders {
Expand All @@ -29,3 +34,17 @@ func badgeQueryPlugins(keeper badgeKeeper.Keeper) *wasmKeeper.QueryPlugins {
Custom: badgeCustomBindings.PerformCustomBadgeQuery(keeper),
}
}


func protocolMsgEncoders() *wasmKeeper.MessageEncoders {
return &wasmKeeper.MessageEncoders{
Custom: protocolCustomBindings.EncodeProtocolMessage(),
}
}

// protocolQueryPlugins needs to be registered in test setup to handle custom query callbacks
func protocolQueryPlugins(keeper protocolKeeper.Keeper) *wasmKeeper.QueryPlugins {
return &wasmKeeper.QueryPlugins{
Custom: protocolCustomBindings.PerformCustomProtocolQuery(keeper),
}
}
2 changes: 1 addition & 1 deletion chain-handlers/ethereum/ethereum/eip712/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func CreateEIP712Domain(chainID uint64) apitypes.TypedDataDomain {
Name: "BitBadges",
Version: "1.0.0",
ChainId: math.NewHexOrDecimal256(int64(chainID)),
VerifyingContract: "0x1a16c87927570239fecd343ad2654fd81682725e",
VerifyingContract: "0xa607FcD07cfe8d84cA839e4D6EdEE4B1A6789603",
Salt: "0x5d1e2c0e9b8a5c395979525d5f6d5f0c595d5a5c5e5e5b5d5ecd5a5e5d2e5412",
}

Expand Down
2 changes: 1 addition & 1 deletion chain-handlers/ethereum/ethereum/eip712/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func GetSchemas() []string {
{
"listId": "",
"addresses": [],
"allowlist": false,
"whitelist": false,
"uri": "",
"customData": "",
"createdBy": "",
Expand Down
4 changes: 2 additions & 2 deletions proto/badges/address_lists.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ option go_package = "github.com/bitbadges/bitbadgeschain/x/badges/types";
/*
An AddressList is a list of addresses that are referenced by an ID.
The list may include only the specified addresses, or it may include all addresses but
the specified addresses (depending on if allowlist is true (allowlist) or false (blocklist)).
the specified addresses (depending on if whitelist is true (whitelist) or false (blacklist)).
AddressLists are used for defining approvals, as well as being a simplified badge interface.
*/
Expand All @@ -23,7 +23,7 @@ message AddressList {
repeated string addresses = 2;

// Indicates whether the list includes the specified addresses (true) or excludes them (false).
bool allowlist = 3;
bool whitelist = 3;

// URI (Uniform Resource Identifier) associated with the address list to provide metadata, if applicable.
string uri = 4;
Expand Down
2 changes: 1 addition & 1 deletion proto/badges/transfers.proto
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ message MerkleChallenge {
// The expected length of the Merkle path for verification. Used to prevent Merkle path truncation attacks.
string expectedProofLength = 2 [(gogoproto.customtype) = "Uint", (gogoproto.nullable) = false];

// If true, we will override the user's leaf for their proof with their creator address. Used for allowlist trees where all leaves are valid Cosmos addresses.
// If true, we will override the user's leaf for their proof with their creator address. Used for whitelist trees where all leaves are valid Cosmos addresses.
bool useCreatorAddressAsLeaf = 3;

// The maximum number of times each leaf can be used. Must be 1 if useCreatorAddressAsLeaf is false to prevent replay attacks.
Expand Down
16 changes: 0 additions & 16 deletions proto/protocols/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,7 @@ option go_package = "github.com/bitbadges/bitbadgeschain/x/protocols/types";
// Query defines the gRPC querier service.
service Query {

// Parameters queries the parameters of the module.
rpc Params (QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/bitbadges/bitbadgeschain/protocols/params";

}

// Queries a list of GetProtocol items.
rpc GetProtocol (QueryGetProtocolRequest) returns (QueryGetProtocolResponse) {
option (google.api.http).get = "/bitbadges/bitbadgeschain/protocols/get_protocol";

}

// Queries a list of GetCollectionIdForProtocol items.
rpc GetCollectionIdForProtocol (QueryGetCollectionIdForProtocolRequest) returns (QueryGetCollectionIdForProtocolResponse) {
option (google.api.http).get = "/bitbadges/bitbadgeschain/protocols/get_collection_id_for_protocol";

}
}
// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}
Expand Down
9 changes: 9 additions & 0 deletions proto/protocols/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ service Msg {
rpc UnsetCollectionForProtocol (MsgUnsetCollectionForProtocol) returns (MsgUnsetCollectionForProtocolResponse);
}

//Used for WASM bindings and JSON parsing
message ProtocolCustomMsgType {
MsgCreateProtocol createProtocolMsg = 1;
MsgUpdateProtocol updateProtocolMsg = 2;
MsgDeleteProtocol deleteProtocolMsg = 3;
MsgSetCollectionForProtocol setCollectionForProtocolMsg = 4;
MsgUnsetCollectionForProtocol unsetCollectionForProtocolMsg = 5;
}

message Protocol {
string name = 1;
string uri = 2;
Expand Down
22 changes: 11 additions & 11 deletions x/badges/keeper/address_lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func getReservedListById(addressListId string, allowAliases bool) (*types.Addres
addressList = &types.AddressList{
ListId: "Mint",
Addresses: []string{"Mint"},
Allowlist: true,
Whitelist: true,
Uri: "",
CustomData: "",
}
Expand All @@ -83,7 +83,7 @@ func getReservedListById(addressListId string, allowAliases bool) (*types.Addres
addressList = &types.AddressList{
ListId: addressListId,
Addresses: []string{},
Allowlist: false,
Whitelist: false,
Uri: "",
CustomData: "",
}
Expand All @@ -103,7 +103,7 @@ func getReservedListById(addressListId string, allowAliases bool) (*types.Addres
addressList = &types.AddressList{
ListId: "All",
Addresses: []string{},
Allowlist: false,
Whitelist: false,
Uri: "",
CustomData: "",
}
Expand All @@ -112,7 +112,7 @@ func getReservedListById(addressListId string, allowAliases bool) (*types.Addres
addressList = &types.AddressList{
ListId: "AllWithMint",
Addresses: []string{},
Allowlist: false,
Whitelist: false,
Uri: "",
CustomData: "",
}
Expand All @@ -121,7 +121,7 @@ func getReservedListById(addressListId string, allowAliases bool) (*types.Addres
addressList = &types.AddressList{
ListId: "None",
Addresses: []string{},
Allowlist: true,
Whitelist: true,
Uri: "",
CustomData: "",
}
Expand All @@ -144,7 +144,7 @@ func getReservedListById(addressListId string, allowAliases bool) (*types.Addres
addressList = &types.AddressList{
ListId: addressListId,
Addresses: addresses,
Allowlist: true,
Whitelist: true,
Uri: "",
CustomData: "",
}
Expand Down Expand Up @@ -174,7 +174,7 @@ func (k Keeper) GetTrackerListById(ctx sdk.Context, trackerListId string) (*type
}

if inverted {
addressList.Allowlist = !addressList.Allowlist
addressList.Whitelist = !addressList.Whitelist
}

return addressList, nil
Expand Down Expand Up @@ -208,7 +208,7 @@ func (k Keeper) GetAddressListById(ctx sdk.Context, addressListId string) (*type
}

if inverted {
addressList.Allowlist = !addressList.Allowlist
addressList.Whitelist = !addressList.Whitelist
}

return addressList, nil
Expand All @@ -227,7 +227,7 @@ func (k Keeper) CheckAddresses(ctx sdk.Context, addressListId string, addressToC
}
}

if !addressList.Allowlist {
if !addressList.Whitelist {
found = !found
}

Expand All @@ -239,8 +239,8 @@ func (k Keeper) CheckAddresses(ctx sdk.Context, addressListId string, addressToC
}

// Checks if the addresses are in their respective list.
// If allowlist is true, then we check if the address is in the Addresses field.
// If allowlist is false, then we check if the address is NOT in the Addresses field.
// If whitelist is true, then we check if the address is in the Addresses field.
// If whitelist is false, then we check if the address is NOT in the Addresses field.

// Note addresses matching does not mean the transfer is allowed. It just means the addresses match.
// All other criteria must also be met.
Expand Down
28 changes: 14 additions & 14 deletions x/badges/keeper/address_lists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (suite *TestSuite) TestDuplicateStoreAddressLists() {
// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test",
// Addresses: []string{},
// Allowlist: false,
// Whitelist: false,
// Filters: []*types.AddressListFilters{
// {
// MustSatisfyMinX: sdkmath.NewUint(1),
Expand All @@ -164,7 +164,7 @@ func (suite *TestSuite) TestDuplicateStoreAddressLists() {
// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test",
// Addresses: []string{},
// Allowlist: false,
// Whitelist: false,
// Filters: []*types.AddressListFilters{
// {
// MustSatisfyMinX: sdkmath.NewUint(1),
Expand Down Expand Up @@ -197,7 +197,7 @@ func (suite *TestSuite) TestDuplicateStoreAddressLists() {
// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test",
// Addresses: []string{},
// Allowlist: false,
// Whitelist: false,
// Filters: []*types.AddressListFilters{
// {
// MustSatisfyMinX: sdkmath.NewUint(1),
Expand All @@ -214,7 +214,7 @@ func (suite *TestSuite) TestDuplicateStoreAddressLists() {
// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test2",
// Addresses: []string{},
// Allowlist: false,
// Whitelist: false,
// Filters: []*types.AddressListFilters{
// {
// MustSatisfyMinX: sdkmath.NewUint(1),
Expand All @@ -231,7 +231,7 @@ func (suite *TestSuite) TestDuplicateStoreAddressLists() {
// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test3",
// Addresses: []string{},
// Allowlist: false,
// Whitelist: false,
// Filters: []*types.AddressListFilters{
// {
// MustSatisfyMinX: sdkmath.NewUint(1),
Expand Down Expand Up @@ -262,7 +262,7 @@ func (suite *TestSuite) TestDuplicateStoreAddressLists() {
// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test",
// Addresses: []string{},
// Allowlist: false,
// Whitelist: false,
// Filters: []*types.AddressListFilters{
// {
// MustSatisfyMinX: sdkmath.NewUint(1),
Expand All @@ -279,7 +279,7 @@ func (suite *TestSuite) TestDuplicateStoreAddressLists() {
// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test2",
// Addresses: []string{},
// Allowlist: false,
// Whitelist: false,
// Filters: []*types.AddressListFilters{
// {
// MustSatisfyMinX: sdkmath.NewUint(1),
Expand All @@ -296,7 +296,7 @@ func (suite *TestSuite) TestDuplicateStoreAddressLists() {
// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test3",
// Addresses: []string{},
// Allowlist: false,
// Whitelist: false,
// Filters: []*types.AddressListFilters{
// {
// MustSatisfyMinX: sdkmath.NewUint(1),
Expand Down Expand Up @@ -327,14 +327,14 @@ func (suite *TestSuite) TestDuplicateStoreAddressLists() {
// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test",
// Addresses: []string{alice},
// Allowlist: true,
// Whitelist: true,
// })
// suite.Require().Nil(err, "Error creating address list: %s", "test")

// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test3",
// Addresses: []string{},
// Allowlist: false,
// Whitelist: false,
// Filters: []*types.AddressListFilters{
// {
// MustSatisfyMinX: sdkmath.NewUint(1),
Expand All @@ -351,7 +351,7 @@ func (suite *TestSuite) TestDuplicateStoreAddressLists() {
// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "mustnot",
// Addresses: []string{},
// Allowlist: false,
// Whitelist: false,
// Filters: []*types.AddressListFilters{
// {
// MustSatisfyMinX: sdkmath.NewUint(1),
Expand Down Expand Up @@ -392,14 +392,14 @@ func (suite *TestSuite) TestDuplicateStoreAddressLists() {
// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test",
// Addresses: []string{alice},
// Allowlist: true,
// Whitelist: true,
// })
// suite.Require().Nil(err, "Error creating address list: %s", "test")

// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test3",
// Addresses: []string{},
// Allowlist: false,
// Whitelist: false,
// Filters: []*types.AddressListFilters{
// {
// MustSatisfyMinX: sdkmath.NewUint(1),
Expand All @@ -425,7 +425,7 @@ func (suite *TestSuite) TestDuplicateStoreAddressLists() {
// err = suite.app.BadgesKeeper.CreateAddressList(suite.ctx, &types.AddressList{
// ListId: "test3",
// Addresses: []string{},
// Allowlist: false,
// Whitelist: false,
// Filters: []*types.AddressListFilters{
// {
// MustSatisfyMinX: sdkmath.NewUint(1),
Expand Down
4 changes: 2 additions & 2 deletions x/badges/keeper/challenges.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (k Keeper) AssertValidSolutionForEveryChallenge(ctx sdk.Context, collection
hasValidSolution := false
errStr := ""
if challenge.UseCreatorAddressAsLeaf {
errStr = "does not satisfy allowlist"
errStr = "does not satisfy whitelist"
} else {
errStr = "invalid code / password"
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func CheckMerklePath(leaf string, expectedRoot string, aunts []*types.MerklePath

func GetLeafIndex(aunts []*types.MerklePathItem) sdkmath.Uint {
leafIndex := sdkmath.NewUint(1)
//iterate through msg.AllowlistProof.Aunts backwards
//iterate through msg.WhitelistProof.Aunts backwards
for i := len(aunts) - 1; i >= 0; i-- {
aunt := aunts[i]
onRight := aunt.OnRight
Expand Down
1 change: 1 addition & 0 deletions x/badges/keeper/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func ConstructUsedClaimDataKey(collectionId sdkmath.Uint, claimId sdkmath.Uint)

func ConstructUsedClaimChallengeKey(collectionId sdkmath.Uint, addressForChallenge string, challengeLevel string, challengeId string, codeLeafIndex sdkmath.Uint) string {
collection_id_str := collectionId.String()

code_leaf_index_str := codeLeafIndex.String()
challenge_id_str := challengeId
address_for_challenge_str := addressForChallenge
Expand Down
Loading

0 comments on commit 549b791

Please sign in to comment.