Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster: refactor EIP712 domain data #1169

Merged
merged 8 commits into from
Oct 3, 2022
Merged

Conversation

xenowits
Copy link
Contributor

@xenowits xenowits commented Sep 26, 2022

Refactor EIP712 Domain data to add support for different chains ids.

category: refactor
ticket: #1203

@codecov
Copy link

codecov bot commented Sep 26, 2022

Codecov Report

Base: 52.81% // Head: 52.97% // Increases project coverage by +0.15% 🎉

Coverage data is based on head (576f5ca) compared to base (fad6f93).
Patch coverage: 72.72% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1169      +/-   ##
==========================================
+ Coverage   52.81%   52.97%   +0.15%     
==========================================
  Files         133      134       +1     
  Lines       15648    15860     +212     
==========================================
+ Hits         8265     8402     +137     
- Misses       6187     6230      +43     
- Partials     1196     1228      +32     
Impacted Files Coverage Δ
cluster/definition.go 53.35% <50.00%> (-0.43%) ⬇️
cluster/helpers.go 62.65% <73.21%> (-2.31%) ⬇️
cluster/test_cluster.go 86.95% <100.00%> (+0.34%) ⬆️
p2p/sender.go 43.95% <0.00%> (-12.95%) ⬇️
core/consensus/msg.go 53.97% <0.00%> (-7.64%) ⬇️
core/consensus/transport.go 56.09% <0.00%> (-4.96%) ⬇️
core/consensus/component.go 50.23% <0.00%> (-3.42%) ⬇️
core/scheduler/scheduler.go 73.13% <0.00%> (-0.40%) ⬇️
app/retry/retry.go 76.56% <0.00%> (-0.19%) ⬇️
... and 7 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@xenowits
Copy link
Contributor Author

Copy link
Contributor

@corverroos corverroos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks backwards compatibility with previous signatures.

Also, you are not only changing the chainID, you are also changing name and salt. We said that the DV launchpad is going to sign like charon does, then we are going to get product to come up a proper next iteration.

Lets rather hold off on this until we know what the plan is, how we are going to do backwards compatibility stuff, etc.

@@ -165,14 +163,14 @@ func digestEIP712(address string, message []byte, nonce int) ([32]byte, error) {
},
PrimaryType: "Challenge",
Domain: apitypes.TypedDataDomain{
Name: "ETHChallenger",
Name: "Obol",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these structure changes for now

@@ -28,21 +28,25 @@ import (
)

func TestDefinitionVerify(t *testing.T) {
forkVersion := "0x80000069"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make these constants in helpers.go

@@ -191,6 +174,68 @@ func digestEIP712(address string, message []byte, nonce int) ([32]byte, error) {
return crypto.Keccak256Hash(rawData), nil
}

// configHashSig returns the EIP712 (https://eips.ethereum.org/EIPS/eip-712) signature of the config hash.
func configHashSig(secret *ecdsa.PrivateKey, configHash string, chainID int64) ([]byte, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add tests for these new functions in the next PR

}

// eip712Digest returns the EIP712 digest of the input data.
func eip712Digest(signerData apitypes.TypedData) ([32]byte, error) {
Copy link
Contributor

@corverroos corverroos Sep 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can replace eip712Digest function with apitypes.TypedDataAndHash


// configHashDigest returns the EIP712 digest of the config hash.
func configHashDigest(configHash string, chainID int64) ([32]byte, error) {
signer := eip712SignerData(chainID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't a signer, it is more data

// See reference https://medium.com/alpineintel/issuing-and-verifying-eip-712-challenges-with-go-32635ca78aaf.
func digestEIP712(address string, message []byte, nonce int) ([32]byte, error) {
// eip712SignerData returns an EIP712 structured data containing the signing domain and the required types.
func eip712SignerData(chainID int64) apitypes.TypedData {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not replace multiple functions with just a single function:

// digestEIP712 returns an EIP712 structured data containing the signing domain and the required types.
func digestEIP712(primaryType, fieldName, fieldValue string, chainID int64) ([]byte, error) {
    data := apitypes.TypedData{
        Types: apitypes.Types{
            "EIP712Domain": []apitypes.Type{
                {Name: "name", Type: "string"},
                {Name: "version", Type: "string"},
                {Name: "chainId", Type: "uint256"},
            },
            primaryType: []apitypes.Type{
                {Name: fieldName, Type: "string"},
            },
        },
        PrimaryType: primaryType,
        Message: apitypes.TypedDataMessage{
            fieldName: fieldValue,
        },
        Domain: apitypes.TypedDataDomain{
            Name:    "Obol",
            Version: "1",
            ChainId: ethmath.NewHexOrDecimal256(chainID),
        },
    }

    resp, _ , err := apitypes.TypedDataAndHash(data)

    return resp, err
}

cluster/helpers.go Outdated Show resolved Hide resolved
@@ -68,3 +68,16 @@ func TestVerifySig(t *testing.T) {
require.True(t, ok)
})
}

func TestForkVersionToChainID(t *testing.T) {
gnosisForkVersion := []byte{0, 0, 0, 100}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use sepolia or make this a constant?

return 100, nil
case "0x80000069": // Ropsten
return 3, nil
case "0x90000069": // Sepolia
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest make these all constants

// Fork version of sepolia testnet.
sepoliaForkVersion = "0x90000069"
// EIP712 values.
configHashPrimaryType = "ConfigHash"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest identical prefixes:

eip712TypeConfigHash = "ConfigHash"
eip712FieldConfigHash = "config_hash"
eip712TypeENR = "ENR"
eip712FieldENR = "enr"

Copy link
Contributor

@corverroos corverroos Oct 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another option would be to make this a type, this couples the two things better:

type eip712Type struct {
  PrimaryType string
  Field string
}

var (
  eip712TypeConfigHash = eip712Type {"ConfigHash","config_hash}
  eip712TypeENR = eip712Type {"ENR","enr}
)

func signEIP712(secret *ecdsa.PrivateKey, typ eip712Type, fieldValue string, chainID int64) ([]byte, error) {

@@ -44,7 +44,7 @@ func TestEncode(t *testing.T) {
3,
testutil.RandomETHAddress(),
testutil.RandomETHAddress(),
"0x00000002",
"0x90000069", // Sepolia testnet.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the constant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will raise a PR to combine network chainID, name and forkVersion and replace relevant constants across the codebase

@xenowits xenowits self-assigned this Oct 3, 2022
@xenowits xenowits added the merge when ready Indicates bulldozer bot may merge when all checks pass label Oct 3, 2022
@obol-bulldozer obol-bulldozer bot merged commit 9486b6d into main Oct 3, 2022
@obol-bulldozer obol-bulldozer bot deleted the xenowits/fix-eip712-domain branch October 3, 2022 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge when ready Indicates bulldozer bot may merge when all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants