diff --git a/app/ante/utils_test.go b/app/ante/utils_test.go index cc682c1145..838ad63f7f 100644 --- a/app/ante/utils_test.go +++ b/app/ante/utils_test.go @@ -568,7 +568,7 @@ func (suite *AnteTestSuite) generateSingleSignature(signMode signing.SignMode, p msg = signDocBytes if signType == "EIP-712" { - msg, err = eip712.GetEIP712HashForMsg(signDocBytes) + msg, err = eip712.GetEIP712BytesForMsg(signDocBytes) suite.Require().NoError(err) } diff --git a/crypto/ethsecp256k1/ethsecp256k1.go b/crypto/ethsecp256k1/ethsecp256k1.go index 2dad73dc0b..379f8bd4b8 100644 --- a/crypto/ethsecp256k1/ethsecp256k1.go +++ b/crypto/ethsecp256k1/ethsecp256k1.go @@ -213,15 +213,15 @@ func (pubKey PubKey) VerifySignature(msg, sig []byte) bool { } // Verifies the signature as an EIP-712 signature by first converting the message payload -// to an EIP-712 hashed object, performing ECDSA verification on the hash. This is to support +// to EIP-712 object bytes, then performing ECDSA verification on the hash. This is to support // signing a Cosmos payload using EIP-712. func (pubKey PubKey) verifySignatureAsEIP712(msg, sig []byte) bool { - eip712Hash, err := eip712.GetEIP712HashForMsg(msg) + eip712Bytes, err := eip712.GetEIP712BytesForMsg(msg) if err != nil { return false } - return pubKey.verifySignatureECDSA(eip712Hash, sig) + return pubKey.verifySignatureECDSA(eip712Bytes, sig) } // Perform standard ECDSA signature verification for the given raw bytes and signature. diff --git a/ethereum/eip712/eip712_test.go b/ethereum/eip712/eip712_test.go index 46b906e33d..8d78c4d910 100644 --- a/ethereum/eip712/eip712_test.go +++ b/ethereum/eip712/eip712_test.go @@ -400,18 +400,17 @@ func (suite *EIP712TestSuite) TestEIP712SignatureVerification() { // Verify that the payload passes signature verification if signed as its EIP-712 representation. func (suite *EIP712TestSuite) verifyEIP712SignatureVerification(expectedSuccess bool, privKey ethsecp256k1.PrivKey, pubKey ethsecp256k1.PubKey, signBytes []byte) { - // Convert to EIP712 hash and sign - eip712Hash, err := eip712.GetEIP712HashForMsg(signBytes) + // Convert to EIP712 bytes and sign + eip712Bytes, err := eip712.GetEIP712BytesForMsg(signBytes) if !expectedSuccess { - // Expect failure generating EIP-712 hash + // Expect failure generating EIP-712 bytes suite.Require().Error(err) return } suite.Require().NoError(err) - sigHash := crypto.Keccak256Hash(eip712Hash) - sig, err := privKey.Sign(sigHash.Bytes()) + sig, err := privKey.Sign(eip712Bytes) suite.Require().NoError(err) // Verify against original payload bytes. This should pass, even though it is not @@ -420,7 +419,7 @@ func (suite *EIP712TestSuite) verifyEIP712SignatureVerification(expectedSuccess suite.Require().True(res) // Verify against the signed EIP-712 bytes. This should pass, since it is the message signed. - res = pubKey.VerifySignature(eip712Hash, sig) + res = pubKey.VerifySignature(eip712Bytes, sig) suite.Require().True(res) // Verify against random bytes to ensure it does not pass unexpectedly (sanity check). diff --git a/ethereum/eip712/encoding.go b/ethereum/eip712/encoding.go index fa744ad74a..f8ff5de465 100644 --- a/ethereum/eip712/encoding.go +++ b/ethereum/eip712/encoding.go @@ -36,27 +36,21 @@ func SetEncodingConfig(cfg params.EncodingConfig) { protoCodec = codec.NewProtoCodec(cfg.InterfaceRegistry) } -// Get the EIP-712 object hash for the given SignDoc bytes by first decoding the bytes into +// Get the EIP-712 object bytes for the given SignDoc bytes by first decoding the bytes into // an EIP-712 object, then hashing the EIP-712 object to create the bytes to be signed. // See https://eips.ethereum.org/EIPS/eip-712 for more. -func GetEIP712HashForMsg(signDocBytes []byte) ([]byte, error) { +func GetEIP712BytesForMsg(signDocBytes []byte) ([]byte, error) { typedData, err := GetEIP712TypedDataForMsg(signDocBytes) if err != nil { return nil, err } - domainSeparator, err := typedData.HashStruct("EIP712Domain", typedData.Domain.Map()) + _, rawData, err := apitypes.TypedDataAndHash(typedData) if err != nil { - return nil, fmt.Errorf("could not hash EIP-712 domain: %w", err) + return nil, fmt.Errorf("could not get EIP-712 object bytes: %w", err) } - typedDataHash, err := typedData.HashStruct(typedData.PrimaryType, typedData.Message) - if err != nil { - return nil, fmt.Errorf("could not hash EIP-712 primary type: %w", err) - } - rawData := []byte(fmt.Sprintf("\x19\x01%s%s", string(domainSeparator), string(typedDataHash))) - - return rawData, nil + return []byte(rawData), nil } // GetEIP712TypedDataForMsg returns the EIP-712 TypedData representation for either