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/sdk50 #66

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fd4e2c0
chore: fix conflict
kenta92115 Feb 26, 2024
99f7d37
chore: fix merge conflict with develop
kenta92115 Feb 26, 2024
532a57c
chore: root cmd
kenta92115 Feb 26, 2024
87df738
chore: add autoCLI
kenta92115 Feb 26, 2024
bf22d39
chore: add vote extension
kenta92115 Feb 26, 2024
ebda987
chore: fix interface registry for gentx
kenta92115 Feb 29, 2024
cf29abb
chore: set default keyring to test in gen account tx
kenta92115 Mar 1, 2024
5d276fb
chore: remove app config
kenta92115 Mar 1, 2024
223df9a
chore: fix bug with autoCli queries
kenta92115 Mar 1, 2024
5a3a443
chore: use comebft pubkey conversion
kenta92115 Mar 6, 2024
5832fab
fix: fix panic with decoding validator address
MikkySnow Mar 6, 2024
64398e5
chore: set default keyring test backend for keys command
kenta92115 Mar 6, 2024
af5b017
chore: fix default keyring for keys add command
kenta92115 Mar 8, 2024
91b63d7
chore: use genutil gen doc reader instead of cometbft genesis reader
kenta92115 Mar 13, 2024
8dab2bb
chore: use cometbft gen doc provider
kenta92115 Mar 18, 2024
fede36a
chore: update encoding proto buf
kenta92115 Mar 22, 2024
02882b1
chore: use stream instead of tendermint wsconn
kenta92115 Mar 22, 2024
21701d7
chore: fix bas module interface registry
kenta92115 Mar 22, 2024
4e1e1e2
chore: remove abic file and use simapp vote extension handler
kenta92115 Mar 22, 2024
14fc62c
chore: use correct address codec
kenta92115 Mar 22, 2024
da45a12
chore: refactor
kenta92115 Mar 29, 2024
fad244e
chore: add genesis templates
kenta92115 Mar 29, 2024
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
7 changes: 4 additions & 3 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"
"runtime/debug"

tmlog "github.com/cometbft/cometbft/libs/log"
tmlog "cosmossdk.io/log"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
Expand All @@ -31,6 +31,7 @@ import (

"swisstronik/crypto/ethsecp256k1"

storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
)

Expand Down Expand Up @@ -115,7 +116,7 @@ var _ authante.SignatureVerificationGasConsumer = DefaultSigVerificationGasConsu
// for signature verification based upon the public key type. The cost is fetched from the given params and is matched
// by the concrete type.
func DefaultSigVerificationGasConsumer(
meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params,
meter storetypes.GasMeter, sig signing.SignatureV2, params authtypes.Params,
) error {
pubkey := sig.PubKey
switch pubkey := pubkey.(type) {
Expand All @@ -141,7 +142,7 @@ func DefaultSigVerificationGasConsumer(

// ConsumeMultisignatureVerificationGas consumes gas from a GasMeter for verifying a multisig pubkey signature
func ConsumeMultisignatureVerificationGas(
meter sdk.GasMeter, sig *signing.MultiSignatureData, pubkey multisig.PubKey,
meter storetypes.GasMeter, sig *signing.MultiSignatureData, pubkey multisig.PubKey,
params authtypes.Params, accSeq uint64,
) error {
size := sig.BitArray.Count()
Expand Down
60 changes: 31 additions & 29 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (

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

"swisstronik/app"
storetypes "cosmossdk.io/store/types"

"swisstronik/app/ante"
"swisstronik/crypto/ethsecp256k1"
"swisstronik/encoding"
Expand All @@ -30,12 +31,13 @@ import (
"github.com/ethereum/go-ethereum/core/types"
ethparams "github.com/ethereum/go-ethereum/params"

signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

func (suite AnteTestSuite) TestAnteHandler() {
var acc authtypes.AccountI
var acc sdk.AccountI
addr, privKey := tests.RandomEthAddressWithPrivateKey()
to := tests.RandomEthAddress()

Expand Down Expand Up @@ -355,14 +357,14 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"uswtr",
sdk.NewInt(1),
sdkmath.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSingleSignedTx(
privKey,
signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
signingv1beta1.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
msg,
suite.ctx.ChainID(),
2000000,
Expand All @@ -385,14 +387,14 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"uswtr",
sdk.NewInt(1),
sdkmath.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
signingv1beta1.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
msg,
suite.ctx.ChainID(),
2000000,
Expand All @@ -415,14 +417,14 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"uswtr",
sdk.NewInt(1),
sdkmath.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
signingv1beta1.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
msg,
suite.ctx.ChainID(),
2000000,
Expand All @@ -447,7 +449,7 @@ func (suite AnteTestSuite) TestAnteHandler() {

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
signingv1beta1.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
msg,
suite.ctx.ChainID(),
2000000,
Expand All @@ -470,14 +472,14 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"uswtr",
sdk.NewInt(1),
sdkmath.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
signingv1beta1.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
msg,
"ethermint_9005-1",
2000000,
Expand All @@ -500,14 +502,14 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"uswtr",
sdk.NewInt(1),
sdkmath.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_DIRECT,
signingv1beta1.SignMode_SIGN_MODE_DIRECT,
msg,
suite.ctx.ChainID(),
2000000,
Expand All @@ -530,14 +532,14 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"uswtr",
sdk.NewInt(1),
sdkmath.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_DIRECT,
signingv1beta1.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
msg,
suite.ctx.ChainID(),
2000,
Expand All @@ -560,21 +562,21 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"uswtr",
sdk.NewInt(1),
sdkmath.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_DIRECT,
signingv1beta1.SignMode_SIGN_MODE_DIRECT,
msg,
suite.ctx.ChainID(),
2000,
"EIP-712",
)

msg.Amount[0].Amount = sdk.NewInt(5)
msg.Amount[0].Amount = sdkmath.NewInt(5)
txBuilder.SetMsgs(msg)

return txBuilder.GetTx()
Expand All @@ -593,14 +595,14 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"uswtr",
sdk.NewInt(1),
sdkmath.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_DIRECT,
signingv1beta1.SignMode_SIGN_MODE_DIRECT,
msg,
suite.ctx.ChainID(),
2000,
Expand All @@ -622,14 +624,14 @@ func (suite AnteTestSuite) TestAnteHandler() {
sdk.NewCoins(
sdk.NewCoin(
"uswtr",
sdk.NewInt(1),
sdkmath.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSingleSignedTx(
privKey,
signing.SignMode_SIGN_MODE_DIRECT,
signingv1beta1.SignMode_SIGN_MODE_DIRECT,
msg,
suite.ctx.ChainID(),
2000,
Expand Down Expand Up @@ -1075,7 +1077,7 @@ func (suite AnteTestSuite) TestAnteHandlerWithParams() {
func (suite *AnteTestSuite) TestConsumeSignatureVerificationGas() {
params := authtypes.DefaultParams()
msg := []byte{1, 2, 3, 4}
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
encodingConfig := encoding.MakeConfig()
cdc := encodingConfig.Amino

p := authtypes.DefaultParams()
Expand All @@ -1096,7 +1098,7 @@ func (suite *AnteTestSuite) TestConsumeSignatureVerificationGas() {
}

type args struct {
meter sdk.GasMeter
meter storetypes.GasMeter
sig signing.SignatureData
pubkey cryptotypes.PubKey
params authtypes.Params
Expand All @@ -1107,11 +1109,11 @@ func (suite *AnteTestSuite) TestConsumeSignatureVerificationGas() {
gasConsumed uint64
shouldErr bool
}{
{"PubKeyEd25519", args{sdk.NewInfiniteGasMeter(), nil, ed25519.GenPrivKey().PubKey(), params}, p.SigVerifyCostED25519, true},
{"PubKeyEthSecp256k1", args{sdk.NewInfiniteGasMeter(), nil, pkSet1[0], params}, 21_000, false},
{"PubKeySecp256r1", args{sdk.NewInfiniteGasMeter(), nil, skR1.PubKey(), params}, p.SigVerifyCostSecp256r1(), true},
{"Multisig", args{sdk.NewInfiniteGasMeter(), multisignature1, multisigKey1, params}, expectedCost1, false},
{"unknown key", args{sdk.NewInfiniteGasMeter(), nil, nil, params}, 0, true},
{"PubKeyEd25519", args{storetypes.NewInfiniteGasMeter(), nil, ed25519.GenPrivKey().PubKey(), params}, p.SigVerifyCostED25519, true},
{"PubKeyEthSecp256k1", args{storetypes.NewInfiniteGasMeter(), nil, pkSet1[0], params}, 21_000, false},
{"PubKeySecp256r1", args{storetypes.NewInfiniteGasMeter(), nil, skR1.PubKey(), params}, p.SigVerifyCostSecp256r1(), true},
{"Multisig", args{storetypes.NewInfiniteGasMeter(), multisignature1, multisigKey1, params}, expectedCost1, false},
{"unknown key", args{storetypes.NewInfiniteGasMeter(), nil, nil, params}, 0, true},
}
for _, tt := range tests {
sigV2 := signing.SignatureV2{
Expand Down
25 changes: 15 additions & 10 deletions app/ante/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,28 @@ import (
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"

"swisstronik/crypto/ethsecp256k1"
"swisstronik/ethereum/eip712"
ethermint "swisstronik/types"

ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/signer/core/apitypes"

evmtypes "swisstronik/x/evm/types"

swisstroniktypes "swisstronik/types"

txsigning "cosmossdk.io/x/tx/signing"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

var ethermintCodec codec.ProtoCodecMarshaler

func init() {
registry := codectypes.NewInterfaceRegistry()
ethermint.RegisterInterfaces(registry)
swisstroniktypes.RegisterInterfaces(registry)
ethermintCodec = codec.NewProtoCodec(registry)
}

Expand Down Expand Up @@ -87,13 +89,13 @@ func NewLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
// CONTRACT: Tx must implement SigVerifiableTx interface
type LegacyEip712SigVerificationDecorator struct {
ak evmtypes.AccountKeeper
signModeHandler authsigning.SignModeHandler
signModeHandler *txsigning.HandlerMap
}

// Deprecated: NewLegacyEip712SigVerificationDecorator creates a new LegacyEip712SigVerificationDecorator
func NewLegacyEip712SigVerificationDecorator(
ak evmtypes.AccountKeeper,
signModeHandler authsigning.SignModeHandler,
signModeHandler *txsigning.HandlerMap,
) LegacyEip712SigVerificationDecorator {
return LegacyEip712SigVerificationDecorator{
ak: ak,
Expand Down Expand Up @@ -130,7 +132,10 @@ func (svd LegacyEip712SigVerificationDecorator) AnteHandle(ctx sdk.Context,
return ctx, err
}

signerAddrs := sigTx.GetSigners()
signerAddrs, err := sigTx.GetSigners()
if err != nil {
return ctx, err
}

// EIP712 allows just one signature
if len(sigs) != 1 {
Expand Down Expand Up @@ -202,7 +207,7 @@ func VerifySignature(
pubKey cryptotypes.PubKey,
signerData authsigning.SignerData,
sigData signing.SignatureData,
_ authsigning.SignModeHandler,
_ *txsigning.HandlerMap,
tx authsigning.Tx,
) error {
switch data := sigData.(type) {
Expand Down Expand Up @@ -233,10 +238,10 @@ func VerifySignature(
Amount: tx.GetFee(),
Gas: tx.GetGas(),
},
msgs, tx.GetMemo(), tx.GetTip(),
msgs, tx.GetMemo(),
)

signerChainID, err := ethermint.ParseChainID(signerData.ChainID)
signerChainID, err := swisstroniktypes.ParseChainID(signerData.ChainID)
if err != nil {
return errorsmod.Wrapf(err, "failed to parse chain-id: %s", signerData.ChainID)
}
Expand All @@ -250,7 +255,7 @@ func VerifySignature(
return errorsmod.Wrap(errortypes.ErrUnknownExtensionOptions, "tx doesnt contain expected amount of extension options")
}

extOpt, ok := opts[0].GetCachedValue().(*ethermint.ExtensionOptionsWeb3Tx)
extOpt, ok := opts[0].GetCachedValue().(*swisstroniktypes.ExtensionOptionsWeb3Tx)
if !ok {
return errorsmod.Wrap(errortypes.ErrUnknownExtensionOptions, "unknown extension option")
}
Expand Down
Loading