-
Notifications
You must be signed in to change notification settings - Fork 79
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
Conversation
Codecov ReportBase: 52.81% // Head: 52.97% // Increases project coverage by
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
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. |
There was a problem hiding this 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", |
There was a problem hiding this comment.
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
cluster/cluster_internal_test.go
Outdated
@@ -28,21 +28,25 @@ import ( | |||
) | |||
|
|||
func TestDefinitionVerify(t *testing.T) { | |||
forkVersion := "0x80000069" |
There was a problem hiding this comment.
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
5d7463d
to
a34724b
Compare
cluster/helpers.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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
cluster/helpers.go
Outdated
} | ||
|
||
// eip712Digest returns the EIP712 digest of the input data. | ||
func eip712Digest(signerData apitypes.TypedData) ([32]byte, error) { |
There was a problem hiding this comment.
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
cluster/helpers.go
Outdated
|
||
// configHashDigest returns the EIP712 digest of the config hash. | ||
func configHashDigest(configHash string, chainID int64) ([32]byte, error) { | ||
signer := eip712SignerData(chainID) |
There was a problem hiding this comment.
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
cluster/helpers.go
Outdated
// 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 { |
There was a problem hiding this comment.
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_internal_test.go
Outdated
@@ -68,3 +68,16 @@ func TestVerifySig(t *testing.T) { | |||
require.True(t, ok) | |||
}) | |||
} | |||
|
|||
func TestForkVersionToChainID(t *testing.T) { | |||
gnosisForkVersion := []byte{0, 0, 0, 100} |
There was a problem hiding this comment.
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?
cluster/helpers.go
Outdated
return 100, nil | ||
case "0x80000069": // Ropsten | ||
return 3, nil | ||
case "0x90000069": // Sepolia |
There was a problem hiding this comment.
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
cluster/helpers.go
Outdated
// Fork version of sepolia testnet. | ||
sepoliaForkVersion = "0x90000069" | ||
// EIP712 values. | ||
configHashPrimaryType = "ConfigHash" |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the constant
There was a problem hiding this comment.
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
Refactor
EIP712 Domain
data to add support for different chains ids.category: refactor
ticket: #1203