fix: improve error handling for EIP-712 encoding config init (#1543)

* Improve error handling for EIP-712 encoding config init

* changelog

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
Austin Chandra 2022-12-09 08:37:00 -08:00 committed by GitHub
parent e1de07dcdc
commit 3b2f9fcf6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -90,6 +90,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes ### Bug Fixes
* (eip712) [#1543](https://github.com/evmos/ethermint/pull/1543) Improve error handling for EIP-712 encoding config initialization.
* (app) [#1505](https://github.com/evmos/ethermint/pull/1505) Setup gRPC node service with the application. * (app) [#1505](https://github.com/evmos/ethermint/pull/1505) Setup gRPC node service with the application.
* (server) [#1497](https://github.com/evmos/ethermint/pull/1497) Fix telemetry server setup for observability * (server) [#1497](https://github.com/evmos/ethermint/pull/1497) Fix telemetry server setup for observability
* (rpc) [#1442](https://github.com/evmos/ethermint/pull/1442) Fix decoding of `finalized` block number. * (rpc) [#1442](https://github.com/evmos/ethermint/pull/1442) Fix decoding of `finalized` block number.

View File

@ -104,6 +104,7 @@ import (
_ "github.com/evmos/ethermint/client/docs/statik" _ "github.com/evmos/ethermint/client/docs/statik"
"github.com/evmos/ethermint/app/ante" "github.com/evmos/ethermint/app/ante"
"github.com/evmos/ethermint/ethereum/eip712"
srvflags "github.com/evmos/ethermint/server/flags" srvflags "github.com/evmos/ethermint/server/flags"
ethermint "github.com/evmos/ethermint/types" ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm" "github.com/evmos/ethermint/x/evm"
@ -252,6 +253,8 @@ func NewEthermintApp(
cdc := encodingConfig.Amino cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry interfaceRegistry := encodingConfig.InterfaceRegistry
eip712.SetEncodingConfig(encodingConfig)
// NOTE we use custom transaction decoder that supports the sdk.Tx interface instead of sdk.StdTx // NOTE we use custom transaction decoder that supports the sdk.Tx interface instead of sdk.StdTx
bApp := baseapp.NewBaseApp( bApp := baseapp.NewBaseApp(
appName, appName,

View File

@ -79,6 +79,11 @@ func isValidEIP712Payload(typedData apitypes.TypedData) bool {
// decodeAminoSignDoc attempts to decode the provided sign doc (bytes) as an Amino payload // decodeAminoSignDoc attempts to decode the provided sign doc (bytes) as an Amino payload
// and returns a signable EIP-712 TypedData object. // and returns a signable EIP-712 TypedData object.
func decodeAminoSignDoc(signDocBytes []byte) (apitypes.TypedData, error) { func decodeAminoSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
// Ensure codecs have been initialized
if err := validateCodecInit(); err != nil {
return apitypes.TypedData{}, err
}
var aminoDoc legacytx.StdSignDoc var aminoDoc legacytx.StdSignDoc
if err := aminoCodec.UnmarshalJSON(signDocBytes, &aminoDoc); err != nil { if err := aminoCodec.UnmarshalJSON(signDocBytes, &aminoDoc); err != nil {
return apitypes.TypedData{}, err return apitypes.TypedData{}, err
@ -134,6 +139,11 @@ func decodeAminoSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
// decodeProtobufSignDoc attempts to decode the provided sign doc (bytes) as a Protobuf payload // decodeProtobufSignDoc attempts to decode the provided sign doc (bytes) as a Protobuf payload
// and returns a signable EIP-712 TypedData object. // and returns a signable EIP-712 TypedData object.
func decodeProtobufSignDoc(signDocBytes []byte) (apitypes.TypedData, error) { func decodeProtobufSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
// Ensure codecs have been initialized
if err := validateCodecInit(); err != nil {
return apitypes.TypedData{}, err
}
signDoc := &txTypes.SignDoc{} signDoc := &txTypes.SignDoc{}
if err := signDoc.Unmarshal(signDocBytes); err != nil { if err := signDoc.Unmarshal(signDocBytes); err != nil {
return apitypes.TypedData{}, err return apitypes.TypedData{}, err
@ -220,6 +230,16 @@ func decodeProtobufSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
return typedData, nil return typedData, nil
} }
// validateCodecInit ensures that both Amino and Protobuf encoding codecs have been set on app init,
// so the module does not panic if either codec is not found.
func validateCodecInit() error {
if aminoCodec == nil || protoCodec == nil {
return errors.New("missing codec: codecs have not been properly initialized using SetEncodingConfig")
}
return nil
}
// validatePayloadMessages ensures that the transaction messages can be represented in an EIP-712 // validatePayloadMessages ensures that the transaction messages can be represented in an EIP-712
// encoding by checking that messages exist, are of the same type, and share a single signer. // encoding by checking that messages exist, are of the same type, and share a single signer.
func validatePayloadMessages(msgs []sdk.Msg) error { func validatePayloadMessages(msgs []sdk.Msg) error {