From acfd1ac30a1b97f03189b1fc34315dea8e83e055 Mon Sep 17 00:00:00 2001 From: testinginprod <98415576+testinginprod@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:15:17 +0200 Subject: [PATCH] refactor(auth): decouple auth from x/accounts account abstraction types (#20875) --- client/v2/go.mod | 1 - go.mod | 1 - server/v2/cometbft/go.mod | 1 - tests/e2e/accounts/base_account_test.go | 3 +-- tests/go.mod | 1 + tests/go.sum | 2 -- x/accounts/keeper_account_abstraction.go | 11 +++++++++-- x/auth/ante/sigverify.go | 24 ++++++++++++++---------- x/auth/go.mod | 1 - x/authz/go.mod | 1 - x/bank/go.mod | 1 - x/circuit/go.mod | 1 - x/consensus/go.mod | 1 - x/distribution/go.mod | 1 - x/epochs/go.mod | 1 - x/evidence/go.mod | 1 - x/feegrant/go.mod | 1 - x/gov/go.mod | 1 - x/mint/go.mod | 1 - x/nft/go.mod | 1 - x/params/go.mod | 1 - x/protocolpool/go.mod | 1 - x/slashing/go.mod | 1 - x/staking/go.mod | 1 - x/upgrade/go.mod | 1 - 25 files changed, 25 insertions(+), 36 deletions(-) diff --git a/client/v2/go.mod b/client/v2/go.mod index 8b8ad2fe19..97c1c76d78 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -30,7 +30,6 @@ require ( cosmossdk.io/log v1.3.1 // indirect cosmossdk.io/math v1.3.0 cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect diff --git a/go.mod b/go.mod index 8527485c19..c78efc9c32 100644 --- a/go.mod +++ b/go.mod @@ -69,7 +69,6 @@ require ( require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/DataDog/datadog-go v4.8.3+incompatible // indirect diff --git a/server/v2/cometbft/go.mod b/server/v2/cometbft/go.mod index b7b51b9287..6e3509c7c4 100644 --- a/server/v2/cometbft/go.mod +++ b/server/v2/cometbft/go.mod @@ -54,7 +54,6 @@ require ( cosmossdk.io/log v1.3.1 // indirect cosmossdk.io/math v1.3.0 // indirect cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v0.13.3 // indirect diff --git a/tests/e2e/accounts/base_account_test.go b/tests/e2e/accounts/base_account_test.go index 64a6dff9a5..fcd43e6940 100644 --- a/tests/e2e/accounts/base_account_test.go +++ b/tests/e2e/accounts/base_account_test.go @@ -43,9 +43,8 @@ func TestBaseAccount(t *testing.T) { func sendTx(t *testing.T, ctx sdk.Context, app *simapp.SimApp, sender []byte, msg sdk.Msg) { tx := sign(t, ctx, app, sender, privKey, msg) - res, _, err := app.SimDeliver(app.TxEncode, tx) + _, _, err := app.SimDeliver(app.TxEncode, tx) require.NoError(t, err) - t.Log(res) } func sign(t *testing.T, ctx sdk.Context, app *simapp.SimApp, from sdk.AccAddress, privKey cryptotypes.PrivKey, msg sdk.Msg) sdk.Tx { diff --git a/tests/go.mod b/tests/go.mod index efe255a582..20ae5e3ae1 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -241,6 +241,7 @@ replace ( cosmossdk.io/core/testing => ../core/testing cosmossdk.io/depinject => ../depinject cosmossdk.io/log => ../log + cosmossdk.io/store => ../store cosmossdk.io/x/accounts => ../x/accounts cosmossdk.io/x/accounts/defaults/lockup => ../x/accounts/defaults/lockup cosmossdk.io/x/auth => ../x/auth diff --git a/tests/go.sum b/tests/go.sum index 17825fa82f..3070683b52 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -196,8 +196,6 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= -cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc h1:R9O9d75e0qZYUsVV0zzi+D7cNLnX2JrUOQNoIPaF0Bg= -cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc/go.mod h1:amTTatOUV3u1PsKmNb87z6/galCxrRbz9kRdJkL0DyU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= diff --git a/x/accounts/keeper_account_abstraction.go b/x/accounts/keeper_account_abstraction.go index 377117db0f..47acac990d 100644 --- a/x/accounts/keeper_account_abstraction.go +++ b/x/accounts/keeper_account_abstraction.go @@ -9,6 +9,7 @@ import ( aa_interface_v1 "cosmossdk.io/x/accounts/interfaces/account_abstraction/v1" "github.com/cosmos/cosmos-sdk/types/address" + "github.com/cosmos/cosmos-sdk/types/tx" ) var ( @@ -37,8 +38,14 @@ func (k Keeper) IsAbstractedAccount(ctx context.Context, addr []byte) (bool, err return impl.HasExec(&aa_interface_v1.MsgAuthenticate{}), nil } -func (k Keeper) AuthenticateAccount(ctx context.Context, addr []byte, msg *aa_interface_v1.MsgAuthenticate) error { - _, err := k.Execute(ctx, addr, address.Module("accounts"), msg, nil) +func (k Keeper) AuthenticateAccount(ctx context.Context, signer []byte, bundler string, rawTx *tx.TxRaw, protoTx *tx.Tx, signIndex uint32) error { + msg := &aa_interface_v1.MsgAuthenticate{ + Bundler: bundler, + RawTx: rawTx, + Tx: protoTx, + SignerIndex: signIndex, + } + _, err := k.Execute(ctx, signer, address.Module("accounts"), msg, nil) if err != nil { return fmt.Errorf("%w: %w", ErrAuthentication, err) } diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 0f4e399959..c16ec1e40b 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -13,7 +13,6 @@ import ( "cosmossdk.io/core/transaction" errorsmod "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" - aa_interface_v1 "cosmossdk.io/x/accounts/interfaces/account_abstraction/v1" authsigning "cosmossdk.io/x/auth/signing" "cosmossdk.io/x/auth/types" txsigning "cosmossdk.io/x/tx/signing" @@ -52,7 +51,7 @@ type SignatureVerificationGasConsumer = func(meter storetypes.GasMeter, sig sign type AccountAbstractionKeeper interface { IsAbstractedAccount(ctx context.Context, addr []byte) (bool, error) - AuthenticateAccount(ctx context.Context, addr []byte, msg *aa_interface_v1.MsgAuthenticate) error + AuthenticateAccount(ctx context.Context, signer []byte, bundler string, rawTx *tx.TxRaw, protoTx *tx.Tx, signIndex uint32) error } // SigVerificationDecorator verifies all signatures for a tx and returns an @@ -434,16 +433,21 @@ func (svd SigVerificationDecorator) authenticateAbstractedAccount(ctx sdk.Contex } infoTx := authTx.(interface { - GetRawTx() *tx.TxRaw - GetProtoTx() *tx.Tx + AsTxRaw() (*tx.TxRaw, error) + AsTx() (*tx.Tx, error) }) - return svd.aaKeeper.AuthenticateAccount(ctx, signer, &aa_interface_v1.MsgAuthenticate{ - Bundler: selfBundler, - RawTx: infoTx.GetRawTx(), - Tx: infoTx.GetProtoTx(), - SignerIndex: uint32(index), - }) + txRaw, err := infoTx.AsTxRaw() + if err != nil { + return fmt.Errorf("unable to get raw tx: %w", err) + } + + protoTx, err := infoTx.AsTx() + if err != nil { + return fmt.Errorf("unable to get proto tx: %w", err) + } + + return svd.aaKeeper.AuthenticateAccount(ctx, signer, selfBundler, txRaw, protoTx, uint32(index)) } // ValidateSigCountDecorator takes in Params and returns errors if there are too many signatures in the tx for the given params diff --git a/x/auth/go.mod b/x/auth/go.mod index 8562bfda8b..5546bd71de 100644 --- a/x/auth/go.mod +++ b/x/auth/go.mod @@ -11,7 +11,6 @@ require ( cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.3.0 cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000 cosmossdk.io/x/tx v0.13.3 github.com/cometbft/cometbft v1.0.0-rc1 diff --git a/x/authz/go.mod b/x/authz/go.mod index d751919833..f76a67cac8 100644 --- a/x/authz/go.mod +++ b/x/authz/go.mod @@ -11,7 +11,6 @@ require ( cosmossdk.io/log v1.3.1 cosmossdk.io/math v1.3.0 cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 cosmossdk.io/x/tx v0.13.3 diff --git a/x/bank/go.mod b/x/bank/go.mod index 4aa7251c70..b6a0be5f19 100644 --- a/x/bank/go.mod +++ b/x/bank/go.mod @@ -11,7 +11,6 @@ require ( cosmossdk.io/log v1.3.1 // indirect cosmossdk.io/math v1.3.0 cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/cometbft/cometbft v1.0.0-rc1 github.com/cosmos/cosmos-proto v1.0.0-beta.5 diff --git a/x/circuit/go.mod b/x/circuit/go.mod index 4af9d344c4..18714f7e8a 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -24,7 +24,6 @@ require ( buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect cosmossdk.io/log v1.3.1 // indirect cosmossdk.io/math v1.3.0 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect diff --git a/x/consensus/go.mod b/x/consensus/go.mod index 7d72583133..6adbd307ae 100644 --- a/x/consensus/go.mod +++ b/x/consensus/go.mod @@ -26,7 +26,6 @@ require ( cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.3.1 // indirect cosmossdk.io/math v1.3.0 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect diff --git a/x/distribution/go.mod b/x/distribution/go.mod index 3f6acc7eda..8a0e9df7c6 100644 --- a/x/distribution/go.mod +++ b/x/distribution/go.mod @@ -38,7 +38,6 @@ require ( require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v0.13.3 // indirect diff --git a/x/epochs/go.mod b/x/epochs/go.mod index ede8e5ccfc..7aaf3ebad8 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -23,7 +23,6 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect cosmossdk.io/math v1.3.0 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect diff --git a/x/evidence/go.mod b/x/evidence/go.mod index 011e71716d..2e45731e33 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -28,7 +28,6 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect cosmossdk.io/log v1.3.1 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 31b3629daf..0082f43338 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -31,7 +31,6 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect cosmossdk.io/log v1.3.1 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190 // indirect diff --git a/x/gov/go.mod b/x/gov/go.mod index 9730ee3350..92efbf8c3c 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -12,7 +12,6 @@ require ( cosmossdk.io/log v1.3.1 // indirect cosmossdk.io/math v1.3.0 cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000 // indirect diff --git a/x/mint/go.mod b/x/mint/go.mod index 4e7a05b6ad..f286acecd2 100644 --- a/x/mint/go.mod +++ b/x/mint/go.mod @@ -11,7 +11,6 @@ require ( cosmossdk.io/log v1.3.1 cosmossdk.io/math v1.3.0 cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/epochs v0.0.0-20240522060652-a1ae4c3e0337 github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/cosmos/cosmos-proto v1.0.0-beta.5 diff --git a/x/nft/go.mod b/x/nft/go.mod index 4836516f8d..10037c6b07 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -25,7 +25,6 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000 // indirect diff --git a/x/params/go.mod b/x/params/go.mod index d06d3e6f0b..fc95311d92 100644 --- a/x/params/go.mod +++ b/x/params/go.mod @@ -29,7 +29,6 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000 // indirect diff --git a/x/protocolpool/go.mod b/x/protocolpool/go.mod index e482722582..ec89c50376 100644 --- a/x/protocolpool/go.mod +++ b/x/protocolpool/go.mod @@ -28,7 +28,6 @@ require ( require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect diff --git a/x/slashing/go.mod b/x/slashing/go.mod index 43ffbe7135..1d9ebe7564 100644 --- a/x/slashing/go.mod +++ b/x/slashing/go.mod @@ -30,7 +30,6 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect cosmossdk.io/log v1.3.1 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v0.13.3 // indirect diff --git a/x/staking/go.mod b/x/staking/go.mod index a7ece3d42b..1d077317e3 100644 --- a/x/staking/go.mod +++ b/x/staking/go.mod @@ -158,7 +158,6 @@ require ( require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect cosmossdk.io/log v1.3.1 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000 github.com/cosmos/crypto v0.1.1 // indirect github.com/dgraph-io/badger/v4 v4.2.0 // indirect diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index 5183ae01f2..11324a6d74 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -44,7 +44,6 @@ require ( cloud.google.com/go/storage v1.42.0 // indirect cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/math v1.3.0 // indirect - cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v0.13.3 // indirect