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

prepare initiation-2 upgrade #292

Merged
merged 17 commits into from
Oct 31, 2024
Merged
197 changes: 131 additions & 66 deletions api/initia/intertx/v1/tx.pulsar.go

Large diffs are not rendered by default.

359 changes: 256 additions & 103 deletions api/initia/move/v1/genesis.pulsar.go

Large diffs are not rendered by default.

805 changes: 712 additions & 93 deletions api/initia/move/v1/types.pulsar.go

Large diffs are not rendered by default.

2,044 changes: 2,044 additions & 0 deletions api/initia/tx/v1/query.pulsar.go

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions api/initia/tx/v1/query_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 79 additions & 15 deletions app/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,45 +1,109 @@
package app

import (
"bytes"
"context"
"encoding/base64"
"errors"
"fmt"

"cosmossdk.io/errors"
sdkerrors "cosmossdk.io/errors"
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"

movetypes "github.com/initia-labs/initia/x/move/types"
vmprecompile "github.com/initia-labs/movevm/precompile"
vmtypes "github.com/initia-labs/movevm/types"
)

const upgradeName = "0.5.6"
const upgradeName = "0.6.0"

// RegisterUpgradeHandlers returns upgrade handlers
func (app *InitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) {
app.UpgradeKeeper.SetUpgradeHandler(
upgradeName,
func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// diff: https://github.com/initia-labs/movevm/compare/v0.4.12...v0.5.0
codes := []string{
// cosmos.move
"oRzrCwYAAAALAQAQAhAaAyqXAQTBAQIFwwGQBAfTBZ4FCPEKIAaRCxoQqwt0Cp8MGgy5DPUJAAAACAAPABEAEgAZACgAMAABAwAABQMAAQcHAAIOBwEAA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M4BgwECgQpBAQLBQ0GAgAAAAAAAAAnCwQrBBADCwELAhEZAhoDAAAEBAsACwERGwIcAQQABAgLABEdCwELAwsCCwQ4CQIfAQAABAMLADgKAiEBAAAEBQsACwELAjgLAgUBAAAEBg4ADgERIxQRJAIlAQAABAULAAsBCwIRJgIdAAAABAoLABEnBwAhBAYFCQYBAAAAAAAAABEoJwIpAQAAJC4OABEqBgUAAAAAAAAAJAQSBwEMAQ4BDgAGAAAAAAAAAAAGBQAAAAAAAAARKwwCDgIRIyEMAwUUCQwDCwMEJw4AESoOAAYFAAAAAAAAAAwEDAUMBgsFCwQLBhErDAcOBxEsES0MCAUrBwALABEFDAgLCDgCAi4BAAEEJxQLABAEFAwCDgI4BgwDCgMpBAQLBQ0GAgAAAAAAAAAnCwMrBBAFCwEIES8CMAEAACsKCwALAQsCCwMLBAsFCwYRMQECMQEAADcyDgMRIxQMBwsACwcRMgwIDggMCQoJCwELAgsDCwQLBQsGETMKCRE0CgkRNQoJETYKCRE3DAoOCgwAEgQMDgsACw4tBAoJETgSAjgMCgk4DQwPCg8SBQoPEgALDxIDCwkROwI8AQAABAMLACkEAj0BAAAEBQsACwERBSkEAj4BAAA7Ng4AOAYMAQoAEQcLAAcAOA4MAwwECwMEFgoEDAUHAhFADAYLBQsGIQwDBRgJDAMLAwQeBwMRQAwEBR4HAAoEEQUKASEEJgsEAgcBEUAMBw4BOA8MCA4IEUINBwwJDAQLCQsEEUMLBwJEAQABBCcUCwAQBBQMAg4COAYMAwoDKQQECwUNBgIAAAAAAAAAJwsDKwQQBQsBCREvAgAABAEFAAQAAwAEAgBWAFcA",

// 1. publish new code module first
codeModuleBz, err := vmprecompile.ReadStdlib("code.move")
if err != nil {
return nil, err
}
err = app.MoveKeeper.SetModule(ctx, vmtypes.StdAddress, movetypes.MoveModuleNameCode, codeModuleBz[0])
if err != nil {
return nil, err
}
beer-1 marked this conversation as resolved.
Show resolved Hide resolved

// 2. update vm data with new seperator and add checksums of each module

type KV struct {
key []byte
value []byte
}
kvs := make([]KV, 0)

// Previous:
// ModuleSeparator = byte(0)
// ResourceSeparator = byte(1)
// TableEntrySeparator = byte(2)
// TableInfoSeparator = byte(3)

modules := make([]vmtypes.Module, len(codes))
for i, code := range codes {
codeBz, err := base64.StdEncoding.DecodeString(code)
// Current:
// ModuleSeparator = byte(0)
// ChecksumSeparator = byte(1)
// ResourceSeparator = byte(2)
// TableEntrySeparator = byte(3)
// TableInfoSeparator = byte(4)

err = app.MoveKeeper.VMStore.Walk(ctx, nil, func(key, value []byte) (stop bool, err error) {
cursor := movetypes.AddressBytesLength
if len(key) <= cursor {
return true, fmt.Errorf("invalid key length: %d", len(key))
}

separator := key[cursor]

if separator == movetypes.ModuleSeparator {
checksum := movetypes.ModuleBzToChecksum(value)
value = checksum[:]
} else if separator >= movetypes.TableInfoSeparator {
return true, errors.New("unknown prefix")
} else {
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
err = app.MoveKeeper.VMStore.Remove(ctx, key)
if err != nil {
return true, err
}
}
key[cursor] = key[cursor] + 1
kvs = append(kvs, KV{
key: bytes.Clone(key),
value: bytes.Clone(value),
})
return false, nil
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add bounds check before key modification.

The key modification at line 92 could cause a panic if cursor is out of bounds.

Add a safety check:

+				if len(key) <= cursor {
+					return true, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid key length for separator increment")
+				}
				key[cursor] = key[cursor] + 1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
key[cursor] = key[cursor] + 1
kvs = append(kvs, KV{
key: bytes.Clone(key),
value: bytes.Clone(value),
})
return false, nil
if len(key) <= cursor {
return true, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid key length for separator increment")
}
key[cursor] = key[cursor] + 1
kvs = append(kvs, KV{
key: bytes.Clone(key),
value: bytes.Clone(value),
})
return false, nil

})
if err != nil {
return nil, err
}

for _, kv := range kvs {
err = app.MoveKeeper.VMStore.Set(ctx, kv.key, kv.value)
if err != nil {
return nil, errors.Wrap(err, "failed to decode module code")
return nil, err
}
}

// 3. update new modules
codesBz, err := vmprecompile.ReadStdlib("object_code_deployment.move", "coin.move", "cosmos.move", "dex.move", "json.move", "bech32.move", "hash.move")
if err != nil {
return nil, err
}
modules := make([]vmtypes.Module, len(codesBz))
for i, codeBz := range codesBz {
modules[i] = vmtypes.NewModule(codeBz)
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
}

err := app.MoveKeeper.PublishModuleBundle(ctx, vmtypes.StdAddress, vmtypes.NewModuleBundle(modules...), movetypes.UpgradePolicy_COMPATIBLE)
err = app.MoveKeeper.PublishModuleBundle(ctx, vmtypes.StdAddress, vmtypes.NewModuleBundle(modules...), movetypes.UpgradePolicy_COMPATIBLE)
if err != nil {
return nil, errors.Wrap(err, "failed to publish module bundle")
return nil, sdkerrors.Wrap(err, "failed to publish module bundle")
}

return vm, nil
Expand Down
13 changes: 9 additions & 4 deletions proto/initia/move/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@ message GenesisState {
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
repeated Resource resources = 5 [
repeated Checksum checksums = 5 [
(gogoproto.jsontag) = "checksums,omitempty",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
repeated Resource resources = 6 [
(gogoproto.jsontag) = "resources,omitempty",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
repeated TableInfo table_infos = 6 [
repeated TableInfo table_infos = 7 [
(gogoproto.jsontag) = "table_infos,omitempty",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
repeated TableEntry table_entries = 7 [
repeated TableEntry table_entries = 8 [
(gogoproto.jsontag) = "table_entries,omitempty",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
repeated DexPair dex_pairs = 8 [
repeated DexPair dex_pairs = 9 [
(gogoproto.jsontag) = "dex_pairs,omitempty",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
9 changes: 7 additions & 2 deletions proto/initia/move/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ message RawParams {
}

// Module is data for the uploaded contract move code
// ex) 0000000000000000000000000000000000000001/0/BasicCoin
message Module {
string address = 1;
string module_name = 2;
Expand All @@ -73,8 +72,14 @@ message Module {
UpgradePolicy upgrade_policy = 5;
}

// Checksum is checksum of the uploaded contract move code
message Checksum {
string address = 1;
string module_name = 2;
bytes checksum = 3;
}

// Resource is data for the stored move resource
// ex) 0000000000000000000000000000000000000002/2/0x1::BasicCoin::Coin<0x1::BasicCoin::Initia>
message Resource {
string address = 1;
string struct_tag = 2;
Expand Down
Loading
Loading