-
Notifications
You must be signed in to change notification settings - Fork 75
/
sig_checker.go
50 lines (42 loc) · 1.78 KB
/
sig_checker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package evm
import (
"github.com/artela-network/artela/app/interfaces"
"github.com/artela-network/artela/x/evm/txs"
"github.com/cosmos/cosmos-sdk/baseapp"
errorsmod "cosmossdk.io/errors"
cosmos "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
)
// EthSigVerificationDecorator validates an ethereum signatures
type EthSigVerificationDecorator struct {
evmKeeper interfaces.EVMKeeper
app *baseapp.BaseApp
}
// NewEthSigVerificationDecorator creates a new EthSigVerificationDecorator
func NewEthSigVerificationDecorator(app *baseapp.BaseApp, ek interfaces.EVMKeeper) EthSigVerificationDecorator {
return EthSigVerificationDecorator{
evmKeeper: ek,
app: app,
}
}
// AnteHandle validates checks that the registered chain id is the same as the one on the message, and
// that the signer address matches the one defined on the message.
// It's not skipped for RecheckTx, because it set `From` address which is critical from other ante handler to work.
// Failure in RecheckTx will prevent tx to be included into block, especially when CheckTx succeed, in which case user
// won't see the error message.
func (esvd EthSigVerificationDecorator) AnteHandle(ctx cosmos.Context, tx cosmos.Tx, simulate bool, next cosmos.AnteHandler) (newCtx cosmos.Context, err error) {
for _, msg := range tx.GetMsgs() {
msgEthTx, ok := msg.(*txs.MsgEthereumTx)
if !ok {
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*txs.MsgEthereumTx)(nil))
}
ethTx := msgEthTx.AsTransaction()
sender, _, err := esvd.evmKeeper.VerifySig(ctx, ethTx)
if err != nil {
return ctx, err
}
// set up the sender to the transaction field if not already
msgEthTx.From = sender.Hex()
}
return next(ctx, tx, simulate)
}