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
1,537 changes: 1,173 additions & 364 deletions api/cosmos/evm/vm/v1/evm.pulsar.go

Large diffs are not rendered by default.

1,800 changes: 1,800 additions & 0 deletions contracts/solidity/StakedBondVault.json

Large diffs are not rendered by default.

865 changes: 865 additions & 0 deletions contracts/solidity/StakedBondVault.sol

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions contracts/staked_bond_vault.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package contracts

import (
_ "embed"

contractutils "github.com/cosmos/evm/contracts/utils"
evmtypes "github.com/cosmos/evm/x/vm/types"
)

var (
// StakedBondVaultJSON are the compiled bytes of the StakedBondVault contract.
//
//go:embed solidity/StakedBondVault.json
StakedBondVaultJSON []byte

// StakedBondVaultContract is the compiled ERC4626-style staking vault.
StakedBondVaultContract evmtypes.CompiledContract
)

func init() {
var err error
if StakedBondVaultContract, err = contractutils.ConvertHardhatBytesToCompiledContract(
StakedBondVaultJSON,
); err != nil {
panic(err)
}
}
10 changes: 7 additions & 3 deletions evmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ func NewExampleApp(
app.ParamsKeeper.Subspace(poatypes.ModuleName).WithKeyTable(poatypes.ParamKeyTable())

// get authority address
authAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String()
accountAddressCodec := evmaddress.NewEvmCodec(sdk.GetConfig().GetBech32AccountAddrPrefix())
authAddr, err := accountAddressCodec.BytesToString(authtypes.NewModuleAddress(govtypes.ModuleName))
if err != nil {
panic(fmt.Errorf("failed to encode gov authority address: %w", err))
}

// set the BaseApp's parameter store
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(
Expand All @@ -313,7 +317,7 @@ func NewExampleApp(
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]),
authtypes.ProtoBaseAccount, evmconfig.GetMaccPerms(),
evmaddress.NewEvmCodec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
accountAddressCodec,
sdk.GetConfig().GetBech32AccountAddrPrefix(),
authAddr,
)
Expand All @@ -334,7 +338,7 @@ func NewExampleApp(
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper),
}
txConfig, err := authtx.NewTxConfigWithOptions(
txConfig, err = authtx.NewTxConfigWithOptions(
appCodec,
txConfigOpts,
)
Expand Down
19 changes: 17 additions & 2 deletions precompiles/staking/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,13 @@ func NewMsgRedelegate(args []interface{}, denom string, addrCdc address.Codec) (
if !ok {
return nil, common.Address{}, fmt.Errorf(cmn.ErrInvalidType, "validatorSrcAddress", "string", args[1])
}
validatorSrcAddress = normalizeValidatorAddressString(validatorSrcAddress)

validatorDstAddress, ok := args[2].(string)
if !ok {
return nil, common.Address{}, fmt.Errorf(cmn.ErrInvalidType, "validatorDstAddress", "string", args[2])
}
validatorDstAddress = normalizeValidatorAddressString(validatorDstAddress)

amount, ok := args[3].(*big.Int)
if !ok {
Expand Down Expand Up @@ -348,6 +350,7 @@ func NewMsgCancelUnbondingDelegation(args []interface{}, denom string, addrCdc a
if !ok {
return nil, common.Address{}, fmt.Errorf(cmn.ErrInvalidType, "validatorAddress", "string", args[1])
}
validatorAddress = normalizeValidatorAddressString(validatorAddress)

amount, ok := args[2].(*big.Int)
if !ok {
Expand Down Expand Up @@ -392,6 +395,7 @@ func NewDelegationRequest(args []interface{}, addrCdc address.Codec) (*stakingty
if !ok {
return nil, fmt.Errorf(cmn.ErrInvalidType, "validatorAddress", "string", args[1])
}
validatorAddress = normalizeValidatorAddressString(validatorAddress)

delegatorAddrStr, err := addrCdc.BytesToString(delegatorAddr.Bytes())
if err != nil {
Expand Down Expand Up @@ -458,6 +462,7 @@ func NewRedelegationRequest(args []interface{}) (*RedelegationRequest, error) {
if !ok {
return nil, fmt.Errorf(cmn.ErrInvalidType, "validatorSrcAddress", "string", args[1])
}
validatorSrcAddress = normalizeValidatorAddressString(validatorSrcAddress)

validatorSrcAddr, err := sdk.ValAddressFromBech32(validatorSrcAddress)
if err != nil {
Expand All @@ -468,6 +473,7 @@ func NewRedelegationRequest(args []interface{}) (*RedelegationRequest, error) {
if !ok {
return nil, fmt.Errorf(cmn.ErrInvalidType, "validatorDstAddress", "string", args[2])
}
validatorDstAddress = normalizeValidatorAddressString(validatorDstAddress)

validatorDstAddr, err := sdk.ValAddressFromBech32(validatorDstAddress)
if err != nil {
Expand Down Expand Up @@ -519,8 +525,8 @@ func NewRedelegationsRequest(method *abi.Method, args []interface{}, addrCdc add

return &stakingtypes.QueryRedelegationsRequest{
DelegatorAddr: delegatorAddr, // bech32 formatted
SrcValidatorAddr: input.SrcValidatorAddress,
DstValidatorAddr: input.DstValidatorAddress,
SrcValidatorAddr: normalizeValidatorAddressString(input.SrcValidatorAddress),
DstValidatorAddr: normalizeValidatorAddressString(input.DstValidatorAddress),
Pagination: &input.PageRequest,
}, nil
}
Expand Down Expand Up @@ -835,6 +841,7 @@ func NewUnbondingDelegationRequest(args []interface{}, addrCdc address.Codec) (*
if !ok {
return nil, fmt.Errorf(cmn.ErrInvalidType, "validatorAddress", "string", args[1])
}
validatorAddress = normalizeValidatorAddressString(validatorAddress)

delegatorAddrStr, err := addrCdc.BytesToString(delegatorAddr.Bytes())
if err != nil {
Expand All @@ -861,6 +868,7 @@ func checkDelegationUndelegationArgs(args []interface{}) (common.Address, string
if !ok {
return common.Address{}, "", nil, fmt.Errorf(cmn.ErrInvalidType, "validatorAddress", "string", args[1])
}
validatorAddress = normalizeValidatorAddressString(validatorAddress)

amount, ok := args[2].(*big.Int)
if !ok {
Expand All @@ -870,6 +878,13 @@ func checkDelegationUndelegationArgs(args []interface{}) (common.Address, string
return delegatorAddr, validatorAddress, amount, nil
}

func normalizeValidatorAddressString(addr string) string {
if common.IsHexAddress(addr) {
return sdk.ValAddress(common.HexToAddress(addr).Bytes()).String()
}
return addr
}

// FormatConsensusPubkey format ConsensusPubkey into a base64 string
func FormatConsensusPubkey(consensusPubkey *codectypes.Any) string {
ed25519pk, ok := consensusPubkey.GetCachedValue().(cryptotypes.PubKey)
Expand Down
19 changes: 18 additions & 1 deletion proto/cosmos/evm/vm/v1/evm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,29 @@ message Params {
repeated string active_static_precompiles = 9;
uint64 history_serve_window = 10;
ExtendedDenomOptions extended_denom_options = 11;
// scheduler defines an optional bounded EndBlock EVM call used for
// contract-owned maintenance such as vault settlement.
EVMSchedulerParams scheduler = 12
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}

message ExtendedDenomOptions {
string extended_denom = 1;
}

message EVMSchedulerParams {
// enabled controls whether EndBlock attempts the configured call.
bool enabled = 1;
// target_contract is the EVM contract called with poke(uint256).
string target_contract = 2;
// gas_cap is the EVM gas limit for the scheduler call.
uint64 gas_cap = 3;
// max_ops is passed as the poke(uint256) argument.
uint32 max_ops = 4;
// cadence_blocks runs the call only when block_height % cadence_blocks == 0.
uint64 cadence_blocks = 5;
}

// AccessControl defines the permission policy of the EVM
// for creating and calling contracts
message AccessControl {
Expand Down Expand Up @@ -359,4 +376,4 @@ message EvmCoinInfo {
string extended_denom = 2;
string display_denom = 3;
uint32 decimals = 4;
}
}
6 changes: 5 additions & 1 deletion tests/integration/precompiles/gov/test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (s *PrecompileTestSuite) SetupTest() {
if err != nil {
panic(err)
}
govAddress := sdk.MustBech32ifyAddressBytes(
sdk.GetConfig().GetBech32AccountAddrPrefix(),
authtypes.NewModuleAddress(govtypes.ModuleName),
)
prop := &govv1.Proposal{
Id: 1,
Status: govv1.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD,
Expand Down Expand Up @@ -99,7 +103,7 @@ func (s *PrecompileTestSuite) SetupTest() {

bankGen := banktypes.DefaultGenesisState()
bankGen.Balances = []banktypes.Balance{{
Address: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Address: govAddress,
Coins: sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(200))),
}}
govGen := govv1.DefaultGenesisState()
Expand Down
21 changes: 16 additions & 5 deletions tests/integration/wallets/test_ledger_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"regexp"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/suite"

"github.com/cosmos/evm/testutil/constants"
Expand Down Expand Up @@ -75,6 +76,8 @@ func (suite *LedgerTestSuite) newPubKey(pk string) (res cryptotypes.PubKey) {

func (suite *LedgerTestSuite) getMockTxAmino() []byte {
whitespaceRegex := regexp.MustCompile(`\s+`)
fromAddress := bech32LedgerAddress("0x1111111111111111111111111111111111111111")
toAddress := bech32LedgerAddress("0x2222222222222222222222222222222222222222")
tmp := whitespaceRegex.ReplaceAllString(fmt.Sprintf(
`{
"account_number": "0",
Expand All @@ -88,12 +91,12 @@ func (suite *LedgerTestSuite) getMockTxAmino() []byte {
"type":"cosmos-sdk/MsgSend",
"value":{
"amount":[{"amount":"150","denom":"atom"}],
"from_address":"og1cml96vmptgw99syqrrz8az79xer2pcgpum8mp7",
"to_address":"og1jcltmuhplrdcwp7stlr4hlhlhgd4htqhgdvy48"
"from_address":"%s",
"to_address":"%s"
}
}],
"sequence":"6"
}`, constants.ExampleChainID.ChainID),
}`, constants.ExampleChainID.ChainID, fromAddress, toAddress),
"",
)

Expand All @@ -105,8 +108,8 @@ func (suite *LedgerTestSuite) getMockTxProtobuf() []byte {

memo := "memo"
msg := banktypes.NewMsgSend(
sdk.MustAccAddressFromBech32("og1cml96vmptgw99syqrrz8az79xer2pcgpum8mp7"),
sdk.MustAccAddressFromBech32("og1jcltmuhplrdcwp7stlr4hlhlhgd4htqhgdvy48"),
ledgerAccAddress("0x1111111111111111111111111111111111111111"),
ledgerAccAddress("0x2222222222222222222222222222222222222222"),
[]sdk.Coin{
{
Denom: "atom",
Expand Down Expand Up @@ -164,3 +167,11 @@ func (suite *LedgerTestSuite) getMockTxProtobuf() []byte {

return signBytes
}

func ledgerAccAddress(hexAddress string) sdk.AccAddress {
return common.HexToAddress(hexAddress).Bytes()
}

func bech32LedgerAddress(hexAddress string) string {
return sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), ledgerAccAddress(hexAddress))
}
2 changes: 1 addition & 1 deletion tests/integration/wallets/test_legder.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (suite *LedgerTestSuite) TestGetAddressPubKeySECP256K1() {
suite.Require().NoError(err)

addr := crypto.PubkeyToAddress(privKey.PublicKey)
expAddr, err := sdk.Bech32ifyAddressBytes("cosmos", common.HexToAddress(addr.String()).Bytes())
expAddr, err := sdk.Bech32ifyAddressBytes(suite.hrp, common.HexToAddress(addr.String()).Bytes())
suite.Require().NoError(err)

testCases := []struct {
Expand Down
31 changes: 18 additions & 13 deletions tests/integration/x/erc20/test_ibc_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cosmos/evm/contracts"
"github.com/cosmos/evm/crypto/ethsecp256k1"
"github.com/cosmos/evm/testutil"
testutils "github.com/cosmos/evm/testutil/integration/evm/utils"
"github.com/cosmos/evm/utils"
"github.com/cosmos/evm/x/erc20/keeper"
"github.com/cosmos/evm/x/erc20/types"
Expand All @@ -34,17 +35,18 @@ var erc20Denom = "erc20:0xdac17f958d2ee523a2206206994597c13d831ec7"

func (s *KeeperTestSuite) TestOnRecvPacketRegistered() {
var ctx sdk.Context
bech32Prefix := sdk.GetConfig().GetBech32AccountAddrPrefix()
// secp256k1 account
secpPk := secp256k1.GenPrivKey()
secpAddr := sdk.AccAddress(secpPk.PubKey().Address())
secpAddrCosmos := sdk.MustBech32ifyAddressBytes(sdk.Bech32MainPrefix, secpAddr)
secpAddrBech32 := sdk.MustBech32ifyAddressBytes(bech32Prefix, secpAddr)

// ethsecp256k1 account
ethPk, err := ethsecp256k1.GenerateKey()
s.Require().Nil(err)
ethsecpAddr := sdk.AccAddress(ethPk.PubKey().Address())
ethsecpAddrEvmos := sdk.AccAddress(ethPk.PubKey().Address()).String()
ethsecpAddrCosmos := sdk.MustBech32ifyAddressBytes(sdk.Bech32MainPrefix, ethsecpAddr)
ethsecpAddrBech32 := sdk.MustBech32ifyAddressBytes(bech32Prefix, ethsecpAddr)

// Setup Cosmos <=> Cosmos EVM IBC relayer
sourceChannel := "channel-292"
Expand Down Expand Up @@ -91,7 +93,7 @@ func (s *KeeperTestSuite) TestOnRecvPacketRegistered() {
{
name: "no-op - erc20 module param disabled",
malleate: func() {
transfer := transfertypes.NewFungibleTokenPacketData(registeredDenom, "100", ethsecpAddrEvmos, ethsecpAddrCosmos, "")
transfer := transfertypes.NewFungibleTokenPacketData(registeredDenom, "100", ethsecpAddrEvmos, ethsecpAddrBech32, "")
bz := transfertypes.ModuleCdc.MustMarshalJSON(&transfer)
packet = channeltypes.NewPacket(bz, 1, transfertypes.PortID, sourceChannel, transfertypes.PortID, cosmosEVMChannel, timeoutHeight, 0)
},
Expand All @@ -105,7 +107,7 @@ func (s *KeeperTestSuite) TestOnRecvPacketRegistered() {
{
name: "success - invalid sender (no '1')",
malleate: func() {
transfer := transfertypes.NewFungibleTokenPacketData(registeredDenom, "100", "evmos", ethsecpAddrCosmos, "")
transfer := transfertypes.NewFungibleTokenPacketData(registeredDenom, "100", "evmos", ethsecpAddrBech32, "")
bz := transfertypes.ModuleCdc.MustMarshalJSON(&transfer)
packet = channeltypes.NewPacket(bz, 100, transfertypes.PortID, sourceChannel, transfertypes.PortID, cosmosEVMChannel, timeoutHeight, 0)
},
Expand All @@ -118,7 +120,7 @@ func (s *KeeperTestSuite) TestOnRecvPacketRegistered() {
{
name: "success - invalid sender (bad address)",
malleate: func() {
transfer := transfertypes.NewFungibleTokenPacketData(registeredDenom, "100", "badba1sv9m0g7ycejwr3s369km58h5qe7xj77hvcxrms", ethsecpAddrCosmos, "")
transfer := transfertypes.NewFungibleTokenPacketData(registeredDenom, "100", "badba1sv9m0g7ycejwr3s369km58h5qe7xj77hvcxrms", ethsecpAddrBech32, "")
bz := transfertypes.ModuleCdc.MustMarshalJSON(&transfer)
packet = channeltypes.NewPacket(bz, 100, transfertypes.PortID, sourceChannel, transfertypes.PortID, cosmosEVMChannel, timeoutHeight, 0)
},
Expand All @@ -145,7 +147,7 @@ func (s *KeeperTestSuite) TestOnRecvPacketRegistered() {
name: "no-op - receiver is module account",
malleate: func() {
secpAddr = s.network.App.GetAccountKeeper().GetModuleAccount(ctx, "erc20").GetAddress()
transfer := transfertypes.NewFungibleTokenPacketData(registeredDenom, "100", secpAddrCosmos, secpAddr.String(), "")
transfer := transfertypes.NewFungibleTokenPacketData(registeredDenom, "100", secpAddrBech32, secpAddr.String(), "")
bz := transfertypes.ModuleCdc.MustMarshalJSON(&transfer)
packet = channeltypes.NewPacket(bz, 100, transfertypes.PortID, sourceChannel, transfertypes.PortID, cosmosEVMChannel, timeoutHeight, 0)
},
Expand All @@ -163,7 +165,7 @@ func (s *KeeperTestSuite) TestOnRecvPacketRegistered() {
bondDenom, err := s.network.App.GetStakingKeeper().BondDenom(ctx)
s.Require().NoError(err)
prefixedDenom := transfertypes.NewDenom(bondDenom, hop).Path()
transfer := transfertypes.NewFungibleTokenPacketData(prefixedDenom, "100", secpAddrCosmos, ethsecpAddrEvmos, "")
transfer := transfertypes.NewFungibleTokenPacketData(prefixedDenom, "100", secpAddrBech32, ethsecpAddrEvmos, "")
bz := transfertypes.ModuleCdc.MustMarshalJSON(&transfer)
packet = channeltypes.NewPacket(bz, 1, transfertypes.PortID, sourceChannel, transfertypes.PortID, cosmosEVMChannel, timeoutHeight, 0)
},
Expand All @@ -176,7 +178,7 @@ func (s *KeeperTestSuite) TestOnRecvPacketRegistered() {
{
name: "no-op - pair is not registered",
malleate: func() {
transfer := transfertypes.NewFungibleTokenPacketData(erc20Denom, "100", secpAddrCosmos, ethsecpAddrEvmos, "")
transfer := transfertypes.NewFungibleTokenPacketData(erc20Denom, "100", secpAddrBech32, ethsecpAddrEvmos, "")
bz := transfertypes.ModuleCdc.MustMarshalJSON(&transfer)
packet = channeltypes.NewPacket(bz, 1, transfertypes.PortID, sourceChannel, transfertypes.PortID, cosmosEVMChannel, timeoutHeight, 0)
},
Expand All @@ -189,7 +191,7 @@ func (s *KeeperTestSuite) TestOnRecvPacketRegistered() {
{
name: "error - pair is not registered but erc20 registered",
malleate: func() {
transfer := transfertypes.NewFungibleTokenPacketData(erc20Denom, "100", secpAddrCosmos, ethsecpAddrEvmos, "")
transfer := transfertypes.NewFungibleTokenPacketData(erc20Denom, "100", secpAddrBech32, ethsecpAddrEvmos, "")
bz := transfertypes.ModuleCdc.MustMarshalJSON(&transfer)
packet = channeltypes.NewPacket(bz, 1, transfertypes.PortID, sourceChannel, transfertypes.PortID, cosmosEVMChannel, timeoutHeight, 0)
collidedAddr, err := utils.GetIBCDenomAddress(transfertypes.NewDenom(erc20Denom, hop).IBCDenom())
Expand All @@ -206,7 +208,7 @@ func (s *KeeperTestSuite) TestOnRecvPacketRegistered() {
{
name: "error - pair is not registered but denom registered",
malleate: func() {
transfer := transfertypes.NewFungibleTokenPacketData(erc20Denom, "100", secpAddrCosmos, ethsecpAddrEvmos, "")
transfer := transfertypes.NewFungibleTokenPacketData(erc20Denom, "100", secpAddrBech32, ethsecpAddrEvmos, "")
bz := transfertypes.ModuleCdc.MustMarshalJSON(&transfer)
packet = channeltypes.NewPacket(bz, 1, transfertypes.PortID, sourceChannel, transfertypes.PortID, cosmosEVMChannel, timeoutHeight, 0)
collidedDenom := transfertypes.NewDenom(erc20Denom, hop).IBCDenom()
Expand All @@ -222,7 +224,7 @@ func (s *KeeperTestSuite) TestOnRecvPacketRegistered() {
{
name: "error - pair is not registered but address has code",
malleate: func() {
transfer := transfertypes.NewFungibleTokenPacketData(erc20Denom, "100", secpAddrCosmos, ethsecpAddrEvmos, "")
transfer := transfertypes.NewFungibleTokenPacketData(erc20Denom, "100", secpAddrBech32, ethsecpAddrEvmos, "")
bz := transfertypes.ModuleCdc.MustMarshalJSON(&transfer)
packet = channeltypes.NewPacket(bz, 1, transfertypes.PortID, sourceChannel, transfertypes.PortID, cosmosEVMChannel, timeoutHeight, 0)
collidedAddr, err := utils.GetIBCDenomAddress(transfertypes.NewDenom(erc20Denom, hop).IBCDenom())
Expand Down Expand Up @@ -326,7 +328,7 @@ func (s *KeeperTestSuite) TestOnRecvPacketRegistered() {

if tc.disableTokenPair {
_, err := s.network.App.GetErc20Keeper().ToggleConversion(ctx, &types.MsgToggleConversion{
Authority: authtypes.NewModuleAddress("gov").String(),
Authority: testutils.GovAuthority(),
Token: pair.Denom,
})
s.Require().NoError(err)
Expand Down Expand Up @@ -359,7 +361,10 @@ func (s *KeeperTestSuite) TestOnRecvPacketRegistered() {

func (s *KeeperTestSuite) TestConvertCoinToERC20FromPacket() {
var ctx sdk.Context
senderAddr := "cosmos1x2w87cvt5mqjncav4lxy8yfreynn273x34qlwy"
senderAddr := sdk.MustBech32ifyAddressBytes(
sdk.GetConfig().GetBech32AccountAddrPrefix(),
common.HexToAddress("0x329c175fa757b5d5d40187d4eb1e1efc62f12959").Bytes(),
)

baseDenom, err := sdk.GetBaseDenom()
s.Require().NoError(err)
Expand Down
Loading
Loading