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

bump initia & adopt ibc-hooks & add missing bridge hook sender check #16

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM golang:1.21-alpine AS go-builder
#ARG arch=x86_64

# See https://github.com/initia-labs/initiavm/releases
ENV LIBINITIAVM_VERSION=v0.2.0-beta.2.1
# See https://github.com/initia-labs/movevm/releases
ENV LIBMOVEVM_VERSION=v0.2.0

# this comes from standard alpine nightly file
# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile
Expand All @@ -20,18 +20,18 @@ COPY . /code/
RUN git clone --depth 1 https://github.com/microsoft/mimalloc; cd mimalloc; mkdir build; cd build; cmake ..; make -j$(nproc); make install
ENV MIMALLOC_RESERVE_HUGE_OS_PAGES=4

# See https://github.com/initia-labs/initiavm/releases
ADD https://github.com/initia-labs/initiavm/releases/download/${LIBINITIAVM_VERSION}/libinitia_muslc.aarch64.a /lib/libinitia_muslc.aarch64.a
ADD https://github.com/initia-labs/initiavm/releases/download/${LIBINITIAVM_VERSION}/libinitia_muslc.x86_64.a /lib/libinitia_muslc.x86_64.a
# See https://github.com/initia-labs/movevm/releases
ADD https://github.com/initia-labs/movevm/releases/download/${LIBMOVEVM_VERSION}/libmovevm_muslc.aarch64.a /lib/libmovevm_muslc.aarch64.a
ADD https://github.com/initia-labs/movevm/releases/download/${LIBMOVEVM_VERSION}/libmovevm_muslc.x86_64.a /lib/libmovevm_muslc.x86_64.a

# Highly recommend to verify the version hash
# RUN sha256sum /lib/libinitia_muslc.aarch64.a | grep a5e63292ec67f5bdefab51b42c3fbc3fa307c6aefeb6b409d971f1df909c3927
# RUN sha256sum /lib/libinitia_muslc.x86_64.a | grep 762307147bf8f550bd5324b7f7c4f17ee20805ff93dc06cc073ffbd909438320
# RUN sha256sum /lib/libmovevm_muslc.aarch64.a | grep a5e63292ec67f5bdefab51b42c3fbc3fa307c6aefeb6b409d971f1df909c3927
# RUN sha256sum /lib/libmovevm_muslc.x86_64.a | grep 762307147bf8f550bd5324b7f7c4f17ee20805ff93dc06cc073ffbd909438320

# Copy the library you want to the final location that will be found by the linker flag `-linitia_muslc`
RUN cp /lib/libinitia_muslc.`uname -m`.a /lib/libinitia_muslc.a
RUN cp /lib/libmovevm_muslc.`uname -m`.a /lib/libmovevm_muslc.a

# force it to use static lib (from above) not standard libinitia.so file
# force it to use static lib (from above) not standard libmovevm.so file
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LDFLAGS="-linkmode=external -extldflags \"-L/code/mimalloc/build -lmimalloc -Wl,-z,muldefs -static\"" make build

FROM alpine:3.15.4
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ build-linux-with-shared-library:
docker build --tag initia/minimove-shared ./ -f ./shared.Dockerfile
docker create --name temp initia/minimove-shared:latest
docker cp temp:/usr/local/bin/minitiad $(BUILDDIR)/
docker cp temp:/lib/libinitia.so $(BUILDDIR)/
docker cp temp:/lib/libmovevm.so $(BUILDDIR)/
docker rm temp

install: go.sum
Expand Down
51 changes: 33 additions & 18 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ import (
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

"github.com/initia-labs/initia/app/params"
ibchooks "github.com/initia-labs/initia/x/ibc-hooks"
ibchookskeeper "github.com/initia-labs/initia/x/ibc-hooks/keeper"
ibcmovehooks "github.com/initia-labs/initia/x/ibc-hooks/move-hooks"
ibchookstypes "github.com/initia-labs/initia/x/ibc-hooks/types"
fetchprice "github.com/initia-labs/initia/x/ibc/fetchprice"
fetchpricekeeper "github.com/initia-labs/initia/x/ibc/fetchprice/keeper"
fetchpricetypes "github.com/initia-labs/initia/x/ibc/fetchprice/types"
Expand All @@ -109,7 +113,6 @@ import (
icaauth "github.com/initia-labs/initia/x/intertx"
icaauthkeeper "github.com/initia-labs/initia/x/intertx/keeper"
icaauthtypes "github.com/initia-labs/initia/x/intertx/types"
moveibcmiddleware "github.com/initia-labs/initia/x/move/ibc-middleware"

authzmodule "github.com/initia-labs/initia/x/authz/module"
"github.com/initia-labs/initia/x/bank"
Expand Down Expand Up @@ -217,6 +220,7 @@ type MinitiaApp struct {
IBCFeeKeeper *ibcfeekeeper.Keeper
MoveKeeper *movekeeper.Keeper
OPChildKeeper *opchildkeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
AuctionKeeper *auctionkeeper.Keeper // x/auction keeper used to process bids for TOB auctions
PacketForwardKeeper *packetforwardkeeper.Keeper
ICQKeeper *icqkeeper.Keeper
Expand Down Expand Up @@ -276,7 +280,7 @@ func NewMinitiaApp(
feegrant.StoreKey, icahosttypes.StoreKey, icacontrollertypes.StoreKey,
icaauthtypes.StoreKey, ibcfeetypes.StoreKey, movetypes.StoreKey, opchildtypes.StoreKey,
auctiontypes.StoreKey, packetforwardtypes.StoreKey, icqtypes.StoreKey,
oracletypes.StoreKey, fetchpricetypes.StoreKey,
oracletypes.StoreKey, fetchpricetypes.StoreKey, ibchookstypes.StoreKey,
)
tkeys := storetypes.NewTransientStoreKeys()
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -360,7 +364,7 @@ func NewMinitiaApp(
runtime.NewKVStoreService(keys[opchildtypes.StoreKey]),
app.AccountKeeper,
app.BankKeeper,
apphook.NewMoveBridgeHook(app.MoveKeeper).Hook,
apphook.NewMoveBridgeHook(ac, app.MoveKeeper).Hook,
app.MsgServiceRouter(),
authorityAddr,
vc,
Expand Down Expand Up @@ -435,6 +439,13 @@ func NewMinitiaApp(
)
app.IBCFeeKeeper = &ibcFeeKeeper

app.IBCHooksKeeper = ibchookskeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[ibchookstypes.StoreKey]),
authorityAddr,
ac,
)

///////////////////////////
// Transfer configuration //
////////////////////////////
Expand Down Expand Up @@ -485,19 +496,20 @@ func NewMinitiaApp(
)

// create move middleware for transfer
moveMiddleware := moveibcmiddleware.NewIBCMiddleware(
hookMiddleware := ibchooks.NewIBCMiddleware(
// receive: move -> packet forward -> transfer
packetForwardMiddleware,
// ics4wrapper: not used
nil,
app.MoveKeeper,
ac,
ibchooks.NewICS4Middleware(
nil, /* ics4wrapper: not used */
ibcmovehooks.NewMoveHooks(app.MoveKeeper, ac),
),
app.IBCHooksKeeper,
)

// create ibcfee middleware for transfer
transferStack = ibcfee.NewIBCMiddleware(
// receive: fee -> move -> packet forward -> transfer
moveMiddleware,
hookMiddleware,
// ics4wrapper: transfer -> packet forward -> fee -> channel
*app.IBCFeeKeeper,
)
Expand All @@ -524,19 +536,20 @@ func NewMinitiaApp(
)
nftTransferIBCModule := ibcnfttransfer.NewIBCModule(*app.NftTransferKeeper)

// create move middleware for nft transfer
moveMiddleware := moveibcmiddleware.NewIBCMiddleware(
// receive: move -> nft transfer
// create move middleware for nft-transfer
hookMiddleware := ibchooks.NewIBCMiddleware(
// receive: move -> nft-transfer
nftTransferIBCModule,
// ics4wrapper: not used
nil,
app.MoveKeeper,
ac,
ibchooks.NewICS4Middleware(
nil, /* ics4wrapper: not used */
ibcmovehooks.NewMoveHooks(app.MoveKeeper, ac),
),
app.IBCHooksKeeper,
)

nftTransferStack = ibcfee.NewIBCMiddleware(
// receive: channel -> fee -> move -> nft transfer
moveMiddleware,
hookMiddleware,
*app.IBCFeeKeeper,
)
}
Expand Down Expand Up @@ -666,6 +679,7 @@ func NewMinitiaApp(
app.BankKeeper,
app.OracleKeeper,
app.BaseApp.MsgServiceRouter(),
app.BaseApp.GRPCQueryRouter(),
moveConfig,
// staking feature
nil, // placeholder for distribution keeper
Expand Down Expand Up @@ -725,6 +739,7 @@ func NewMinitiaApp(
packetforward.NewAppModule(app.PacketForwardKeeper, nil),
icq.NewAppModule(*app.ICQKeeper, nil),
fetchprice.NewAppModule(appCodec, *app.FetchPriceKeeper),
ibchooks.NewAppModule(appCodec, *app.IBCHooksKeeper),
// slinky modules
oracle.NewAppModule(appCodec, *app.OracleKeeper),
)
Expand Down Expand Up @@ -776,7 +791,7 @@ func NewMinitiaApp(
upgradetypes.ModuleName, feegrant.ModuleName, consensusparamtypes.ModuleName, ibcexported.ModuleName,
ibctransfertypes.ModuleName, ibcnfttransfertypes.ModuleName, icatypes.ModuleName, icaauthtypes.ModuleName,
ibcfeetypes.ModuleName, consensusparamtypes.ModuleName, auctiontypes.ModuleName, oracletypes.ModuleName,
packetforwardtypes.ModuleName, icqtypes.ModuleName, fetchpricetypes.ModuleName,
packetforwardtypes.ModuleName, icqtypes.ModuleName, fetchpricetypes.ModuleName, ibchookstypes.ModuleName,
}

app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
Expand Down
2 changes: 1 addition & 1 deletion app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
movetypes "github.com/initia-labs/initia/x/move/types"
"github.com/initia-labs/initiavm/precompile"
"github.com/initia-labs/movevm/precompile"

auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"
)
Expand Down
23 changes: 18 additions & 5 deletions app/hook/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,43 @@ package hook
import (
"context"
"encoding/json"
"strings"

"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

movekeeper "github.com/initia-labs/initia/x/move/keeper"
movetypes "github.com/initia-labs/initia/x/move/types"
)

// bridge hook implementation for move
type MoveBridgeHook struct {
ac address.Codec
moveKeeper *movekeeper.Keeper
}

func NewMoveBridgeHook(moveKeeper *movekeeper.Keeper) MoveBridgeHook {
return MoveBridgeHook{moveKeeper}
func NewMoveBridgeHook(ac address.Codec, moveKeeper *movekeeper.Keeper) MoveBridgeHook {
return MoveBridgeHook{ac, moveKeeper}
}

func (mbh MoveBridgeHook) Hook(ctx context.Context, sender sdk.AccAddress, msgBytes []byte) error {
msg := movetypes.MsgExecute{}
err := json.Unmarshal(msgBytes, &msg)
var msg movetypes.MsgExecute
decoder := json.NewDecoder(strings.NewReader(string(msgBytes)))
decoder.DisallowUnknownFields()
err := decoder.Decode(&msg)
if err != nil {
return err
}

ms := movekeeper.NewMsgServerImpl(*mbh.moveKeeper)
senderAddr, err := mbh.ac.StringToBytes(msg.Sender)
if err != nil {
return err
} else if !sender.Equals(sdk.AccAddress(senderAddr)) {
return sdkerrors.ErrUnauthorized
}

ms := movekeeper.NewMsgServerImpl(mbh.moveKeeper)
_, err = ms.Execute(ctx, &msg)

return err
Expand Down
42 changes: 1 addition & 41 deletions app/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,52 +1,12 @@
package app

import (
"context"

storetypes "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types"
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v8/types"
oracletypes "github.com/skip-mev/slinky/x/oracle/types"

fetchpricetypes "github.com/initia-labs/initia/x/ibc/fetchprice/types"
)

const upgradeName = "0.2.0-beta.6"
// const upgradeName = "0.2.0-beta.6"

// RegisterUpgradeHandlers returns upgrade handlers
func (app *MinitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) {
app.UpgradeKeeper.SetUpgradeHandler(
upgradeName,
func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {

// remove fetchprice ibc module from version map
delete(vm, fetchpricetypes.ModuleName)

return app.ModuleManager.RunMigrations(ctx, app.configurator, vm)
},
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
fetchpricetypes.StoreKey,
packetforwardtypes.StoreKey,
icqtypes.StoreKey,
oracletypes.StoreKey,
},
Deleted: []string{
"fetchpriceconsumer",
},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
Loading
Loading