Skip to content

Commit

Permalink
feat(x/auth/ante): allow custom verifyIsOnCurve when validate tx for …
Browse files Browse the repository at this point in the history
…public key
  • Loading branch information
mmsqe committed Dec 30, 2024
1 parent 4f3f401 commit 3f8243b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

* (baseapp) [#20291](https://github.com/cosmos/cosmos-sdk/pull/20291) Simulate nested messages.
* (client/keys) [#21829](https://github.com/cosmos/cosmos-sdk/pull/21829) Add support for importing hex key using standard input.
* (x/auth/ante) [#23128](https://github.com/cosmos/cosmos-sdk/pull/23128) Allow custom verifyIsOnCurve when validate tx for public key like ethsecp256k1.

### Improvements

Expand Down
34 changes: 25 additions & 9 deletions x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,24 @@ type AccountAbstractionKeeper interface {
//
// CONTRACT: Tx must implement SigVerifiableTx interface
type SigVerificationDecorator struct {
ak AccountKeeper
aaKeeper AccountAbstractionKeeper
signModeHandler *txsigning.HandlerMap
sigGasConsumer SignatureVerificationGasConsumer
ak AccountKeeper
aaKeeper AccountAbstractionKeeper
signModeHandler *txsigning.HandlerMap
sigGasConsumer SignatureVerificationGasConsumer
extraVerifyIsOnCurve func(pubKey cryptotypes.PubKey) (bool, error)
}

func NewSigVerificationDecorator(ak AccountKeeper, signModeHandler *txsigning.HandlerMap, sigGasConsumer SignatureVerificationGasConsumer, aaKeeper AccountAbstractionKeeper) SigVerificationDecorator {
return NewSigVerificationDecoratorWithVerifyOnCurve(ak, signModeHandler, sigGasConsumer, aaKeeper, nil)
}

func NewSigVerificationDecoratorWithVerifyOnCurve(ak AccountKeeper, signModeHandler *txsigning.HandlerMap, sigGasConsumer SignatureVerificationGasConsumer, aaKeeper AccountAbstractionKeeper, verifyFn func(pubKey cryptotypes.PubKey) (bool, error)) SigVerificationDecorator {
return SigVerificationDecorator{
aaKeeper: aaKeeper,
ak: ak,
signModeHandler: signModeHandler,
sigGasConsumer: sigGasConsumer,
aaKeeper: aaKeeper,
ak: ak,
signModeHandler: signModeHandler,
sigGasConsumer: sigGasConsumer,
extraVerifyIsOnCurve: verifyFn,
}
}

Expand Down Expand Up @@ -150,6 +156,16 @@ func verifyIsOnCurve(pubKey cryptotypes.PubKey) (err error) {
return nil
}

func (svd SigVerificationDecorator) VerifyIsOnCurve(pubKey cryptotypes.PubKey) error {
if svd.extraVerifyIsOnCurve != nil {
handled, err := svd.extraVerifyIsOnCurve(pubKey)
if handled {
return err
}
}
return verifyIsOnCurve(pubKey)
}

func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if err := svd.ValidateTx(ctx, tx); err != nil {
return ctx, err
Expand Down Expand Up @@ -417,7 +433,7 @@ func (svd SigVerificationDecorator) setPubKey(ctx context.Context, acc sdk.Accou
return sdkerrors.ErrInvalidPubKey.Wrapf("the account %s cannot be claimed by public key with address %x", acc.GetAddress(), txPubKey.Address())
}

err := verifyIsOnCurve(txPubKey)
err := svd.VerifyIsOnCurve(txPubKey)
if err != nil {
return err
}
Expand Down

0 comments on commit 3f8243b

Please sign in to comment.