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: update ante handler to allow authz message #116

Merged
merged 3 commits into from
Nov 19, 2024
Merged
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
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func NewAppKeeper(
appKeepers.FeeGrantKeeper = &feeGrantKeeper

authzKeeper := authzkeeper.NewKeeper(runtime.NewKVStoreService(appKeepers.keys[authzkeeper.StoreKey]), appCodec, bApp.MsgServiceRouter(), appKeepers.AccountKeeper)
authzKeeper = authzKeeper.SetBankKeeper(appKeepers.BankKeeper)
appKeepers.AuthzKeeper = &authzKeeper

groupConfig := group.DefaultConfig()
Expand Down
101 changes: 53 additions & 48 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
)

const upgradeName = "0.6.5"
const upgradeName = "0.6.6"

// RegisterUpgradeHandlers returns upgrade handlers
func (app *MinitiaApp) RegisterUpgradeHandlers(cfg module.Configurator) {
Expand All @@ -47,63 +47,68 @@

//////////////////////////// MINIEVM ///////////////////////////////////

// deploy and store erc20 factory contract address
if err := app.EVMKeeper.DeployERC20Factory(ctx); err != nil &&
// deploy and store erc20 wrapper contract address
if err := app.EVMKeeper.DeployERC20Wrapper(ctx); err != nil &&

Check warning on line 51 in app/upgrade.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade.go#L51

Added line #L51 was not covered by tests
// ignore contract address collision error (contract already deployed)
!strings.Contains(err.Error(), vm.ErrContractAddressCollision.Error()) {
return nil, err
}

// deploy and store erc20 wrapper contract address
if err := app.EVMKeeper.DeployERC20Wrapper(ctx); err != nil &&
// deploy and store erc20 factory contract address
if err := app.EVMKeeper.DeployERC20Factory(ctx); err != nil &&

Check warning on line 58 in app/upgrade.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade.go#L58

Added line #L58 was not covered by tests
// ignore contract address collision error (contract already deployed)
!strings.Contains(err.Error(), vm.ErrContractAddressCollision.Error()) {
return nil, err
}

code := hexutil.MustDecode(erc20.Erc20MetaData.Bin)

// runtime code
initCodeOP := common.Hex2Bytes("5ff3fe")
initCodePos := bytes.Index(code, initCodeOP)
code = code[initCodePos+3:]

// code hash
codeHash := crypto.Keccak256Hash(code).Bytes()

// iterate all erc20 contracts and replace contract code to new version
err = app.EVMKeeper.ERC20s.Walk(ctx, nil, func(contractAddr []byte) (bool, error) {
acc := app.AccountKeeper.GetAccount(ctx, contractAddr)
if acc == nil {
return true, fmt.Errorf("account not found for contract address %s", contractAddr)
}

contractAcc, ok := acc.(*evmtypes.ContractAccount)
if !ok {
return true, fmt.Errorf("account is not a contract account for contract address %s", contractAddr)
}

contractAcc.CodeHash = codeHash
app.AccountKeeper.SetAccount(ctx, contractAcc)

// set code
codeKey := append(contractAddr, append(state.CodeKeyPrefix, codeHash...)...)
err := app.EVMKeeper.VMStore.Set(ctx, codeKey, code)
} else if err == nil {
// update erc20 contracts only if erc20 factory contract has been deployed without error.
//
// address collision error is ignored because it means that the contract has already been deployed
// and the erc20 contracts have already been updated.
//
code := hexutil.MustDecode(erc20.Erc20MetaData.Bin)

// runtime code
initCodeOP := common.Hex2Bytes("5ff3fe")
initCodePos := bytes.Index(code, initCodeOP)
code = code[initCodePos+3:]

// code hash
codeHash := crypto.Keccak256Hash(code).Bytes()

// iterate all erc20 contracts and replace contract code to new version
err = app.EVMKeeper.ERC20s.Walk(ctx, nil, func(contractAddr []byte) (bool, error) {
acc := app.AccountKeeper.GetAccount(ctx, contractAddr)
if acc == nil {
return true, fmt.Errorf("account not found for contract address %s", contractAddr)
}

Check warning on line 83 in app/upgrade.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade.go#L62-L83

Added lines #L62 - L83 were not covered by tests

contractAcc, ok := acc.(*evmtypes.ContractAccount)
if !ok {
return true, fmt.Errorf("account is not a contract account for contract address %s", contractAddr)
}

Check warning on line 88 in app/upgrade.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade.go#L85-L88

Added lines #L85 - L88 were not covered by tests

contractAcc.CodeHash = codeHash
app.AccountKeeper.SetAccount(ctx, contractAcc)

// set code
codeKey := append(contractAddr, append(state.CodeKeyPrefix, codeHash...)...)
err := app.EVMKeeper.VMStore.Set(ctx, codeKey, code)
if err != nil {
return true, err
}

Check warning on line 98 in app/upgrade.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade.go#L90-L98

Added lines #L90 - L98 were not covered by tests

// set code size
codeSizeKey := append(contractAddr, append(state.CodeSizeKeyPrefix, codeHash...)...)
err = app.EVMKeeper.VMStore.Set(ctx, codeSizeKey, uint64ToBytes(uint64(len(code))))
if err != nil {
return true, err
}

Check warning on line 105 in app/upgrade.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade.go#L101-L105

Added lines #L101 - L105 were not covered by tests

return false, nil

Check warning on line 107 in app/upgrade.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade.go#L107

Added line #L107 was not covered by tests
})
if err != nil {
return true, err
return nil, err

Check warning on line 110 in app/upgrade.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade.go#L110

Added line #L110 was not covered by tests
}

// set code size
codeSizeKey := append(contractAddr, append(state.CodeSizeKeyPrefix, codeHash...)...)
err = app.EVMKeeper.VMStore.Set(ctx, codeSizeKey, uint64ToBytes(uint64(len(code))))
if err != nil {
return true, err
}

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

return versionMap, nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/hashicorp/go-metrics v0.5.3
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/holiman/uint256 v1.3.1
github.com/initia-labs/OPinit v0.6.0
github.com/initia-labs/OPinit v0.6.1
github.com/initia-labs/initia v0.6.1
github.com/initia-labs/kvindexer v0.1.9
github.com/initia-labs/kvindexer/submodules/block v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1433,8 +1433,8 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/initia-labs/OPinit v0.6.0 h1:V9jQf8+PjNctLX31FHMGUsk6fpnygVJO1WYzCmBMzkU=
github.com/initia-labs/OPinit v0.6.0/go.mod h1:gDpCh4Zx94mihwgzP/PLav8eVHLroZBu3dFyzCy8iIs=
github.com/initia-labs/OPinit v0.6.1 h1:G9ebeYeqPlV9Z2s3JdSWfwQAUgIM+nhkcA8xSJUMR7M=
github.com/initia-labs/OPinit v0.6.1/go.mod h1:gDpCh4Zx94mihwgzP/PLav8eVHLroZBu3dFyzCy8iIs=
github.com/initia-labs/OPinit/api v0.6.0 h1:Q3hDHpTd9EqlDfY/OryCKIwuXYWJxGJdGfJicV1RjL4=
github.com/initia-labs/OPinit/api v0.6.0/go.mod h1:gHK6DEWb3/DqQD5LjKirUx9jilAh2UioXanoQdgqVfU=
github.com/initia-labs/cometbft v0.0.0-20241113064430-a371e2dc387f h1:PpYBvJ0L58bAgH7KwS/7GBEUphLnhf4fnTLua9uOov8=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ require (
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/initia-labs/OPinit v0.6.0 // indirect
github.com/initia-labs/OPinit v0.6.1 // indirect
github.com/initia-labs/OPinit/api v0.6.0 // indirect
github.com/initia-labs/kvindexer v0.1.9 // indirect
github.com/initia-labs/kvindexer/submodules/block v0.1.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/initia-labs/OPinit v0.6.0 h1:V9jQf8+PjNctLX31FHMGUsk6fpnygVJO1WYzCmBMzkU=
github.com/initia-labs/OPinit v0.6.1 h1:G9ebeYeqPlV9Z2s3JdSWfwQAUgIM+nhkcA8xSJUMR7M=
github.com/initia-labs/OPinit/api v0.6.0 h1:Q3hDHpTd9EqlDfY/OryCKIwuXYWJxGJdGfJicV1RjL4=
github.com/initia-labs/cometbft v0.0.0-20241113064430-a371e2dc387f h1:PpYBvJ0L58bAgH7KwS/7GBEUphLnhf4fnTLua9uOov8=
github.com/initia-labs/cometbft v0.0.0-20241113064430-a371e2dc387f/go.mod h1:y7+6kPknafzWlkSMCekzXC81wpRf1pcVAUnO0wRy9lQ=
Expand Down
Loading