Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

refactor(codec): Remove Bech32 from Polaris #889

Closed
wants to merge 4 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
24 changes: 13 additions & 11 deletions cosmos/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
# TITLE.

KEYS[0]="dev0"
KEYS[1]="dev1"
KEYS[2]="dev2"
<<<<<<< HEAD

# KEY="dev0"
KEY="dev0"
# KEYS[1]="dev1"
CHAINID="polaris-2061"
MONIKER="localtestnet"
# Remember to change to other types of keyring like 'file' in-case exposing to outside world,
Expand Down Expand Up @@ -75,9 +77,9 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
./bin/polard config set client chain-id "$CHAINID" --home "$HOMEDIR"

# If keys exist they should be deleted
for KEY in "${KEYS[@]}"; do
./bin/polard keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --home "$HOMEDIR"
done
# for KEY in "${KEYS[@]}"; do
./bin/polard keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --home "$HOMEDIR"
# done

# Change parameter token denominations to abera
jq '.app_state["staking"]["params"]["bond_denom"]="abera"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
Expand All @@ -87,17 +89,17 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
jq '.consensus["params"]["block"]["max_gas"]="30000000"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"

# Allocate genesis accounts (cosmos formatted addresses)
for KEY in "${KEYS[@]}"; do
./bin/polard genesis add-genesis-account $KEY 100000000000000000000000000abera --keyring-backend $KEYRING --home "$HOMEDIR"
done
# for KEY in "${KEYS[@]}"; do
./bin/polard genesis add-genesis-account $KEY 100000000000000000000000000abera --keyring-backend $KEYRING --home "$HOMEDIR"
# done

# Test Account
# absurd surge gather author blanket acquire proof struggle runway attract cereal quiz tattoo shed almost sudden survey boring film memory picnic favorite verb tank
# 0xfffdbb37105441e14b0ee6330d855d8504ff39e705c3afa8f859ac9865f99306
./bin/polard genesis add-genesis-account polar1yrene6g2zwjttemf0c65fscg8w8c55w5vhc9hd 69000000000000000000000000abera --keyring-backend $KEYRING --home "$HOMEDIR"
# ./bin/polard genesis add-genesis-account 0x20f33CE90A13a4b5E7697E3544c3083B8F8A51D4 69000000000000000000000000abera --keyring-backend $KEYRING --home "$HOMEDIR"

# Sign genesis transaction
./bin/polard genesis gentx ${KEYS[0]} 1000000000000000000000abera --keyring-backend $KEYRING --chain-id $CHAINID --home "$HOMEDIR"
./bin/polard genesis gentx $KEY 10000000000000000abera --keyring-backend $KEYRING --chain-id $CHAINID --home "$HOMEDIR"
## In case you want to create multiple validators at genesis
## 1. Back to `./bin/polard keys add` step, init more keys
## 2. Back to `./bin/polard add-genesis-account` step, add balance for those
Expand Down
39 changes: 39 additions & 0 deletions cosmos/lib/codec/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2023, Berachain Foundation. All rights reserved.
// Use of this software is govered by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package codec

import (
"cosmossdk.io/core/address"

"pkg.berachain.dev/polaris/eth/common"
)

var _ address.Codec = (*EIP55Address)(nil)

type EIP55Address struct{}

func (e EIP55Address) StringToBytes(text string) ([]byte, error) {
return common.FromHex(text), nil
}

func (e EIP55Address) BytesToString(bz []byte) (string, error) {
return common.BytesToAddress(bz).Hex(), nil
}
8 changes: 8 additions & 0 deletions cosmos/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

dbm "github.com/cosmos/cosmos-db"

"cosmossdk.io/core/address"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -63,6 +64,7 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

ethcryptocodec "pkg.berachain.dev/polaris/cosmos/crypto/codec"
polarcodec "pkg.berachain.dev/polaris/cosmos/lib/codec"
erc20keeper "pkg.berachain.dev/polaris/cosmos/x/erc20/keeper"
evmante "pkg.berachain.dev/polaris/cosmos/x/evm/ante"
evmkeeper "pkg.berachain.dev/polaris/cosmos/x/evm/keeper"
Expand Down Expand Up @@ -134,6 +136,7 @@ func NewPolarisApp(
var (
app = &SimApp{}
appBuilder *runtime.AppBuilder
addrCodec = polarcodec.EIP55Address{}
ethTxMempool = evmmempool.NewPolarisEthereumTxPool()
// merge the AppConfig and other configuration in one config
appConfig = depinject.Configs(
Expand All @@ -147,6 +150,11 @@ func NewPolarisApp(
ethTxMempool,
// ADVANCED CONFIGURATION
PrecompilesToInject(app),

// REQUIRED FOR EIP-55 ADDRESSES
func() address.Codec { return addrCodec },
func() runtime.ConsensusAddressCodec { return addrCodec },
func() runtime.ValidatorAddressCodec { return addrCodec },
//
// AUTH
//
Expand Down
3 changes: 2 additions & 1 deletion cosmos/simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ var (
{
Name: authtypes.ModuleName,
Config: appconfig.WrapAny(&authmodulev1.Module{
Bech32Prefix: "polar",
// Bech32Prefix: "polar",
ModuleAccountPermissions: moduleAccPerms,
// By default modules authority is the governance module. This is configurable with the following:
// Authority: "group", // A custom module authority can be set using a module name
// Authority: "cosmos1cwwv22j5ca08ggdv9c2uky355k908694z577tv", // or a specific address
Authority: "0x20f33CE90A13a4b5E7697E3544c3083B8F8A51D4",
}),
},
{
Expand Down
22 changes: 18 additions & 4 deletions cosmos/simapp/polard/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ import (
"github.com/spf13/viper"

"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/address"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
confixcmd "cosmossdk.io/tools/confix/cmd"
"cosmossdk.io/x/tx/signing"
txsigning "cosmossdk.io/x/tx/signing"

cmtcfg "github.com/cometbft/cometbft/config"

Expand All @@ -48,6 +49,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/snapshot"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/server"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand All @@ -62,6 +64,7 @@ import (

ethcryptocodec "pkg.berachain.dev/polaris/cosmos/crypto/codec"
"pkg.berachain.dev/polaris/cosmos/crypto/keyring"
polarcodec "pkg.berachain.dev/polaris/cosmos/lib/codec"
"pkg.berachain.dev/polaris/cosmos/simapp"
evmante "pkg.berachain.dev/polaris/cosmos/x/evm/ante"
evmmepool "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/txpool/mempool"
Expand All @@ -78,9 +81,15 @@ func NewRootCmd() *cobra.Command {
legacyAmino *codec.LegacyAmino
autoCliOpts autocli.AppOptions
moduleBasicManager module.BasicManager
addrCodec = polarcodec.EIP55Address{}
)
if err := depinject.Inject(depinject.Configs(simapp.AppConfig, depinject.Supply(
evmmepool.NewPolarisEthereumTxPool(), log.NewNopLogger())),
if err := depinject.Inject(
depinject.Configs(
simapp.AppConfig, depinject.Supply(
func() address.Codec { return addrCodec },
func() runtime.ConsensusAddressCodec { return addrCodec },
func() runtime.ValidatorAddressCodec { return addrCodec },
evmmepool.NewPolarisEthereumTxPool(), log.NewNopLogger())),
&interfaceRegistry,
&appCodec,
&txConfig,
Expand Down Expand Up @@ -129,11 +138,16 @@ func NewRootCmd() *cobra.Command {
}

// Add a custom sign mode handler for ethereum transactions.
txConfigOpts.CustomSignModes = []signing.SignModeHandler{evmante.SignModeEthTxHandler{}}
txConfigOpts.CustomSignModes = []txsigning.SignModeHandler{evmante.SignModeEthTxHandler{}}
txConfigOpts.SigningOptions = &txsigning.Options{
AddressCodec: addrCodec,
ValidatorAddressCodec: addrCodec,
}
txConfigWithTextual, err := tx.NewTxConfigWithOptions(
codec.NewProtoCodec(interfaceRegistry),
txConfigOpts,
)

if err != nil {
return err
}
Expand Down
Loading
Loading