Skip to content

Commit b2b14e6

Browse files
authored
signer/core: EIP-712 encoded data should not reject a Domain without a ChainId (#21306)
* Do not check for a non-nil ChainId * Add encoding test
1 parent 290d6bd commit b2b14e6

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

signer/core/signed_data.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,11 +965,7 @@ func isPrimitiveTypeValid(primitiveType string) bool {
965965
// validate checks if the given domain is valid, i.e. contains at least
966966
// the minimum viable keys and values
967967
func (domain *TypedDataDomain) validate() error {
968-
if domain.ChainId == nil {
969-
return errors.New("chainId must be specified according to EIP-155")
970-
}
971-
972-
if len(domain.Name) == 0 && len(domain.Version) == 0 && len(domain.VerifyingContract) == 0 && len(domain.Salt) == 0 {
968+
if domain.ChainId == nil && len(domain.Name) == 0 && len(domain.Version) == 0 && len(domain.VerifyingContract) == 0 && len(domain.Salt) == 0 {
973969
return errors.New("domain is undefined")
974970
}
975971

signer/core/signed_data_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ func TestDomainChainId(t *testing.T) {
245245
if _, ok := withoutChainID.Domain.Map()["chainId"]; ok {
246246
t.Errorf("Expected the chainId key to not be present in the domain map")
247247
}
248+
// should encode successfully
249+
if _, err := withoutChainID.HashStruct("EIP712Domain", withoutChainID.Domain.Map()); err != nil {
250+
t.Errorf("Expected the typedData to encode the domain successfully, got %v", err)
251+
}
248252
withChainID := core.TypedData{
249253
Types: core.Types{
250254
"EIP712Domain": []core.Type{
@@ -261,6 +265,10 @@ func TestDomainChainId(t *testing.T) {
261265
if _, ok := withChainID.Domain.Map()["chainId"]; !ok {
262266
t.Errorf("Expected the chainId key be present in the domain map")
263267
}
268+
// should encode successfully
269+
if _, err := withChainID.HashStruct("EIP712Domain", withChainID.Domain.Map()); err != nil {
270+
t.Errorf("Expected the typedData to encode the domain successfully, got %v", err)
271+
}
264272
}
265273

266274
func TestHashStruct(t *testing.T) {

0 commit comments

Comments
 (0)