Skip to content
Open
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
23 changes: 22 additions & 1 deletion app/ante/ante_evm.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
package ante

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
evmante "github.com/cosmos/evm/ante/evm"
anteinterfaces "github.com/cosmos/evm/ante/interfaces"
)

// evmAccountKeeperWrapper adapts push-chain's AccountKeeper to satisfy the
// cosmos/evm interfaces.AccountKeeper, which requires unordered-tx methods not
// present in cosmos-sdk v0.50.x. Stubs return safe no-op values because
// unordered transactions are not enabled on this chain.
type evmAccountKeeperWrapper struct {
AccountKeeper
}

var _ anteinterfaces.AccountKeeper = evmAccountKeeperWrapper{}

func (w evmAccountKeeperWrapper) UnorderedTransactionsEnabled() bool { return false }

func (w evmAccountKeeperWrapper) RemoveExpiredUnorderedNonces(_ sdk.Context) error { return nil }

func (w evmAccountKeeperWrapper) TryAddUnorderedNonce(_ sdk.Context, _ []byte, _ time.Time) error {
return nil
}

// newMonoEVMAnteHandler creates the sdk.AnteHandler implementation for the EVM transactions.
func newMonoEVMAnteHandler(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
evmante.NewEVMMonoDecorator(
options.AccountKeeper,
evmAccountKeeperWrapper{options.AccountKeeper},
options.FeeMarketKeeper,
options.EvmKeeper,
options.MaxTxGasWanted,
Expand Down
31 changes: 25 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"sort"
"sync"
"time"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
Expand Down Expand Up @@ -185,7 +186,8 @@ const (
NodeDir = ".pchain"
Bech32Prefix = "push"

ChainID = "localchain_9000-1"
ChainID = "localchain_9000-1"
EVMChainID = uint64(9000)
)

var (
Expand All @@ -198,6 +200,20 @@ var (
}
)

// authKeeperEVMWrapper adapts cosmos-sdk v0.50.x AccountKeeper to satisfy the
// cosmos/evm AccountKeeper interfaces, which require unordered-tx methods not
// present in sdk v0.50. Stubs are safe no-ops because this chain does not
// enable unordered transactions.
type authKeeperEVMWrapper struct {
authkeeper.AccountKeeper
}

func (w authKeeperEVMWrapper) UnorderedTransactionsEnabled() bool { return false }
func (w authKeeperEVMWrapper) RemoveExpiredUnorderedNonces(_ sdk.Context) error { return nil }
func (w authKeeperEVMWrapper) TryAddUnorderedNonce(_ sdk.Context, _ []byte, _ time.Time) error {
return nil
}

func init() {
// manually update the power reduction based on the base denom unit (10^18 [evm] or 10^6 [cosmos])
sdk.DefaultPowerReduction = math.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(BaseDenomUnit), nil))
Expand Down Expand Up @@ -345,7 +361,7 @@ func NewChainApp(

// TODO: verify

encodingConfig := cosmosevmencoding.MakeConfig()
encodingConfig := cosmosevmencoding.MakeConfig(EVMChainID)
interfaceRegistry := encodingConfig.InterfaceRegistry
appCodec := encodingConfig.Codec
legacyAmino := encodingConfig.Amino
Expand Down Expand Up @@ -686,11 +702,13 @@ func NewChainApp(
appCodec,
keys[evmtypes.StoreKey],
tkeys[evmtypes.TransientKey],
keys,
authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper,
authKeeperEVMWrapper{app.AccountKeeper},
app.BankKeeper,
app.StakingKeeper,
app.FeeMarketKeeper,
app.ConsensusParamsKeeper,
&app.Erc20Keeper,
tracer,
)
Expand Down Expand Up @@ -776,6 +794,7 @@ func NewChainApp(
app.GovKeeper,
app.SlashingKeeper,
app.EvidenceKeeper,
appCodec,
)

// Add the usigverifier precompile for Ed25519 verification (old address: 0xCA)
Expand Down Expand Up @@ -1027,7 +1046,7 @@ func NewChainApp(
packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)),
wasmlc.NewAppModule(app.WasmClientKeeper),
ratelimit.NewAppModule(appCodec, app.RatelimitKeeper),
vm.NewAppModule(app.EVMKeeper, app.AccountKeeper),
vm.NewAppModule(app.EVMKeeper, authKeeperEVMWrapper{app.AccountKeeper}, app.AccountKeeper.AddressCodec()),
feemarket.NewAppModule(app.FeeMarketKeeper),
erc20.NewAppModule(app.Erc20Keeper, app.AccountKeeper),
uexecutor.NewAppModule(appCodec, app.UexecutorKeeper, app.EVMKeeper, app.FeeMarketKeeper, app.BankKeeper, app.AccountKeeper, app.UregistryKeeper, app.UvalidatorKeeper),
Expand Down Expand Up @@ -1437,7 +1456,7 @@ func (a *ChainApp) DefaultGenesis() map[string]json.RawMessage {
// which is the base denomination of the chain (i.e. the WTOKEN contract)
erc20GenState := erc20types.DefaultGenesisState()
erc20GenState.TokenPairs = ExampleTokenPairs
erc20GenState.Params.NativePrecompiles = append(erc20GenState.Params.NativePrecompiles, WTokenContractMainnet)
erc20GenState.NativePrecompiles = append(erc20GenState.NativePrecompiles, WTokenContractMainnet)
genesis[erc20types.ModuleName] = a.appCodec.MustMarshalJSON(erc20GenState)

return genesis
Expand Down Expand Up @@ -1560,7 +1579,7 @@ func BlockedAddresses() map[string]bool {
}

for _, precompile := range blockedPrecompilesHex {
blockedAddrs[cosmosevmutils.EthHexToCosmosAddr(precompile).String()] = true
blockedAddrs[cosmosevmutils.Bech32StringFromHexAddress(precompile)] = true
}

return blockedAddrs
Expand Down
2 changes: 1 addition & 1 deletion app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func EVMAppOptions(chainID string) error {
return err
}

ethCfg := evmtypes.DefaultChainConfig(chainID)
ethCfg := evmtypes.DefaultChainConfig(EVMChainID)

err := evmtypes.NewEVMConfigurator().
WithChainConfig(ethCfg).
Expand Down
12 changes: 8 additions & 4 deletions app/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"maps"

evidencekeeper "cosmossdk.io/x/evidence/keeper"
"github.com/cosmos/cosmos-sdk/codec"
distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
Expand Down Expand Up @@ -43,6 +44,7 @@ func NewAvailableStaticPrecompiles(
govKeeper govkeeper.Keeper,
slashingKeeper slashingkeeper.Keeper,
evidenceKeeper evidencekeeper.Keeper,
appCodec codec.Codec,
) map[common.Address]vm.PrecompiledContract {
// Clone the mapping from the latest EVM fork.
precompiles := maps.Clone(vm.PrecompiledContractsBerlin)
Expand All @@ -55,13 +57,14 @@ func NewAvailableStaticPrecompiles(
panic(fmt.Errorf("failed to instantiate bech32 precompile: %w", err))
}

stakingPrecompile, err := stakingprecompile.NewPrecompile(stakingKeeper)
stakingPrecompile, err := stakingprecompile.NewPrecompile(stakingKeeper, bankKeeper)
if err != nil {
panic(fmt.Errorf("failed to instantiate staking precompile: %w", err))
}

distributionPrecompile, err := distprecompile.NewPrecompile(
distributionKeeper,
bankKeeper,
stakingKeeper,
evmKeeper,
)
Expand All @@ -71,6 +74,7 @@ func NewAvailableStaticPrecompiles(

ibcTransferPrecompile, err := ics20precompile.NewPrecompile(
stakingKeeper,
bankKeeper,
transferKeeper,
channelKeeper,
evmKeeper,
Expand All @@ -84,17 +88,17 @@ func NewAvailableStaticPrecompiles(
panic(fmt.Errorf("failed to instantiate bank precompile: %w", err))
}

govPrecompile, err := govprecompile.NewPrecompile(govKeeper)
govPrecompile, err := govprecompile.NewPrecompile(govKeeper, bankKeeper, appCodec)
if err != nil {
panic(fmt.Errorf("failed to instantiate gov precompile: %w", err))
}

slashingPrecompile, err := slashingprecompile.NewPrecompile(slashingKeeper)
slashingPrecompile, err := slashingprecompile.NewPrecompile(slashingKeeper, bankKeeper)
if err != nil {
panic(fmt.Errorf("failed to instantiate slashing precompile: %w", err))
}

evidencePrecompile, err := evidenceprecompile.NewPrecompile(evidenceKeeper)
evidencePrecompile, err := evidenceprecompile.NewPrecompile(evidenceKeeper, bankKeeper)
if err != nil {
panic(fmt.Errorf("failed to instantiate evidence precompile: %w", err))
}
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
purgeexpiredoutbounds "github.com/pushchain/push-chain-node/app/upgrades/purge-expired-outbounds"
removeutxverifier "github.com/pushchain/push-chain-node/app/upgrades/remove-utxverifier"
tssfundmigrationfixes "github.com/pushchain/push-chain-node/app/upgrades/tss-fund-migration-fixes"
evmupgrade032 "github.com/pushchain/push-chain-node/app/upgrades/evm-upgrade032"
tssmigration "github.com/pushchain/push-chain-node/app/upgrades/tss-migration"
ueamigration "github.com/pushchain/push-chain-node/app/upgrades/uea-migration"
ceagasandpayload "github.com/pushchain/push-chain-node/app/upgrades/cea-gas-and-payload"
Expand Down Expand Up @@ -65,6 +66,7 @@ var Upgrades = []upgrades.Upgrade{
purgeexpiredoutbounds.NewUpgrade(),
removeutxverifier.NewUpgrade(),
tssfundmigrationfixes.NewUpgrade(),
evmupgrade032.NewUpgrade(),
}

// RegisterUpgradeHandlers registers the chain upgrade handlers
Expand Down
59 changes: 59 additions & 0 deletions app/upgrades/evm-upgrade032/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package evmupgrade032

import (
"context"

storetypes "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

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

"github.com/pushchain/push-chain-node/app/upgrades"
)

const UpgradeName = "evm-upgrade032"

func NewUpgrade() upgrades.Upgrade {
return upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{
Added: []string{},
Deleted: []string{},
},
}
}

// CreateUpgradeHandler runs the cosmos/evm v0.3.2 upgrade migrations.
//
// Key changes in this library bump:
// - AccountKeeper now requires unordered-tx methods (satisfied via authKeeperEVMWrapper stub)
// - EVMKeeper constructor takes additional params: store keys map, ConsensusParamsKeeper
// - go-ethereum bumped to v1.15.11-cosmos-0; statedb.Account.Balance is now uint256.Int (not big.Int)
// - erc20 module: NativePrecompiles moved from Params to a top-level genesis field
// - Precompile constructors now require bankKeeper; gov precompile also requires appCodec
// - vm.NewAppModule signature updated to accept AddressCodec
//
// RunMigrations handles the erc20 state migration automatically (consensus version bump).
func CreateUpgradeHandler(
mm upgrades.ModuleManager,
configurator module.Configurator,
ak *upgrades.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
logger := sdkCtx.Logger().With("upgrade", UpgradeName)
logger.Info("Starting upgrade handler")
logger.Info("cosmos/evm bumped to v0.3.2: erc20 NativePrecompiles field migration, go-ethereum v1.15.11-cosmos-0")

versionMap, err := mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
logger.Error("RunMigrations failed", "error", err)
return nil, err
}

logger.Info("Upgrade complete", "upgrade", UpgradeName)
return versionMap, nil
}
}
Loading
Loading