feat(x/auth/ante): allow custom verifyIsOnCurve when validate tx for public key (#23128)
This commit is contained in:
parent
8f3122e31c
commit
57a1437fdf
@ -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
|
||||
|
||||
|
||||
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +111,13 @@ func OnlyLegacyAminoSigners(sigData signing.SignatureData) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func verifyIsOnCurve(pubKey cryptotypes.PubKey) (err error) {
|
||||
func (svd SigVerificationDecorator) VerifyIsOnCurve(pubKey cryptotypes.PubKey) error {
|
||||
if svd.extraVerifyIsOnCurve != nil {
|
||||
handled, err := svd.extraVerifyIsOnCurve(pubKey)
|
||||
if handled {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// when simulating pubKey.Key will always be nil
|
||||
if pubKey.Bytes() == nil {
|
||||
return nil
|
||||
@ -134,7 +146,7 @@ func verifyIsOnCurve(pubKey cryptotypes.PubKey) (err error) {
|
||||
pubKeysObjects := typedPubKey.GetPubKeys()
|
||||
ok := true
|
||||
for _, pubKeyObject := range pubKeysObjects {
|
||||
if err := verifyIsOnCurve(pubKeyObject); err != nil {
|
||||
if err := svd.VerifyIsOnCurve(pubKeyObject); err != nil {
|
||||
ok = false
|
||||
break
|
||||
}
|
||||
@ -417,7 +429,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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user