Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit 3b2f9fc

Browse files
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>
1 parent e1de07d commit 3b2f9fc

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
9090

9191
### Bug Fixes
9292

93+
* (eip712) [#1543](https://github.com/evmos/ethermint/pull/1543) Improve error handling for EIP-712 encoding config initialization.
9394
* (app) [#1505](https://github.com/evmos/ethermint/pull/1505) Setup gRPC node service with the application.
9495
* (server) [#1497](https://github.com/evmos/ethermint/pull/1497) Fix telemetry server setup for observability
9596
* (rpc) [#1442](https://github.com/evmos/ethermint/pull/1442) Fix decoding of `finalized` block number.

app/app.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import (
104104
_ "github.com/evmos/ethermint/client/docs/statik"
105105

106106
"github.com/evmos/ethermint/app/ante"
107+
"github.com/evmos/ethermint/ethereum/eip712"
107108
srvflags "github.com/evmos/ethermint/server/flags"
108109
ethermint "github.com/evmos/ethermint/types"
109110
"github.com/evmos/ethermint/x/evm"
@@ -252,6 +253,8 @@ func NewEthermintApp(
252253
cdc := encodingConfig.Amino
253254
interfaceRegistry := encodingConfig.InterfaceRegistry
254255

256+
eip712.SetEncodingConfig(encodingConfig)
257+
255258
// NOTE we use custom transaction decoder that supports the sdk.Tx interface instead of sdk.StdTx
256259
bApp := baseapp.NewBaseApp(
257260
appName,

ethereum/eip712/encoding.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ func isValidEIP712Payload(typedData apitypes.TypedData) bool {
7979
// decodeAminoSignDoc attempts to decode the provided sign doc (bytes) as an Amino payload
8080
// and returns a signable EIP-712 TypedData object.
8181
func decodeAminoSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
82+
// Ensure codecs have been initialized
83+
if err := validateCodecInit(); err != nil {
84+
return apitypes.TypedData{}, err
85+
}
86+
8287
var aminoDoc legacytx.StdSignDoc
8388
if err := aminoCodec.UnmarshalJSON(signDocBytes, &aminoDoc); err != nil {
8489
return apitypes.TypedData{}, err
@@ -134,6 +139,11 @@ func decodeAminoSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
134139
// decodeProtobufSignDoc attempts to decode the provided sign doc (bytes) as a Protobuf payload
135140
// and returns a signable EIP-712 TypedData object.
136141
func decodeProtobufSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
142+
// Ensure codecs have been initialized
143+
if err := validateCodecInit(); err != nil {
144+
return apitypes.TypedData{}, err
145+
}
146+
137147
signDoc := &txTypes.SignDoc{}
138148
if err := signDoc.Unmarshal(signDocBytes); err != nil {
139149
return apitypes.TypedData{}, err
@@ -220,6 +230,16 @@ func decodeProtobufSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
220230
return typedData, nil
221231
}
222232

233+
// validateCodecInit ensures that both Amino and Protobuf encoding codecs have been set on app init,
234+
// so the module does not panic if either codec is not found.
235+
func validateCodecInit() error {
236+
if aminoCodec == nil || protoCodec == nil {
237+
return errors.New("missing codec: codecs have not been properly initialized using SetEncodingConfig")
238+
}
239+
240+
return nil
241+
}
242+
223243
// validatePayloadMessages ensures that the transaction messages can be represented in an EIP-712
224244
// encoding by checking that messages exist, are of the same type, and share a single signer.
225245
func validatePayloadMessages(msgs []sdk.Msg) error {

0 commit comments

Comments
 (0)