Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: blocked addrs #210

Merged
merged 6 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
"golang.org/x/exp/maps"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
Expand Down Expand Up @@ -878,7 +879,7 @@ func NewInitiaApp(
authzmodule.NewAppModule(appCodec, *app.AuthzKeeper, app.interfaceRegistry),
groupmodule.NewAppModule(appCodec, *app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
consensus.NewAppModule(appCodec, *app.ConsensusParamsKeeper),
move.NewAppModule(appCodec, *app.MoveKeeper, vc),
move.NewAppModule(appCodec, *app.MoveKeeper, vc, maps.Keys(maccPerms)),
auction.NewAppModule(app.appCodec, *app.AuctionKeeper),
ophost.NewAppModule(appCodec, *app.OPHostKeeper),
// slinky modules
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,6 @@ github.com/initia-labs/cosmos-sdk v0.0.0-20240425031032-6bc18cf6e67d h1:8OCL+PBo
github.com/initia-labs/cosmos-sdk v0.0.0-20240425031032-6bc18cf6e67d/go.mod h1:lVkRY6cdMJ0fG3gp8y4hFrsKZqF4z7y0M2UXFb9Yt40=
github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e h1:1gkMWkAgVhYFhEv7K4tX+8uJJLdiTKlQhl5+wGaxdMg=
github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM=
github.com/initia-labs/movevm v0.3.1 h1:vydw0mdqsLyPN9W2DVq1/gDXDR3snbr6c4Wy/sTYVxY=
github.com/initia-labs/movevm v0.3.1/go.mod h1:6MxR4GP5zH3JUc1IMgfqAe1e483mZVS7fshPknZPJ30=
github.com/jhump/protoreflect v1.15.3 h1:6SFRuqU45u9hIZPJAoZ8c28T3nK64BNdp9w6jFonzls=
github.com/jhump/protoreflect v1.15.3/go.mod h1:4ORHmSBmlCW8fh3xHmJMGyul1zNqZK4Elxc8qKP+p1k=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
7 changes: 4 additions & 3 deletions x/move/keeper/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewApi(k Keeper, ctx context.Context) GoApi {
}

// GetAccountInfo return account info (account number, sequence)
func (api GoApi) GetAccountInfo(addr vmtypes.AccountAddress) (bool /* found */, uint64 /* account number */, uint64 /* sequence */, uint8 /* account_type */) {
func (api GoApi) GetAccountInfo(addr vmtypes.AccountAddress) (bool /* found */, uint64 /* account number */, uint64 /* sequence */, uint8 /* account_type */, bool /* is_blocked */) {
sdkAddr := types.ConvertVMAddressToSDKAddress(addr)
if api.authKeeper.HasAccount(api.ctx, sdkAddr) {
acc := api.authKeeper.GetAccount(api.ctx, sdkAddr)
Expand All @@ -47,10 +47,11 @@ func (api GoApi) GetAccountInfo(addr vmtypes.AccountAddress) (bool /* found */,
accType = vmtypes.AccountType_Module
}

return true, acc.GetAccountNumber(), acc.GetSequence(), accType
isBlocked := api.bankKeeper.BlockedAddr(sdkAddr)
return true, acc.GetAccountNumber(), acc.GetSequence(), accType, isBlocked
}

return false, 0, 0, 0
return false, 0, 0, 0, false
}

// AmountToShare convert amount to share
Expand Down
13 changes: 8 additions & 5 deletions x/move/keeper/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ func Test_GetAccountInfo(t *testing.T) {

// base account
input.AccountKeeper.SetAccount(ctx, input.AccountKeeper.NewAccountWithAddress(ctx, addrs[0]))
found, accountNumber, sequence, accountType := api.GetAccountInfo(vmaddr)
found, accountNumber, sequence, accountType, isBlocked := api.GetAccountInfo(vmaddr)
require.True(t, found)
require.False(t, isBlocked)

acc := input.AccountKeeper.GetAccount(ctx, addrs[0])
require.Equal(t, acc.GetAccountNumber(), accountNumber)
Expand All @@ -45,8 +46,9 @@ func Test_GetAccountInfo(t *testing.T) {
govAddr := govAcc.GetAddress()
govVmAddr, err := vmtypes.NewAccountAddressFromBytes(govAddr.Bytes())
require.NoError(t, err)
found, accountNumber, sequence, accountType = api.GetAccountInfo(govVmAddr)
found, accountNumber, sequence, accountType, isBlocked = api.GetAccountInfo(govVmAddr)
require.True(t, found)
require.True(t, isBlocked)

acc = input.AccountKeeper.GetAccount(ctx, govAddr)
require.Equal(t, acc.GetAccountNumber(), accountNumber)
Expand All @@ -57,8 +59,9 @@ func Test_GetAccountInfo(t *testing.T) {
vmaddr, err = vmtypes.NewAccountAddress("0x3")
require.NoError(t, err)

found, _, _, _ = api.GetAccountInfo(vmaddr)
found, _, _, _, isBlocked = api.GetAccountInfo(vmaddr)
require.False(t, found)
require.False(t, isBlocked)
}

func Test_CreateTypedAccounts(t *testing.T) {
Expand All @@ -70,7 +73,7 @@ func Test_CreateTypedAccounts(t *testing.T) {
api := keeper.NewApi(input.MoveKeeper, ctx)

input.AccountKeeper.SetAccount(ctx, input.AccountKeeper.NewAccountWithAddress(ctx, addrs[0]))
found, accountNumber, sequence, accountType := api.GetAccountInfo(vmaddr)
found, accountNumber, sequence, accountType, _ := api.GetAccountInfo(vmaddr)
require.True(t, found)

acc := input.AccountKeeper.GetAccount(ctx, addrs[0])
Expand All @@ -81,7 +84,7 @@ func Test_CreateTypedAccounts(t *testing.T) {
vmaddr, err = vmtypes.NewAccountAddress("0x3")
require.NoError(t, err)

found, _, _, _ = api.GetAccountInfo(vmaddr)
found, _, _, _, _ = api.GetAccountInfo(vmaddr)
require.False(t, found)
}

Expand Down
9 changes: 5 additions & 4 deletions x/move/keeper/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (k MoveBankKeeper) MintCoins(
vmtypes.StdAddress,
vmtypes.StdAddress,
types.MoveModuleNameManagedCoin,
types.FunctionNameManagedCoinMint,
types.FunctionNameManagedCoinSudoMint,
[]vmtypes.TypeTag{},
[][]byte{recipientAddr[:], metadata[:], amountBz},
)
Expand Down Expand Up @@ -520,13 +520,14 @@ func (k MoveBankKeeper) SendCoin(
return err
}

return k.ExecuteEntryFunction(
return k.executeEntryFunction(
ctx,
fromVmAddr,
[]vmtypes.AccountAddress{vmtypes.StdAddress, fromVmAddr},
vmtypes.StdAddress,
types.MoveModuleNameCoin,
types.FunctionNameCoinTransfer,
types.FunctionNameCoinSudoTransfer,
[]vmtypes.TypeTag{},
[][]byte{toVmAddr[:], metadata[:], amountBz},
false,
)
}
9 changes: 7 additions & 2 deletions x/move/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"sort"

sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -57,8 +58,12 @@ func (k Keeper) Initialize(
}

// InitGenesis sets supply information for genesis.
func (k Keeper) InitGenesis(ctx context.Context, genState types.GenesisState) error {
k.authKeeper.GetModuleAccount(ctx, types.MoveStakingModuleName)
func (k Keeper) InitGenesis(ctx context.Context, moduleNames []string, genState types.GenesisState) error {
// create all module addresses
sort.StringSlice(moduleNames).Sort()
for _, moduleName := range moduleNames {
k.authKeeper.GetModuleAccount(ctx, moduleName)
}
Comment on lines +61 to +66
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The search did not reveal any validation logic for moduleNames before they are used in the InitGenesis function. This indicates a potential issue with the code.

  • Ensure that moduleNames are properly validated before use to avoid potential errors from malformed names.

Category:

Analysis chain

The InitGenesis function has been modified to accept a moduleNames parameter which is sorted and used to retrieve module accounts. Ensure that the moduleNames are properly validated before use to avoid potential errors from malformed names.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that moduleNames are validated before being used in InitGenesis.

# Test: Search for validation logic related to moduleNames.
rg --type go $'moduleNames' -A 10 | grep 'validate'

Length of output: 48



Script:

#!/bin/bash
# Description: Check for validation logic for moduleNames in the entire codebase.

# Search for validation function definitions and usages related to moduleNames.
rg --type go 'func validate' -A 10
rg --type go 'validate(moduleNames)'

Length of output: 14551


params := genState.GetParams()
if err := k.SetRawParams(ctx, params.ToRaw()); err != nil {
Expand Down
10 changes: 7 additions & 3 deletions x/move/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry)
// AppModule implements an application module for the move module.
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
vc address.Codec

keeper keeper.Keeper
vc address.Codec
moduleNames []string
}

// IsAppModule implements the appmodule.AppModule interface.
Expand All @@ -111,11 +113,13 @@ func NewAppModule(
cdc codec.Codec,
k keeper.Keeper,
vc address.Codec,
moduleNames []string,
) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc},
keeper: k,
vc: vc,
moduleNames: moduleNames,
}
}

Expand All @@ -133,7 +137,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.
var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)

if err := am.keeper.InitGenesis(ctx, genesisState); err != nil {
if err := am.keeper.InitGenesis(ctx, am.moduleNames, genesisState); err != nil {
panic(err)
}
}
Expand Down
11 changes: 6 additions & 5 deletions x/move/types/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (

// function names for managed_coin
FunctionNameManagedCoinInitialize = "initialize"
FunctionNameManagedCoinMint = "mint"
FunctionNameManagedCoinSudoMint = "sudo_mint"
FunctionNameManagedCoinBurn = "burn"

// function names for simple_nft
Expand All @@ -37,10 +37,11 @@ const (
FunctionNameSimpleNftBurn = "burn"

// function names for coin
FunctionNameCoinBalance = "balance"
FunctionNameCoinRegister = "register"
FunctionNameCoinTransfer = "transfer"
FunctionNameCoinWhitelist = "whitelist"
FunctionNameCoinBalance = "balance"
FunctionNameCoinRegister = "register"
FunctionNameCoinTransfer = "transfer"
FunctionNameCoinSudoTransfer = "sudo_transfer"
FunctionNameCoinWhitelist = "whitelist"
Comment on lines +40 to +44
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The context around the identified lines in both x/move/types/connector.go and benchmark/app_test.go shows that FunctionNameCoinTransfer is still defined and used. This indicates that the renaming to FunctionNameCoinSudoTransfer might be incomplete or inconsistent.

  • x/move/types/connector.go (line 42): FunctionNameCoinTransfer is defined alongside FunctionNameCoinSudoTransfer.
  • benchmark/app_test.go (line 147): FunctionNameCoinTransfer is used in a test case.

This confirms that the renaming process has not been fully propagated across the codebase.

  • x/move/types/connector.go: Line 42
  • benchmark/app_test.go: Line 147

Please ensure that all instances of FunctionNameCoinTransfer are updated to FunctionNameCoinSudoTransfer where appropriate to maintain consistency.

Analysis chain

Ensure consistency in function naming conventions.

The renaming of FunctionNameCoinTransfer to FunctionNameCoinSudoTransfer suggests a similar elevation in privilege requirements as seen with the managed coin functions. Confirm that all related function calls across the codebase have been updated to reflect these changes.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check for consistent usage of renamed coin functions.

# Test: Search for old function names to ensure they are no longer used.
rg --type go $'FunctionNameCoinTransfer'

Length of output: 183



Script:

#!/bin/bash
# Check the context and usage of FunctionNameCoinTransfer in the identified files.

# Extract relevant lines from x/move/types/connector.go
rg --type go --line-number 'FunctionNameCoinTransfer' x/move/types/connector.go

# Extract relevant lines from benchmark/app_test.go
rg --type go --line-number 'FunctionNameCoinTransfer' benchmark/app_test.go

Length of output: 258



Script:

#!/bin/bash
# Extract surrounding lines for context in the identified files.

# Extract lines around the definition in x/move/types/connector.go
rg --type go --context 5 --line-number 'FunctionNameCoinTransfer' x/move/types/connector.go

# Extract lines around the usage in benchmark/app_test.go
rg --type go --context 5 --line-number 'FunctionNameCoinTransfer' benchmark/app_test.go

Length of output: 1039


// function names for staking
FunctionNameStakingInitialize = "initialize_for_chain"
Expand Down
Loading