Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
4f4a25d7
Unverified
Commit
4f4a25d7
authored
Jan 20, 2023
by
Martin Holst Swende
Committed by
GitHub
Jan 20, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
signer/core: don't require capital lettered reference types (#26462)
parent
50e65392
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
160 additions
and
21 deletions
+160
-21
types.go
signer/core/apitypes/types.go
+10
-21
signed_data_test.go
signer/core/signed_data_test.go
+150
-0
No files found.
signer/core/apitypes/types.go
View file @
4f4a25d7
...
...
@@ -27,8 +27,6 @@ import (
"sort"
"strconv"
"strings"
"unicode"
"unicode/utf8"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -38,7 +36,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
)
var
typedDataReferenceTypeRegexp
=
regexp
.
MustCompile
(
`^[A-Z](\w*)(\[\])?$`
)
var
typedDataReferenceTypeRegexp
=
regexp
.
MustCompile
(
`^[A-Z
a-z
](\w*)(\[\])?$`
)
type
ValidationInfo
struct
{
Typ
string
`json:"type"`
...
...
@@ -224,15 +222,6 @@ func (t *Type) typeName() string {
return
t
.
Type
}
func
(
t
*
Type
)
isReferenceType
()
bool
{
if
len
(
t
.
Type
)
==
0
{
return
false
}
// Reference types must have a leading uppercase character
r
,
_
:=
utf8
.
DecodeRuneInString
(
t
.
Type
)
return
unicode
.
IsUpper
(
r
)
}
type
Types
map
[
string
][]
Type
type
TypePriority
struct
{
...
...
@@ -731,15 +720,15 @@ func (t Types) validate() error {
if
typeKey
==
typeObj
.
Type
{
return
fmt
.
Errorf
(
"type %q cannot reference itself"
,
typeObj
.
Type
)
}
if
typeObj
.
isReferenceType
(
)
{
if
_
,
exist
:=
t
[
typeObj
.
typeName
()];
!
exist
{
return
fmt
.
Errorf
(
"reference type %q is undefined"
,
typeObj
.
Type
)
}
if
!
typedDataReferenceTypeRegexp
.
MatchString
(
typeObj
.
Type
)
{
return
fmt
.
Errorf
(
"unknown reference type %q
"
,
typeObj
.
Type
)
}
}
else
if
!
isPrimitiveTypeValid
(
typeObj
.
Type
)
{
return
fmt
.
Errorf
(
"unknown type %q"
,
typeObj
.
Type
)
if
isPrimitiveTypeValid
(
typeObj
.
Type
)
{
continue
}
// Must be reference type
if
_
,
exist
:=
t
[
typeObj
.
typeName
()];
!
exist
{
return
fmt
.
Errorf
(
"reference type %q is undefined
"
,
typeObj
.
Type
)
}
if
!
typedDataReferenceTypeRegexp
.
MatchString
(
typeObj
.
Type
)
{
return
fmt
.
Errorf
(
"unknown
reference
type %q"
,
typeObj
.
Type
)
}
}
}
...
...
signer/core/signed_data_test.go
View file @
4f4a25d7
...
...
@@ -848,3 +848,153 @@ func TestGnosisSafe(t *testing.T) {
t
.
Fatal
(
"expected equality"
)
}
}
var
complexTypedDataLCRefType
=
`
{
"types": {
"EIP712Domain": [
{
"name": "chainId",
"type": "uint256"
},
{
"name": "name",
"type": "string"
},
{
"name": "verifyingContract",
"type": "address"
},
{
"name": "version",
"type": "string"
}
],
"Action": [
{
"name": "action",
"type": "string"
},
{
"name": "params",
"type": "string"
}
],
"cCell": [
{
"name": "capacity",
"type": "string"
},
{
"name": "lock",
"type": "string"
},
{
"name": "type",
"type": "string"
},
{
"name": "data",
"type": "string"
},
{
"name": "extraData",
"type": "string"
}
],
"Transaction": [
{
"name": "DAS_MESSAGE",
"type": "string"
},
{
"name": "inputsCapacity",
"type": "string"
},
{
"name": "outputsCapacity",
"type": "string"
},
{
"name": "fee",
"type": "string"
},
{
"name": "action",
"type": "Action"
},
{
"name": "inputs",
"type": "cCell[]"
},
{
"name": "outputs",
"type": "cCell[]"
},
{
"name": "digest",
"type": "bytes32"
}
]
},
"primaryType": "Transaction",
"domain": {
"chainId": "56",
"name": "da.systems",
"verifyingContract": "0x0000000000000000000000000000000020210722",
"version": "1"
},
"message": {
"DAS_MESSAGE": "SELL mobcion.bit FOR 100000 CKB",
"inputsCapacity": "1216.9999 CKB",
"outputsCapacity": "1216.9998 CKB",
"fee": "0.0001 CKB",
"digest": "0x53a6c0f19ec281604607f5d6817e442082ad1882bef0df64d84d3810dae561eb",
"action": {
"action": "start_account_sale",
"params": "0x00"
},
"inputs": [
{
"capacity": "218 CKB",
"lock": "das-lock,0x01,0x051c152f77f8efa9c7c6d181cc97ee67c165c506...",
"type": "account-cell-type,0x01,0x",
"data": "{ account: mobcion.bit, expired_at: 1670913958 }",
"extraData": "{ status: 0, records_hash: 0x55478d76900611eb079b22088081124ed6c8bae21a05dd1a0d197efcc7c114ce }"
}
],
"outputs": [
{
"capacity": "218 CKB",
"lock": "das-lock,0x01,0x051c152f77f8efa9c7c6d181cc97ee67c165c506...",
"type": "account-cell-type,0x01,0x",
"data": "{ account: mobcion.bit, expired_at: 1670913958 }",
"extraData": "{ status: 1, records_hash: 0x55478d76900611eb079b22088081124ed6c8bae21a05dd1a0d197efcc7c114ce }"
},
{
"capacity": "201 CKB",
"lock": "das-lock,0x01,0x051c152f77f8efa9c7c6d181cc97ee67c165c506...",
"type": "account-sale-cell-type,0x01,0x",
"data": "0x1209460ef3cb5f1c68ed2c43a3e020eec2d9de6e...",
"extraData": ""
}
]
}
}
`
func
TestComplexTypedDataWithLowercaseReftype
(
t
*
testing
.
T
)
{
var
td
apitypes
.
TypedData
err
:=
json
.
Unmarshal
([]
byte
(
complexTypedDataLCRefType
),
&
td
)
if
err
!=
nil
{
t
.
Fatalf
(
"unmarshalling failed '%v'"
,
err
)
}
_
,
sighash
,
err
:=
sign
(
td
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
expSigHash
:=
common
.
FromHex
(
"0x49191f910874f0148597204d9076af128d4694a7c4b714f1ccff330b87207bff"
)
if
!
bytes
.
Equal
(
expSigHash
,
sighash
)
{
t
.
Fatalf
(
"Error, got %x, wanted %x"
,
sighash
,
expSigHash
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment