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

Commit

Permalink
Merge branch 'main' into austinchandra/ENG-1161
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze authored Dec 9, 2022
2 parents 363d907 + e1de07d commit d6cab45
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions crypto/ethsecp256k1/ethsecp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 5 additions & 6 deletions ethereum/eip712/eip712_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
Expand Down
16 changes: 5 additions & 11 deletions ethereum/eip712/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ schema = 3
version = "v1.0.0"
hash = "sha256-k1DYvCqO3BKNcGEve/nMW0RxzMkK2tGfXbUbycqcVSo="
[mod."github.com/ethereum/go-ethereum"]
version = "v1.10.25"
hash = "sha256-tNlI2XyuTXjGuBoe5vlYDcaGN2Sub7yltVtI6TeLLSc="
version = "v1.10.26"
hash = "sha256-gkMEwJ4rOgn12amD4QpZ4th/10uyTTeoFmpseuKDQPs="
[mod."github.com/felixge/httpsnoop"]
version = "v1.0.1"
hash = "sha256-TNXnnC/ZGNY9lInAcES1cBGqIdEljKuh5LH/khVFjVk="
Expand Down Expand Up @@ -512,8 +512,8 @@ schema = 3
version = "v0.2.0"
hash = "sha256-azcllZ0o/9TurqX9udaJ0o9yxqSoI0/bSJsvQQLYIQc="
[mod."golang.org/x/text"]
version = "v0.4.0"
hash = "sha256-JvyMygdmTvWg7xhbnUB9MMk6WcYXJt8DAj4DYl82Pys="
version = "v0.5.0"
hash = "sha256-ztH+xQyM/clOcQl+y/UEPcfNKbc3xApMbEPDDZ9up0o="
[mod."golang.org/x/xerrors"]
version = "v0.0.0-20220907171357-04be3eba64a2"
hash = "sha256-6+zueutgefIYmgXinOflz8qGDDDj0Zhv+2OkGhBTKno="
Expand Down
21 changes: 12 additions & 9 deletions tests/integration_tests/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/integration_tests/test_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,4 @@ def test_block_gas_limit(ethermint):
)
(ethermint.w3.eth.wait_for_transaction_receipt(ethermint_txhash))


return
3 changes: 3 additions & 0 deletions tests/integration_tests/test_grpc_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def grpc_eth_call(port: int, args: dict, chain_id=None, proposer_address=None):
).json()


@pytest.mark.skip(
reason="undeterministic test - https://github.com/evmos/ethermint/issues/1530"
)
def test_grpc_mode(custom_ethermint):
"""
- restart a fullnode in grpc-only mode
Expand Down

0 comments on commit d6cab45

Please sign in to comment.