Skip to content

Commit 194db7f

Browse files
authored
fix: support fixed-size array dimensions in signature parser (#278)
The Lark grammar only handled dynamic arrays (`[]`) but rejected fixed-size arrays (`[N]`), causing lint failures on valid Solidity types like `address[11]` and `uint256[5][5]`. Made-with: Cursor
1 parent 31481dc commit 194db7f

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/erc7730/common/abi.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
named_param: type identifier?
2323
named_tuple: tuple array* identifier?
2424
25-
array: "[]"
25+
array: "[]" | "[" /[0-9]+/ "]"
2626
identifier: /[a-zA-Z$_][a-zA-Z0-9$_]*/
2727
type: identifier array*
2828
@@ -61,8 +61,8 @@ def named_tuple(self, ast: Any) -> Component:
6161

6262
# Separate arrays from name
6363
# Arrays are "[]", name is anything else
64-
arrays = [elem for elem in ast[1:] if elem == "[]"]
65-
names = [elem for elem in ast[1:] if elem != "[]"]
64+
arrays = [elem for elem in ast[1:] if isinstance(elem, str) and elem.startswith("[")]
65+
names = [elem for elem in ast[1:] if not (isinstance(elem, str) and elem.startswith("["))]
6666

6767
# Build type with array suffixes
6868
type_str = "tuple" + "".join(arrays)
@@ -73,6 +73,8 @@ def named_tuple(self, ast: Any) -> Component:
7373
return Component(name=name, type=type_str, components=components)
7474

7575
def array(self, ast: Any) -> str:
76+
if ast:
77+
return f"[{ast[0]}]"
7678
return "[]"
7779

7880
def identifier(self, ast: Any) -> str:

tests/common/test_abi.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,31 @@
6767
"mixed(bytes32[][] data, (address a,uint256 b)[][] _tuples, string name)",
6868
"mixed(bytes32[][],(address,uint256)[][],string)",
6969
),
70+
# fixed-size arrays
71+
(
72+
"exchange(address[11] _route, uint256[5][5] _swap_params, uint256 _amount, uint256 _min_dy)",
73+
"exchange(address[11],uint256[5][5],uint256,uint256)",
74+
),
75+
# fixed-size array single dimension
76+
(
77+
"foo(uint256[3] values)",
78+
"foo(uint256[3])",
79+
),
80+
# mixed fixed and dynamic arrays
81+
(
82+
"bar(address[5] addrs, uint256[] amounts, bytes32[2][] pairs)",
83+
"bar(address[5],uint256[],bytes32[2][])",
84+
),
85+
# fixed-size array of tuples
86+
(
87+
"baz((uint256,address)[3] items)",
88+
"baz((uint256,address)[3])",
89+
),
90+
# higher-dimensional fixed-size arrays
91+
(
92+
"multi(uint256[2][3][4] cube)",
93+
"multi(uint256[2][3][4])",
94+
),
7095
],
7196
)
7297
def test_reduce_signature(signature: str, expected: str) -> None:

0 commit comments

Comments
 (0)