From 45e90dc4c10120ac0f52b1490e62167870277c97 Mon Sep 17 00:00:00 2001 From: Simone Date: Tue, 3 Jan 2023 15:13:14 +0100 Subject: [PATCH 1/2] Fix top level struct parsing --- slither/solc_parsing/slither_compilation_unit_solc.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/slither/solc_parsing/slither_compilation_unit_solc.py b/slither/solc_parsing/slither_compilation_unit_solc.py index d12bda1b4..6dce9b005 100644 --- a/slither/solc_parsing/slither_compilation_unit_solc.py +++ b/slither/solc_parsing/slither_compilation_unit_solc.py @@ -24,6 +24,7 @@ from slither.solc_parsing.declarations.function import FunctionSolc from slither.solc_parsing.declarations.structure_top_level import StructureTopLevelSolc from slither.solc_parsing.exceptions import VariableNotFound from slither.solc_parsing.variables.top_level_variable import TopLevelVariableSolc +from slither.solc_parsing.declarations.caller_context import CallerContextExpression logging.basicConfig() logger = logging.getLogger("SlitherSolcParsing") @@ -57,7 +58,7 @@ def _handle_import_aliases( scope.renaming[local_name] = original_name -class SlitherCompilationUnitSolc: +class SlitherCompilationUnitSolc(CallerContextExpression): # pylint: disable=no-self-use,too-many-instance-attributes def __init__(self, compilation_unit: SlitherCompilationUnit): super().__init__() @@ -95,6 +96,10 @@ class SlitherCompilationUnitSolc: def underlying_contract_to_parser(self) -> Dict[Contract, ContractSolc]: return self._underlying_contract_to_parser + @property + def slither_parser(self) -> "SlitherCompilationUnitSolc": + return self + ################################################################################### ################################################################################### # region AST From 680c914ded73e5b221f9df903da8050ed4756ce7 Mon Sep 17 00:00:00 2001 From: Simone Date: Tue, 3 Jan 2023 15:29:20 +0100 Subject: [PATCH 2/2] Add test --- ...p-level-struct-0.8.0.sol-0.8.0-compact.zip | Bin 0 -> 2027 bytes ...-level-struct-0.8.0.sol-0.8.0-compact.json | 3 +++ tests/ast-parsing/top-level-struct-0.8.0.sol | 18 ++++++++++++++++++ tests/test_ast_parsing.py | 1 + 4 files changed, 22 insertions(+) create mode 100644 tests/ast-parsing/compile/top-level-struct-0.8.0.sol-0.8.0-compact.zip create mode 100644 tests/ast-parsing/expected/top-level-struct-0.8.0.sol-0.8.0-compact.json create mode 100644 tests/ast-parsing/top-level-struct-0.8.0.sol diff --git a/tests/ast-parsing/compile/top-level-struct-0.8.0.sol-0.8.0-compact.zip b/tests/ast-parsing/compile/top-level-struct-0.8.0.sol-0.8.0-compact.zip new file mode 100644 index 0000000000000000000000000000000000000000..7cb2fb659609b654a99a51480f172e7555306ef0 GIT binary patch literal 2027 zcmb8wX&}>$0|)TmOq&+TP087uZRT+;(#n)GH1bq)#GH%Sm>IciEFO|0w~0i}BM~i+ z5|X2sBg7OUDrb(c9RHsG`~Qpo_xs}e>ihcRU;`G!00O{4AR~ z005{#WJG{B%{u@QLJbZjP!T938i_)N1O>Qz)5$@>RCkYHf}cOl8%YcaBJCI42e<-2 zEC84?nZA14dX#(pJ@qCc1#KjMc#{Gn1$X$A;&8|dY29_~sZ`z(53#8)oRtI4MYq>2 z53g41;1+YTEz1v$yr)tMNkWb9u$51%tmmZPmi(CbvDy*U;=X`4g>g*HFQ!P>F$C}} z4wvS9({^#fNLRHNdF?mr(!ztp2Su!Sz3vlPj-3-%Z^9%z0X7U{vU)iQ^1BD6Kt;yaqh?RTYzFae;%GnYvxX8eOb6W0#j^oXNfb?OX7+8d|ed1N-B z-0BW|icHqLExr(z{k5EzB`|%Yz+CL+OX#y%gT3)rT=Brq+;6%fJqm-FgYhHFL-Fw0 zM_@U$|A*uUWA)8#ABNkLpktOys1l=IZvIol2{#0aWSbPFt?_pgyXKU?QGU zw|ciCJNKd6^eVG0Hu(xY?e{A9Z$j&Ck-BbP&q3y#AZ zEHuA#oeJA4Dr(iWwOq@m9q%W-wIwvB59Z4WuSy&R*LQ09*yD~R!gxD%^9#LHRA~3v zptY+*q(4EC+7Se|zs}z=tzSf^JzQ({yuE)S^@)KOpA}s=G5O%AYTEe|Nnh6-&m z#c1Y9eDix&4K2#U9`@bQ(*ZX0;9IaoJFHxIZK{Cv`}Q>*TZ}2~amOmm6fuBZsN(MG z+zQ|0@?m3nfl69}_BglaYNy*xvL?2FIbkKT-tbSoEL)B-Fd%B|kL{l_R$BfQ`{{cr zUuIg|r}to3bqIX)*WJ1YVSzd!DvMcvKZtm-yf-{p-jYR%+JpoiAmWdWnDe&bX9z}7 zT#V}VC>}@`5+k*|+F$Jyu1*^t>YDLGy@WC$yZ8M>jIOMu0K02sC-0XGA)xk9J^F+I zcsR18=RD1EtN99=(=CI`(2Ne>8~u6Gjh^|~Mr^UmA50sU=`0O>A^t3Z4>;HI@{ z1*A)IuB0oIXPsGY(=cRr^l6wdEV*@1CtDbSkqX_=jNvD1!EseMyrpa!MBA8wt^OW;F45L#Q|HJ zT{5%NC|#p$_twRpPuY`$c))Coclw-KSsBeQj76kaKB0Z<>;3m3FJnQL?iTFj@7#3szYSzmtA#%^x1R1!rC`7jzNRW<$;#+sL*Q z9*%iT&j?gK7qQlE$bY`nW-gBh*b_ZdJ)VKAVAn4By{qw;>CCReKa=fw=o*#0kI^Ci zN#!F9Llw3e!JW@1xVN3tOI!zU<3~l~L<2nqEtDwgUa#!QGqJi;=})b93`F9fO~NI;X5&ELI4UToDpZjmk0;Ol^%KN}}U}5i`2|qb6Px;g2tLD%bRZ zdKZdwyd74DshduessvR9PV5dvs(j9feS8Tna>EJ%@0!2JZGVA)0JEabjL|&&-j7Ev pYYsLb0Sx$m)B9WB|0Wjn@BDudJJ{@l{QCm^uFLNY|4ljo{09_{xwZfR literal 0 HcmV?d00001 diff --git a/tests/ast-parsing/expected/top-level-struct-0.8.0.sol-0.8.0-compact.json b/tests/ast-parsing/expected/top-level-struct-0.8.0.sol-0.8.0-compact.json new file mode 100644 index 000000000..65dfd3b51 --- /dev/null +++ b/tests/ast-parsing/expected/top-level-struct-0.8.0.sol-0.8.0-compact.json @@ -0,0 +1,3 @@ +{ + "BaseContract": {} +} \ No newline at end of file diff --git a/tests/ast-parsing/top-level-struct-0.8.0.sol b/tests/ast-parsing/top-level-struct-0.8.0.sol new file mode 100644 index 000000000..8a335680c --- /dev/null +++ b/tests/ast-parsing/top-level-struct-0.8.0.sol @@ -0,0 +1,18 @@ +struct my_struct { + uint[][] a; // works fine + uint[][3] b; // works fine + uint[3][] c; // fails + uint[3][3] d; // fails + uint[2**20] e; // works fine +} +contract BaseContract{ + struct my_struct_2 { + uint[][] f; // works fine + uint[][3] g; // works fine + uint[3][] h; // works fine + uint[3][3] i; // works fine + uint[2**20] j; // works fine + } + + uint[3][] k; // works fine +} diff --git a/tests/test_ast_parsing.py b/tests/test_ast_parsing.py index e96a129b8..47f230534 100644 --- a/tests/test_ast_parsing.py +++ b/tests/test_ast_parsing.py @@ -425,6 +425,7 @@ ALL_TESTS = [ Test("free_functions/library_constant_function_collision.sol", ["0.8.12"]), Test("ternary-with-max.sol", ["0.8.15"]), Test("library_event-0.8.16.sol", ["0.8.16"]), + Test("top-level-struct-0.8.0.sol", ["0.8.0"]), ] # create the output folder if needed try: