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

Refactor EIP-712 signature verification #1397

Merged
merged 40 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7611743
[WIP] EIP-712 Signature Refactor
0a1c Oct 19, 2022
aeda1cf
Merge branch 'main' of https://github.com/evmos/ethermint into austin…
0a1c Oct 20, 2022
e4e8650
Debug and add ante tests
0a1c Oct 20, 2022
afc37f6
Add tests for failure cases
0a1c Oct 21, 2022
57fe441
Add changelog entry
0a1c Oct 21, 2022
998987a
Code cleanup
0a1c Oct 24, 2022
578185c
Add tests for MsgDelegate and MsgWithdrawDelegationReward
0a1c Oct 25, 2022
e941c8e
Update ethereum/eip712/encoding.go
0a1c Oct 25, 2022
14c4cd7
Update ethereum/eip712/encoding.go
0a1c Oct 25, 2022
84f061a
Update ethereum/eip712/encoding.go
0a1c Oct 25, 2022
e93c95e
Update ethereum/eip712/encoding.go
0a1c Oct 25, 2022
e711f77
Update ethereum/eip712/encoding.go
0a1c Oct 25, 2022
e97298f
Update ethereum/eip712/encoding.go
0a1c Oct 25, 2022
8f6f63b
Code cleanup
0a1c Oct 25, 2022
876876b
Update ethereum/eip712/encoding.go
0a1c Oct 26, 2022
6b0481f
Minor codefix
0a1c Oct 26, 2022
b8cb5a4
Merge branch 'main' into austin/ENG-891
0a1c Oct 26, 2022
e08c6af
Update ethereum/eip712/encoding.go
fedekunze Oct 26, 2022
74548b7
Minor code revision updates
0a1c Oct 28, 2022
36ea28f
Refactor EIP712 unit tests to use test suite
0a1c Oct 28, 2022
6a7cd65
Merge branch 'main' into austin/ENG-891
facs95 Oct 31, 2022
d91ea3a
update branch
facs95 Oct 31, 2022
13e91de
Address import cycle and implement minor refactors
0a1c Oct 31, 2022
386a019
Fix lint issues
0a1c Oct 31, 2022
3ef98c8
Add EIP712 unit suite test function
0a1c Oct 31, 2022
5003d85
Update ethereum/eip712/encoding.go
0a1c Nov 1, 2022
13a0f4d
Update ethereum/eip712/encoding.go
0a1c Nov 1, 2022
cdba1ee
Update ethereum/eip712/encoding.go
0a1c Nov 1, 2022
f16265a
Add minor refactors; increase test coverage
0a1c Nov 1, 2022
3a5a525
Correct ante_test for change in payload
0a1c Nov 1, 2022
e93b3db
Add single-signer util and tests
0a1c Nov 1, 2022
47e224c
Update ethereum/eip712/encoding.go
fedekunze Nov 2, 2022
1c075c8
Update ethereum/eip712/encoding.go
fedekunze Nov 2, 2022
f795487
Merge branch 'main' into austin/ENG-891
fedekunze Nov 2, 2022
2b7486e
fix build
facs95 Nov 2, 2022
e4795a2
Merge branch 'main' into austin/ENG-891
facs95 Nov 2, 2022
c265a66
Merge branch 'main' into austin/ENG-891
facs95 Nov 3, 2022
a61c40f
Remove reflect import
0a1c Nov 3, 2022
658ed26
Merge branch 'austin/ENG-891' of https://github.com/evmos/ethermint i…
0a1c Nov 3, 2022
be34c8c
Merge branch 'main' into austin/ENG-891
fedekunze Nov 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [#1378](https://github.com/evmos/ethermint/pull/1378) Add support for EVM RPC metrics
* (ante) [#1390](https://github.com/evmos/ethermint/pull/1390) Added multisig tx support.
* (test) [#1396](https://github.com/evmos/ethermint/pull/1396) Increase test coverage for the EVM module `keeper`
* (ante) [#1397](https://github.com/evmos/ethermint/pull/1397) Refactor EIP-712 signature verification to support EIP-712 multi-signing.
* (deps) [#1416](https://github.com/evmos/ethermint/pull/1416) Bump Go version to `1.19`
* (cmd) [\#1417](https://github.com/evmos/ethermint/pull/1417) Apply Google CLI Syntax for required and optional args.

Expand Down
298 changes: 297 additions & 1 deletion app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
evmtypes "github.com/evmos/ethermint/x/evm/types"

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

func (suite AnteTestSuite) TestAnteHandler() {
Expand Down Expand Up @@ -507,6 +508,301 @@ func (suite AnteTestSuite) TestAnteHandler() {
return tx
}, true, false, false,
},
{
"passes - Single-signer EIP-712",
func() sdk.Tx {
msg := banktypes.NewMsgSend(
sdk.AccAddress(privKey.PubKey().Address()),
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSingleSignedTx(
privKey,
signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
msg,
"ethermint_9000-1",
2000000,
"EIP-712",
)

return txBuilder.GetTx()
}, false, false, true,
},
{
"passes - EIP-712 multi-key",
func() sdk.Tx {
numKeys := 5
privKeys, pubKeys := suite.GenerateMultipleKeys(numKeys)
pk := kmultisig.NewLegacyAminoPubKey(numKeys, pubKeys)

msg := banktypes.NewMsgSend(
sdk.AccAddress(pk.Address()),
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
msg,
"ethermint_9000-1",
2000000,
"EIP-712",
)

return txBuilder.GetTx()
}, false, false, true,
},
{
"passes - Mixed multi-key",
func() sdk.Tx {
numKeys := 5
privKeys, pubKeys := suite.GenerateMultipleKeys(numKeys)
pk := kmultisig.NewLegacyAminoPubKey(numKeys, pubKeys)

msg := banktypes.NewMsgSend(
sdk.AccAddress(pk.Address()),
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
msg,
"ethermint_9000-1",
2000000,
"mixed", // Combine EIP-712 and standard signatures
)

return txBuilder.GetTx()
}, false, false, true,
},
{
"passes - Mixed multi-key with MsgVote",
func() sdk.Tx {
numKeys := 5
privKeys, pubKeys := suite.GenerateMultipleKeys(numKeys)
pk := kmultisig.NewLegacyAminoPubKey(numKeys, pubKeys)

msg := govtypes.NewMsgVote(
sdk.AccAddress(pk.Address()),
1,
govtypes.OptionYes,
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
msg,
"ethermint_9000-1",
2000000,
"mixed", // Combine EIP-712 and standard signatures
)

return txBuilder.GetTx()
}, false, false, true,
},
{
"Fails - Multi-Key with incorrect Chain ID",
func() sdk.Tx {
numKeys := 5
privKeys, pubKeys := suite.GenerateMultipleKeys(numKeys)
pk := kmultisig.NewLegacyAminoPubKey(numKeys, pubKeys)

msg := banktypes.NewMsgSend(
sdk.AccAddress(pk.Address()),
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
msg,
"ethermint_9005-1",
2000000,
"mixed",
)

return txBuilder.GetTx()
}, false, false, false,
},
{
"Fails - Multi-Key with incorrect sign mode",
func() sdk.Tx {
numKeys := 5
privKeys, pubKeys := suite.GenerateMultipleKeys(numKeys)
pk := kmultisig.NewLegacyAminoPubKey(numKeys, pubKeys)

msg := banktypes.NewMsgSend(
sdk.AccAddress(pk.Address()),
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_DIRECT,
msg,
"ethermint_9000-1",
2000000,
"mixed",
)

return txBuilder.GetTx()
}, false, false, false,
},
{
"Fails - Multi-Key with too little gas",
func() sdk.Tx {
numKeys := 5
privKeys, pubKeys := suite.GenerateMultipleKeys(numKeys)
pk := kmultisig.NewLegacyAminoPubKey(numKeys, pubKeys)

msg := banktypes.NewMsgSend(
sdk.AccAddress(pk.Address()),
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_DIRECT,
msg,
"ethermint_9000-1",
2000,
"mixed", // Combine EIP-712 and standard signatures
)

return txBuilder.GetTx()
}, false, false, false,
},
{
"Fails - Multi-Key with different payload than one signed",
func() sdk.Tx {
numKeys := 1
privKeys, pubKeys := suite.GenerateMultipleKeys(numKeys)
pk := kmultisig.NewLegacyAminoPubKey(numKeys, pubKeys)

msg := banktypes.NewMsgSend(
sdk.AccAddress(pk.Address()),
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_DIRECT,
msg,
"ethermint_9000-1",
2000,
"EIP-712",
)

msg.Amount[0].Amount = sdk.NewInt(5)
txBuilder.SetMsgs(msg)

return txBuilder.GetTx()
}, false, false, false,
},
{
"Fails - Multi-Key with messages added after signing",
func() sdk.Tx {
numKeys := 1
privKeys, pubKeys := suite.GenerateMultipleKeys(numKeys)
pk := kmultisig.NewLegacyAminoPubKey(numKeys, pubKeys)

msg := banktypes.NewMsgSend(
sdk.AccAddress(pk.Address()),
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSignedMultisigTx(
privKeys,
signing.SignMode_SIGN_MODE_DIRECT,
msg,
"ethermint_9000-1",
2000,
"EIP-712",
)

// Duplicate
txBuilder.SetMsgs(msg, msg)

return txBuilder.GetTx()
}, false, false, false,
},
{
"Fails - Single-Signer EIP-712 with messages added after signing",
func() sdk.Tx {
msg := banktypes.NewMsgSend(
sdk.AccAddress(privKey.PubKey().Address()),
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"photon",
sdk.NewInt(1),
),
),
)

txBuilder := suite.CreateTestSingleSignedTx(
privKey,
signing.SignMode_SIGN_MODE_DIRECT,
msg,
"ethermint_9000-1",
2000,
"EIP-712",
)

txBuilder.SetMsgs(msg, msg)

return txBuilder.GetTx()
}, false, false, false,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -939,7 +1235,7 @@ func (suite *AnteTestSuite) TestConsumeSignatureVerificationGas() {
multisigKey1 := kmultisig.NewLegacyAminoPubKey(2, pkSet1)
multisignature1 := multisig.NewMultisig(len(pkSet1))
expectedCost1 := expectedGasCostByKeys(pkSet1)

for i := 0; i < len(pkSet1); i++ {
stdSig := legacytx.StdSignature{PubKey: pkSet1[i], Signature: sigSet1[i]}
sigV2, err := legacytx.StdSignatureToSignatureV2(cdc, stdSig)
Expand Down
Loading