Skip to content

Commit 33524d7

Browse files
dafernaholiman
authored andcommittedJun 6, 2023
signer/core: accept all solidity primitive types for EIP-712 signing (ethereum#26770)
Accept all primitive types in Solidity for EIP-712 from intN, uintN, intN[], uintN[] for N as 0 to 256 in multiples of 8 --------- Co-authored-by: Martin Holst Swende <martin@swende.se>
1 parent 31663eb commit 33524d7

File tree

2 files changed

+60
-102
lines changed

2 files changed

+60
-102
lines changed
 

‎signer/core/apitypes/types.go

+20-102
Original file line numberDiff line numberDiff line change
@@ -742,112 +742,30 @@ func isPrimitiveTypeValid(primitiveType string) bool {
742742
primitiveType == "bool" ||
743743
primitiveType == "bool[]" ||
744744
primitiveType == "string" ||
745-
primitiveType == "string[]" {
746-
return true
747-
}
748-
if primitiveType == "bytes" ||
745+
primitiveType == "string[]" ||
746+
primitiveType == "bytes" ||
749747
primitiveType == "bytes[]" ||
750-
primitiveType == "bytes1" ||
751-
primitiveType == "bytes1[]" ||
752-
primitiveType == "bytes2" ||
753-
primitiveType == "bytes2[]" ||
754-
primitiveType == "bytes3" ||
755-
primitiveType == "bytes3[]" ||
756-
primitiveType == "bytes4" ||
757-
primitiveType == "bytes4[]" ||
758-
primitiveType == "bytes5" ||
759-
primitiveType == "bytes5[]" ||
760-
primitiveType == "bytes6" ||
761-
primitiveType == "bytes6[]" ||
762-
primitiveType == "bytes7" ||
763-
primitiveType == "bytes7[]" ||
764-
primitiveType == "bytes8" ||
765-
primitiveType == "bytes8[]" ||
766-
primitiveType == "bytes9" ||
767-
primitiveType == "bytes9[]" ||
768-
primitiveType == "bytes10" ||
769-
primitiveType == "bytes10[]" ||
770-
primitiveType == "bytes11" ||
771-
primitiveType == "bytes11[]" ||
772-
primitiveType == "bytes12" ||
773-
primitiveType == "bytes12[]" ||
774-
primitiveType == "bytes13" ||
775-
primitiveType == "bytes13[]" ||
776-
primitiveType == "bytes14" ||
777-
primitiveType == "bytes14[]" ||
778-
primitiveType == "bytes15" ||
779-
primitiveType == "bytes15[]" ||
780-
primitiveType == "bytes16" ||
781-
primitiveType == "bytes16[]" ||
782-
primitiveType == "bytes17" ||
783-
primitiveType == "bytes17[]" ||
784-
primitiveType == "bytes18" ||
785-
primitiveType == "bytes18[]" ||
786-
primitiveType == "bytes19" ||
787-
primitiveType == "bytes19[]" ||
788-
primitiveType == "bytes20" ||
789-
primitiveType == "bytes20[]" ||
790-
primitiveType == "bytes21" ||
791-
primitiveType == "bytes21[]" ||
792-
primitiveType == "bytes22" ||
793-
primitiveType == "bytes22[]" ||
794-
primitiveType == "bytes23" ||
795-
primitiveType == "bytes23[]" ||
796-
primitiveType == "bytes24" ||
797-
primitiveType == "bytes24[]" ||
798-
primitiveType == "bytes25" ||
799-
primitiveType == "bytes25[]" ||
800-
primitiveType == "bytes26" ||
801-
primitiveType == "bytes26[]" ||
802-
primitiveType == "bytes27" ||
803-
primitiveType == "bytes27[]" ||
804-
primitiveType == "bytes28" ||
805-
primitiveType == "bytes28[]" ||
806-
primitiveType == "bytes29" ||
807-
primitiveType == "bytes29[]" ||
808-
primitiveType == "bytes30" ||
809-
primitiveType == "bytes30[]" ||
810-
primitiveType == "bytes31" ||
811-
primitiveType == "bytes31[]" ||
812-
primitiveType == "bytes32" ||
813-
primitiveType == "bytes32[]" {
814-
return true
815-
}
816-
if primitiveType == "int" ||
748+
primitiveType == "int" ||
817749
primitiveType == "int[]" ||
818-
primitiveType == "int8" ||
819-
primitiveType == "int8[]" ||
820-
primitiveType == "int16" ||
821-
primitiveType == "int16[]" ||
822-
primitiveType == "int32" ||
823-
primitiveType == "int32[]" ||
824-
primitiveType == "int64" ||
825-
primitiveType == "int64[]" ||
826-
primitiveType == "int96" ||
827-
primitiveType == "int96[]" ||
828-
primitiveType == "int128" ||
829-
primitiveType == "int128[]" ||
830-
primitiveType == "int256" ||
831-
primitiveType == "int256[]" {
750+
primitiveType == "uint" ||
751+
primitiveType == "uint[]" {
832752
return true
833753
}
834-
if primitiveType == "uint" ||
835-
primitiveType == "uint[]" ||
836-
primitiveType == "uint8" ||
837-
primitiveType == "uint8[]" ||
838-
primitiveType == "uint16" ||
839-
primitiveType == "uint16[]" ||
840-
primitiveType == "uint32" ||
841-
primitiveType == "uint32[]" ||
842-
primitiveType == "uint64" ||
843-
primitiveType == "uint64[]" ||
844-
primitiveType == "uint96" ||
845-
primitiveType == "uint96[]" ||
846-
primitiveType == "uint128" ||
847-
primitiveType == "uint128[]" ||
848-
primitiveType == "uint256" ||
849-
primitiveType == "uint256[]" {
850-
return true
754+
// For 'bytesN', 'bytesN[]', we allow N from 1 to 32
755+
for n := 1; n <= 32; n++ {
756+
// e.g. 'bytes28' or 'bytes28[]'
757+
if primitiveType == fmt.Sprintf("bytes%d", n) || primitiveType == fmt.Sprintf("bytes%d[]", n) {
758+
return true
759+
}
760+
}
761+
// For 'intN','intN[]' and 'uintN','uintN[]' we allow N in increments of 8, from 8 up to 256
762+
for n := 8; n <= 256; n += 8 {
763+
if primitiveType == fmt.Sprintf("int%d", n) || primitiveType == fmt.Sprintf("int%d[]", n) {
764+
return true
765+
}
766+
if primitiveType == fmt.Sprintf("uint%d", n) || primitiveType == fmt.Sprintf("uint%d[]", n) {
767+
return true
768+
}
851769
}
852770
return false
853771
}

‎signer/core/apitypes/types_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2023 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package apitypes
18+
19+
import "testing"
20+
21+
func TestIsPrimitive(t *testing.T) {
22+
// Expected positives
23+
for i, tc := range []string{
24+
"int24", "int24[]", "uint88", "uint88[]", "uint", "uint[]", "int256", "int256[]",
25+
"uint96", "uint96[]", "int96", "int96[]", "bytes17[]", "bytes17",
26+
} {
27+
if !isPrimitiveTypeValid(tc) {
28+
t.Errorf("test %d: expected '%v' to be a valid primitive", i, tc)
29+
}
30+
}
31+
// Expected negatives
32+
for i, tc := range []string{
33+
"int257", "int257[]", "uint88 ", "uint88 []", "uint257", "uint-1[]",
34+
"uint0", "uint0[]", "int95", "int95[]", "uint1", "uint1[]", "bytes33[]", "bytess",
35+
} {
36+
if isPrimitiveTypeValid(tc) {
37+
t.Errorf("test %d: expected '%v' to not be a valid primitive", i, tc)
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)