From f88e8e550c35e57b6726f4d932df0a8cb06e2079 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 8 Nov 2023 15:58:05 +0100 Subject: [PATCH 01/20] Remove file level functions and variable from namespace rewrite --- .../contracts/test/NamespacedToModify.sol | 10 ++ .../core/src/utils/make-namespaced.test.ts.md | 12 +- .../src/utils/make-namespaced.test.ts.snap | Bin 1013 -> 957 bytes packages/core/src/utils/make-namespaced.ts | 103 ++++++++++-------- 4 files changed, 79 insertions(+), 46 deletions(-) diff --git a/packages/core/contracts/test/NamespacedToModify.sol b/packages/core/contracts/test/NamespacedToModify.sol index 91863fc3b..2f58391cf 100644 --- a/packages/core/contracts/test/NamespacedToModify.sol +++ b/packages/core/contracts/test/NamespacedToModify.sol @@ -83,6 +83,8 @@ library Lib { } contract Consumer { + bytes4 public variableFromConstant = CONSTANT_USING_SELECTOR; + function usingFreeFunction() pure public returns (bytes4) { return FreeFunctionUsingSelector(); } @@ -100,6 +102,14 @@ function plusTwo(uint x) pure returns (uint) { return x + 2; } +function plusThree(uint x) pure returns (uint) { + return x + 3; +} + +function plusThree(uint x, uint y) pure returns (uint) { + return x + y + 3; +} + using {plusTwo} for uint; contract UsingForDirectives { diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index bdcf08b29..fb58ca41d 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -82,9 +82,9 @@ Generated by [AVA](https://avajs.dev). ␊ }␊ ␊ - uint256 constant FreeFunctionUsingSelector = 0;␊ ␊ - uint256 constant CONSTANT_USING_SELECTOR = 0;␊ + ␊ + ␊ ␊ library Lib {␊ ␊ @@ -98,9 +98,15 @@ Generated by [AVA](https://avajs.dev). ␊ ␊ ␊ + ␊ + ␊ }␊ ␊ - uint256 constant plusTwo = 0;␊ + ␊ + ␊ + ␊ + ␊ + ␊ ␊ ␊ ␊ diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index 760ce4135a3d057f59ab08d0d02979f71be5092b..6c4b4427684b62003263d0564828f274cd037173 100644 GIT binary patch literal 957 zcmV;u148^kRzV%^(g@6Mefw$w0yFv(U`@J{sy_xskR0&%t=61o4C}&jJHG06en%c7ltW{4@IMbkfqn)00%eb(?2X3H)YS;}r<0SD7Mie-W1#|I>@TBP<`~NP zgl~jogZ4M-!e<`ST?-vW=m}`-a}?E@@eO4-uM(VbB|_;^6&d8b1;z)U!zg8pJ#0)4 z*=GP!OT%&_HrwVvh6V>75^c=_c9%-S`Xj+Ah)_e=>eL4fOmL$C8Q7l**hyD#Es3jD zMN_3K*ZW~#7i+>}&2Cu<-#GLd#NGg9?Ubd?h(jj;QcT0fMquXw@?9EsXfMBq?rNNJ z((tKg)^;Jq9g`tfW-(@OTM4(XW(IDf*v(PN*p&*d-(3E_w8~t{6)mlJ zz-CQG-wiCj+#x~Rr}$nT!>EA9B{x)B1Pky1 zaaw}sPog`*RJ!xE>e&U_6DbFTaU-R)3_;Zztm{3YSY0$i#&zx6Iow$s+3NPTHismq z6N?`u;hqS<-U!$G>^)7I(XIC;_sl`Kv4}VGv3IydU6-`r@EOuzWy)RQ(V5tunE`Vu z>El$fh)eh^d{5zD8eMpa-_-gt)lRcnEG{MuN_-Q*3m#Put=iNbaRtBz zL=4IkF`_a%+Y8-nLI-fMsZ24evQJ<(6L)=$s4F2i31==SpW@$AP&oPsrbYz-9Sxr~ zB#~Xb${M}>w5Cgft1zH)z)hfbN9tT5mzj*p!5yj+T1|FK$c_%sqf9CvGyBw`r-O8| z%*M-9enEo&4O{Pb6=p6bkgEo*!*6&i4PZ!L;^oFpod2!TgngeSKhqsm}LX%nk^?1(E8jK18=oF2j%detvV+DUpba_9H``cVi8z!Qbm9| fBSqjh*!tZ$pa?t%zzgT!Dgqw?A?YJ@V+sHO1GmA3 literal 1013 zcmVRzV{cK`<{7tTHP?Rc|Z?nLN5ZOnuSf}V3z^%Ru*>ZsJti6YMOG= z^{HpZb|s^ok|9@SFl9fmQfdEO7^jWq4;7Q1qurof$76fPX*6*A`s(|&4dzm=Xl>mC zHR~}dm++tiN7wHJ8if!;Qsj`y?3n6yGUh_!{8xiW@2|f+c9c zoYvs_ljw{vmF{Azd0~l;OzHt)+*m0sLvXbTykb!K1aH&PPr>QIv2+?H&&iY z=XkDK#Wj2Z+L!UC-67n>i><__x!>zmtIO$tQmxrfE;O7Ega^s^f=BG3)quLWQ~+#1 z#GpJ8BO3Gbqph1y`2a08%oM8{$85|&>a5=(>RQOngEI$I&ggd(5J!SwDsKSj!@~os zC>o8gNlFh<#>41U3yI&r(N)VCtZZ+!J6E?lyF2amt+#jEYa44To$YsHxX-$h$RXZf z-O-xaC|AHw7*ILZ9v9ib4^`*3h#lt=6>^oyh<`q&Dz%iMli%Pu{t5D^kRgD=F~m1h zOx~|$CR)YG2Mvt!9!z~$j2#xPN=b&}UZqkopj!aAodHcxfXap%o{gv>S-~MnAFY{* z-|+?+0_nz8Y#$$4#^9O*SGc%YU(8oD=fVH7qVenjYc3`=?RPMI z2vRz^rkw}Kt0&jAHvzKxpVhR#?5D12Us_LF)8MYw7l42NS(-EZ|AJ##XF+Pt6OzCc jCqn|%$&tWUF!i-_0tx&GfS;Uyiv%766wNAS)CvFq$ Date: Wed, 8 Nov 2023 16:04:15 +0100 Subject: [PATCH 02/20] lint --- packages/core/src/utils/make-namespaced.ts | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/core/src/utils/make-namespaced.ts b/packages/core/src/utils/make-namespaced.ts index 532c73720..ea530f560 100644 --- a/packages/core/src/utils/make-namespaced.ts +++ b/packages/core/src/utils/make-namespaced.ts @@ -45,7 +45,7 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI for (const node of output.sources[sourcePath].ast.nodes) { switch (node.nodeType) { - case 'ContractDefinition': + case 'ContractDefinition': { const contractDef = node; // Remove any calls to parent constructors from the inheritance list @@ -59,21 +59,21 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI const contractNodes = contractDef.nodes; for (const contractNode of contractNodes) { - switch(contractNode.nodeType) { + switch (contractNode.nodeType) { case 'FunctionDefinition': case 'ModifierDefinition': - case 'VariableDeclaration': + case 'VariableDeclaration': { if (contractNode.documentation) { modifications.push(makeDelete(contractNode.documentation, orig)); } modifications.push(makeDelete(contractNode, orig)); break; - - case 'UsingForDirective': + } + case 'UsingForDirective': { modifications.push(makeDelete(contractNode, orig)); break; - - case 'StructDefinition': + } + case 'StructDefinition': { const storageLocation = getStorageLocationAnnotation(contractNode); if (storageLocation !== undefined) { const structName = contractNode.name; @@ -83,30 +83,33 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI modifications.push(makeInsertAfter(contractNode, insertText)); } break; - + } case 'EnumDefinition': case 'ErrorDefinition': case 'EventDefinition': - case 'UserDefinedValueTypeDefinition': + case 'UserDefinedValueTypeDefinition': { // nothing break; + } } } break; - + } case 'FunctionDefinition': case 'UsingForDirective': - case 'VariableDeclaration': + case 'VariableDeclaration': { modifications.push(makeDelete(node, orig)); break; - + } case 'EnumDefinition': case 'ErrorDefinition': case 'ImportDirective': case 'PragmaDirective': case 'StructDefinition': - case 'UserDefinedValueTypeDefinition': + case 'UserDefinedValueTypeDefinition': { + // nothing break; + } } } From 2af8660e78397d5e46bd5860eb0e2a1839195d4d Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 8 Nov 2023 16:10:31 +0100 Subject: [PATCH 03/20] up --- packages/core/src/utils/make-namespaced.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/core/src/utils/make-namespaced.ts b/packages/core/src/utils/make-namespaced.ts index ea530f560..fd9be1aaa 100644 --- a/packages/core/src/utils/make-namespaced.ts +++ b/packages/core/src/utils/make-namespaced.ts @@ -60,6 +60,8 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI const contractNodes = contractDef.nodes; for (const contractNode of contractNodes) { switch (contractNode.nodeType) { + case 'ErrorDefinition': + case 'EventDefinition': case 'FunctionDefinition': case 'ModifierDefinition': case 'VariableDeclaration': { @@ -85,16 +87,15 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI break; } case 'EnumDefinition': - case 'ErrorDefinition': - case 'EventDefinition': case 'UserDefinedValueTypeDefinition': { - // nothing + // keep: it may be used in structures with storage locations break; } } } break; } + case 'ErrorDefinition': case 'FunctionDefinition': case 'UsingForDirective': case 'VariableDeclaration': { @@ -102,12 +103,15 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI break; } case 'EnumDefinition': - case 'ErrorDefinition': case 'ImportDirective': case 'PragmaDirective': case 'StructDefinition': case 'UserDefinedValueTypeDefinition': { - // nothing + // - EnumDefinition may be used in structures with storage locations + // - ImportDirective may import types used in structures with storage locations + // - PragmaDirective is necessary for compilation + // - StructDefinition may be used in structures with storage locations + // - UserDefinedValueTypeDefinition may be used in structures with storage locations break; } } From 66f197699e9212dea083ac0bb38abc2f8cdb1f2a Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 8 Nov 2023 17:04:24 +0100 Subject: [PATCH 04/20] add default cases --- packages/core/src/utils/make-namespaced.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/core/src/utils/make-namespaced.ts b/packages/core/src/utils/make-namespaced.ts index fd9be1aaa..a7f2bb9fe 100644 --- a/packages/core/src/utils/make-namespaced.ts +++ b/packages/core/src/utils/make-namespaced.ts @@ -87,31 +87,29 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI break; } case 'EnumDefinition': - case 'UserDefinedValueTypeDefinition': { - // keep: it may be used in structures with storage locations + case 'UserDefinedValueTypeDefinition': + default: { + // - EnumDefinition may be used in structures with storage locations + // - UserDefinedValueTypeDefinition may be used in structures with storage locations + // - default: in case unexpected ast nodes show up break; } } } break; } - case 'ErrorDefinition': - case 'FunctionDefinition': - case 'UsingForDirective': - case 'VariableDeclaration': { - modifications.push(makeDelete(node, orig)); - break; - } case 'EnumDefinition': case 'ImportDirective': case 'PragmaDirective': case 'StructDefinition': - case 'UserDefinedValueTypeDefinition': { + case 'UserDefinedValueTypeDefinition': + default: { // - EnumDefinition may be used in structures with storage locations // - ImportDirective may import types used in structures with storage locations // - PragmaDirective is necessary for compilation // - StructDefinition may be used in structures with storage locations // - UserDefinedValueTypeDefinition may be used in structures with storage locations + // - default: in case unexpected ast nodes show up (file-level events since 0.8.22) break; } } From 02645046b1d2b961b35d2ba043735e959a8aae6f Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Wed, 8 Nov 2023 12:01:22 -0500 Subject: [PATCH 05/20] Add test for importing free fn and constant --- packages/core/contracts/test/NamespacedToModifyImported.sol | 6 ++++++ packages/core/src/utils/make-namespaced.test.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 packages/core/contracts/test/NamespacedToModifyImported.sol diff --git a/packages/core/contracts/test/NamespacedToModifyImported.sol b/packages/core/contracts/test/NamespacedToModifyImported.sol new file mode 100644 index 000000000..afc07ecc8 --- /dev/null +++ b/packages/core/contracts/test/NamespacedToModifyImported.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +import {CONSTANT_USING_SELECTOR, plusTwo} from "./NamespacedToModify.sol"; + +contract Example {} \ No newline at end of file diff --git a/packages/core/src/utils/make-namespaced.test.ts b/packages/core/src/utils/make-namespaced.test.ts index da02b8418..95a1c8b85 100644 --- a/packages/core/src/utils/make-namespaced.test.ts +++ b/packages/core/src/utils/make-namespaced.test.ts @@ -12,7 +12,7 @@ import { SolcInput, SolcOutput } from '../solc-api'; import { BuildInfo } from 'hardhat/types'; test('make namespaced input', async t => { - const origBuildInfo = await artifacts.getBuildInfo('contracts/test/NamespacedToModify.sol:Example'); + const origBuildInfo = await artifacts.getBuildInfo('contracts/test/NamespacedToModifyImported.sol:Example'); await testMakeNamespaced(origBuildInfo, t, '0.8.20'); }); From 0a49f9b1331ed66ffcb099956727fc809d6540d5 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Wed, 8 Nov 2023 12:03:01 -0500 Subject: [PATCH 06/20] Add overloaded import --- packages/core/contracts/test/NamespacedToModifyImported.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/contracts/test/NamespacedToModifyImported.sol b/packages/core/contracts/test/NamespacedToModifyImported.sol index afc07ecc8..594bba0de 100644 --- a/packages/core/contracts/test/NamespacedToModifyImported.sol +++ b/packages/core/contracts/test/NamespacedToModifyImported.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import {CONSTANT_USING_SELECTOR, plusTwo} from "./NamespacedToModify.sol"; +import {CONSTANT_USING_SELECTOR, plusTwo, plusThree} from "./NamespacedToModify.sol"; contract Example {} \ No newline at end of file From 6fbc54fba7926492a0b2d753fd82ae44d3a230c5 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Fri, 24 Nov 2023 14:51:55 -0500 Subject: [PATCH 07/20] Replace errors, free fns, vars with dummy variable --- .../contracts/test/NamespacedToModify.sol | 12 +++++- .../test/NamespacedToModifyImported.sol | 6 ++- .../core/src/utils/make-namespaced.test.ts.md | 36 +++++++++--------- .../src/utils/make-namespaced.test.ts.snap | Bin 1245 -> 1218 bytes packages/core/src/utils/make-namespaced.ts | 17 +++++++++ 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/packages/core/contracts/test/NamespacedToModify.sol b/packages/core/contracts/test/NamespacedToModify.sol index ad33b703e..88a15bf80 100644 --- a/packages/core/contracts/test/NamespacedToModify.sol +++ b/packages/core/contracts/test/NamespacedToModify.sol @@ -61,6 +61,11 @@ contract Example { * @notice some natspec */ function foo4() public {} + + /** + * @dev a custom error inside a contract + */ + error CustomErrorInsideContract(address a); } contract HasFunction { @@ -124,4 +129,9 @@ contract UsingForDirectives { function usingFor(uint x) pure public returns (uint) { return x.plusOne() + x.plusTwo(); } -} \ No newline at end of file +} + +/** + * @dev a custom error outside a contract + */ +error CustomErrorOutsideContract(address a); \ No newline at end of file diff --git a/packages/core/contracts/test/NamespacedToModifyImported.sol b/packages/core/contracts/test/NamespacedToModifyImported.sol index 594bba0de..b3f5301ca 100644 --- a/packages/core/contracts/test/NamespacedToModifyImported.sol +++ b/packages/core/contracts/test/NamespacedToModifyImported.sol @@ -1,6 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import {CONSTANT_USING_SELECTOR, plusTwo, plusThree} from "./NamespacedToModify.sol"; +import {CONSTANT_USING_SELECTOR, plusTwo, plusThree, CustomErrorOutsideContract} from "./NamespacedToModify.sol"; -contract Example {} \ No newline at end of file +contract Example { + using {plusTwo} for uint; +} \ No newline at end of file diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index 111e17859..715a2aff6 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -78,6 +78,9 @@ Generated by [AVA](https://avajs.dev). ␊ ␊ ␊ + ␊ + ␊ + ␊ }␊ ␊ contract HasFunction {␊ @@ -89,11 +92,9 @@ Generated by [AVA](https://avajs.dev). ␊ }␊ ␊ - function FreeFunctionUsingSelector() pure returns (bytes4) {␊ - return HasFunction.foo.selector;␊ - }␊ + uint256 constant FreeFunctionUsingSelector = 0;␊ ␊ - bytes4 constant CONSTANT_USING_SELECTOR = HasFunction.foo.selector;␊ + uint256 constant CONSTANT_USING_SELECTOR = 0;␊ ␊ library Lib {␊ ␊ @@ -111,33 +112,34 @@ Generated by [AVA](https://avajs.dev). ␊ }␊ ␊ - function plusTwo(uint x) pure returns (uint) {␊ - return x + 2;␊ - }␊ + uint256 constant plusTwo = 0;␊ ␊ - function plusThree(uint x) pure returns (uint) {␊ - return x + 3;␊ - }␊ + uint256 constant plusThree = 0;␊ + ␊ + uint256 constant plusThree = 0;␊ ␊ - function plusThree(uint x, uint y) pure returns (uint) {␊ - return x + y + 3;␊ - }␊ ␊ - using {plusTwo} for uint;␊ ␊ contract UsingForDirectives {␊ ␊ ␊ ␊ - }`, + }␊ + ␊ + /**␊ + * @dev a custom error outside a contract␊ + */␊ + uint256 constant CustomErrorOutsideContract = 0;`, }, 'contracts/test/NamespacedToModifyImported.sol': { content: `// SPDX-License-Identifier: MIT␊ pragma solidity ^0.8.20;␊ ␊ - import {CONSTANT_USING_SELECTOR, plusTwo, plusThree} from "./NamespacedToModify.sol";␊ + import {CONSTANT_USING_SELECTOR, plusTwo, plusThree, CustomErrorOutsideContract} from "./NamespacedToModify.sol";␊ ␊ - contract Example {}`, + contract Example {␊ + ␊ + }`, }, }, } diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index 52c8007f5fb4d81a3f655b2e61ca6988b75438e7..1be1b4b6bbd6844542b08fa45457de832e305064 100644 GIT binary patch literal 1218 zcmV;z1U>sfRzVkRNqs zWd+$#(_ND-)7>>xRmU0QtmwgmCr_dv$ciV=UR1<`f{Q2dv{%8?dJ*y9(bv^IGd
  • N!q9+I$qlEIh`6@t~Fg{8`^O@WWZ3b>hHIU`g#{C|D^5yI?U-a%@Ral|;zu&LB(;w#{tX>Q)4El-i3iwQ{D~ zrrTy*5<64}hjc*wCXA1bghR}v?~E@2@@*0}k%IjUkUL4(R0{S5T&k~f30NT&1tSrK z9Px0|A-0+u#e{T%`<_sf3FEe=4Cu;BpX7&L(o228sO7+U#FNq7_un>L7PixR$!wl^DvHplxeMk2bx=z6X4bY-EoQYiG}fHpeVZ94=V6%hQYU~$#* zg=FqBJV2e4;iJUCO+bWOOAED&%Oq5(xR`oMOGxg6sco3oL#4=E@bjrB7oJ)~ot4y5 zH(ctCXr7Nv_Bi%z<^tbSlM@7vXk*@uGpzR)$J4}Vn$14Vl=}JP$|&LRar|rCZ=kJS zj?|X0AL{i_j1Gup;RB#Ci<`7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pRst&eXDa8fzLDd#~w?d&vUGVspD;h5>pW8Gm5y|<)$1cOJNgc5F#Kv&~E}EG2lNPoH#PMe0teKsGnHll-PQQ#UBWf_ucsxB_4a!V+cD2vIAS!yuLuI)IC0fsa_V zF@ZTuT+UZ9zv{cP4#`v%Qv7Qi>Tis&cvb+=-2ve$BV@ppl3|gfY@viapAp1}@R`fe zf{fYorRaKu#7iB$Pm4S>Ulit2^7R_Lc4S?zPs&_A9%s_09Fw_RbsV z(gV~KY^%fIE}>1U6I!44cNNt84q-!X0u}q|**Y?+f(adVN z4&ge9j*Ac0u^3+N{;_oRV|{**D0C3{bcni?Nkz@fHK1(GVnNfoL3kp3$10__m49DK zE!nZq!I+dU4)U=$3< Date: Fri, 24 Nov 2023 15:27:47 -0500 Subject: [PATCH 08/20] Check for duplicate identifiers --- .../contracts/test/NamespacedToModify.sol | 2 +- .../test/NamespacedToModifyImported.sol | 3 ++- .../core/src/utils/make-namespaced.test.ts.md | 8 ++++--- .../src/utils/make-namespaced.test.ts.snap | Bin 1218 -> 1230 bytes packages/core/src/utils/make-namespaced.ts | 21 +++++++++++++----- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/packages/core/contracts/test/NamespacedToModify.sol b/packages/core/contracts/test/NamespacedToModify.sol index 88a15bf80..e7446bde9 100644 --- a/packages/core/contracts/test/NamespacedToModify.sol +++ b/packages/core/contracts/test/NamespacedToModify.sol @@ -134,4 +134,4 @@ contract UsingForDirectives { /** * @dev a custom error outside a contract */ -error CustomErrorOutsideContract(address a); \ No newline at end of file +error CustomErrorOutsideContract(Example a); diff --git a/packages/core/contracts/test/NamespacedToModifyImported.sol b/packages/core/contracts/test/NamespacedToModifyImported.sol index b3f5301ca..2961c1238 100644 --- a/packages/core/contracts/test/NamespacedToModifyImported.sol +++ b/packages/core/contracts/test/NamespacedToModifyImported.sol @@ -1,8 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import {CONSTANT_USING_SELECTOR, plusTwo, plusThree, CustomErrorOutsideContract} from "./NamespacedToModify.sol"; +import {CONSTANT_USING_SELECTOR, plusTwo, plusThree, CustomErrorOutsideContract, Example as ParentExample} from "./NamespacedToModify.sol"; contract Example { using {plusTwo} for uint; + error ChildCustomError(ParentExample a); } \ No newline at end of file diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index 715a2aff6..a531b3cc5 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -116,7 +116,7 @@ Generated by [AVA](https://avajs.dev). ␊ uint256 constant plusThree = 0;␊ ␊ - uint256 constant plusThree = 0;␊ + ␊ ␊ ␊ ␊ @@ -129,16 +129,18 @@ Generated by [AVA](https://avajs.dev). /**␊ * @dev a custom error outside a contract␊ */␊ - uint256 constant CustomErrorOutsideContract = 0;`, + uint256 constant CustomErrorOutsideContract = 0;␊ + `, }, 'contracts/test/NamespacedToModifyImported.sol': { content: `// SPDX-License-Identifier: MIT␊ pragma solidity ^0.8.20;␊ ␊ - import {CONSTANT_USING_SELECTOR, plusTwo, plusThree, CustomErrorOutsideContract} from "./NamespacedToModify.sol";␊ + import {CONSTANT_USING_SELECTOR, plusTwo, plusThree, CustomErrorOutsideContract, Example as ParentExample} from "./NamespacedToModify.sol";␊ ␊ contract Example {␊ ␊ + ␊ }`, }, }, diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index 1be1b4b6bbd6844542b08fa45457de832e305064..c84b022de8f87f8938a930bddfd147692223805b 100644 GIT binary patch literal 1230 zcmV;<1Tp(TRzVI5hB0&j7shkud<)dJi z4+)6IyW@25?v6Dx8)Bjq!GQxOP8CQ6sfZK*0SCl^1LcIosYj4FwHE{zj=Y^++w0w! zZBUU|Y4&5@@4flWd$aGoTkV#^td98bOCqUsi0|SKK^}IA=wgf5hEFbItIVLYmzI-{T3X}v=%sq2H+>FH@rKdtGerWXNY zJQl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T&1tSrK z9Px0|A-0+u#e{T%`<_sf3FEe=4Cu;BpX7&L(o228sO7+U#FNq7_un>L7PixR$!wl^DvHplxeMk2bx=z6X4bY-EoQYiG}fHpeVZ94=V6%hQYU~$#* zg=FqBJV2e4;iJUCO+bWOOAED&%Oq5(xR`oMOGxg6sco3oL#4=E@bjrB7oJ)~ot4y5 zH(ctCXr7Nv_Bi%z<^tbSlM@7vXk*@uGpzR)$J4}Vn$14Vl=}JP$|&LRar|rCZ=kJS zj?|X0AL{i_j1Gup;RB#Ci<`7UJd4?6HexnA6wbthGBY=a%IG3IA44~rUHHh)HyX6VgX13t`@496gJI&m^U= zw!2erT;6HyU9E5KJhxZh*xFcY?7kGi9opn@8PFDOhI=Miu7MrjC44B2p;DW*9bYtF zXXCgi@eMe^NdYN$F}_ZDkmnDH7$K}8SVF5dIYbzR-yD2m92^7nK~S3n%aO4{5X`iv zl+s3^vm2_c^*0aLoG8P6ul@TBM^zy~M`I#3-}mnP&`tCIK)Q!o9DFcS8B^+J#wFE4 zPnEGBA;13wQ<1^R%berx@U2)ZD$q3m zTu*>g|e zOyg$W1;Oty?#pc2jCp`8WH)SKU=PMOVjt)kjab+#d=rB`p4m~=mIl4lub_ArMn1cj zx&V+TvU{mZ09nuIrS4sm^qX<&Ch6T%rx3WSl|`tJ_qO&Z|37SM+M_Va<_VL)s+mXv g#7rfD_h9LLGb0In27u4a|0)Um4VYbbsk;pT0Qw(); const modifications: Modification[] = []; for (const node of output.sources[sourcePath].ast.nodes) { @@ -103,16 +104,24 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI modifications.push(makeDelete(node, orig)); break; } - // - ErrorDefinition, FunctionDefinition, and VariableDeclaration might be imported by other files, - // so they cannot be deleted. Instead, they are converted to dummy variables if one of the same name - // does not already exist. + // - ErrorDefinition, FunctionDefinition, and VariableDeclaration might be imported by other files, so they cannot be deleted. + // However, we need to remove their values to avoid referencing other deleted nodes. + // We do this by converting them to dummy variables, but avoiding duplicate names. case 'ErrorDefinition': case 'FunctionDefinition': case 'VariableDeclaration': { - // Replace with a dummy variable of arbitrary type + // If an identifier with the same name was not previously written, replace with a dummy variable. + // Otherwise delete to avoid duplicate names, which can happen if there was overloading. + // This does not need to check all identifiers from the original contract, since the original compilation + // should have failed if there were conflicts in the first place. const name = node.name; - const insertText = `uint256 constant ${name} = 0;`; - modifications.push(makeReplace(node, orig, insertText)); + if (!replacedIdentifiers.has(name)) { + const insertText = `uint256 constant ${name} = 0;`; + modifications.push(makeReplace(node, orig, insertText)); + replacedIdentifiers.add(name); + } else { + modifications.push(makeDelete(node, orig)); + } break; } case 'EnumDefinition': From e72d9914d8a93955be9af6f7b1fc48551e5b2f96 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Fri, 24 Nov 2023 15:37:24 -0500 Subject: [PATCH 09/20] Simplify tests --- .../test/NamespacedToModifyImported.sol | 7 ++----- .../core/src/utils/make-namespaced.test.ts.md | 8 +++----- .../src/utils/make-namespaced.test.ts.snap | Bin 1230 -> 1216 bytes 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/core/contracts/test/NamespacedToModifyImported.sol b/packages/core/contracts/test/NamespacedToModifyImported.sol index 2961c1238..23828588d 100644 --- a/packages/core/contracts/test/NamespacedToModifyImported.sol +++ b/packages/core/contracts/test/NamespacedToModifyImported.sol @@ -1,9 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import {CONSTANT_USING_SELECTOR, plusTwo, plusThree, CustomErrorOutsideContract, Example as ParentExample} from "./NamespacedToModify.sol"; +import {CONSTANT_USING_SELECTOR, plusTwo, plusThree, CustomErrorOutsideContract} from "./NamespacedToModify.sol"; -contract Example { - using {plusTwo} for uint; - error ChildCustomError(ParentExample a); -} \ No newline at end of file +contract Example {} diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index a531b3cc5..b927b1d2c 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -136,12 +136,10 @@ Generated by [AVA](https://avajs.dev). content: `// SPDX-License-Identifier: MIT␊ pragma solidity ^0.8.20;␊ ␊ - import {CONSTANT_USING_SELECTOR, plusTwo, plusThree, CustomErrorOutsideContract, Example as ParentExample} from "./NamespacedToModify.sol";␊ + import {CONSTANT_USING_SELECTOR, plusTwo, plusThree, CustomErrorOutsideContract} from "./NamespacedToModify.sol";␊ ␊ - contract Example {␊ - ␊ - ␊ - }`, + contract Example {}␊ + `, }, }, } diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index c84b022de8f87f8938a930bddfd147692223805b..dafc432beb6f1a99f30fda03ae1b93965b10f9fc 100644 GIT binary patch literal 1216 zcmV;x1V8&hRzVM=Yu9gYMMSl%}86bW_tyfH58m zdXwk$yo0?xAMcUDK!Z8drn0B$kLdd6U~wQ3L`v%I2_^X@CdmorbBhQ?=r0i5gNAfX zThkmzKF{dHHJNl4dfpsNy=?8=>k!cJ? zCFVZZCQ`6p0dgk^E2Lo8VN>16C1Ax=6pTa^a>T~g&4VkDw1jNYwRU#QO4my5-I9MJj!cDoKiheZTW4J@u$zL3ma zf)}Wh3LHut>;y!(wK!kDxI{vgs*9MyM2-3m%_(a{l=Rbg-Nn>V-o` zBbw)9Kf4@zHgkdRsmTcfOSCcX#ThpGgX3x9G|g6@W=j2ha%7Zn_&T{8_Zw)d&Y_wT z=0ivQ6{8NZEZhMaGq^>o#Iu-9W+G-YL*aBhDATjEsDduS`)PFC>cL5SZhoLsKWMjS zXP4uIVsGVRk4e~2Ko1tWiPCgfKIq~ZaBinIct`w<1LfS5#AI3azMvJmDy#?d7d9Fvs7>dtnf zd3n3Jd$qB#{qk;OeRF-ax$}AicW8^lWRH{$PBK@*t7#6EVU_g{X{HY_g9q3J(>WAr32t3qVkt1jCWBVi2vgE0ofD zptBRItoA2YeC{iU{jB}_97feufey#SWUlYOxuK`#{(KjPk-$DB+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p+QfqN`e zt1PAaHuLuXp>O+sOy6eS1;Oty9?I<5jCp`8WcO=fU_0acup4?t9~QO>-^O51XEs!| zr9mt88z|m|k;`tS&H?0nb}RJ)K-Mx^sR!31-7`+yBYkw@`~qjSvIynz!ImE7|Hn;D sdlE+3yw4=CY9^8ZF;hw4W0?BH%t!)X0pM%%ze)ms1H1QAIl2u10F#eHyZ`_I From f3af40237e98fc8d8ee9a7393770d705d8888660 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Fri, 24 Nov 2023 15:44:10 -0500 Subject: [PATCH 10/20] Add natspec which causes compilation failure --- .../contracts/test/NamespacedToModify.sol | 12 +++++++++++- .../core/src/utils/make-namespaced.test.ts.md | 10 ++++++++++ .../src/utils/make-namespaced.test.ts.snap | Bin 1216 -> 1257 bytes 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/core/contracts/test/NamespacedToModify.sol b/packages/core/contracts/test/NamespacedToModify.sol index e7446bde9..7edec66ba 100644 --- a/packages/core/contracts/test/NamespacedToModify.sol +++ b/packages/core/contracts/test/NamespacedToModify.sol @@ -113,10 +113,19 @@ function plusTwo(uint x) pure returns (uint) { return x + 2; } +/** + * @dev plusThree + * @param x x + */ function plusThree(uint x) pure returns (uint) { return x + 3; } +/** + * @dev plusThree overloaded + * @param x x + * @param y y + */ function plusThree(uint x, uint y) pure returns (uint) { return x + y + 3; } @@ -133,5 +142,6 @@ contract UsingForDirectives { /** * @dev a custom error outside a contract + * @param example example parameter */ -error CustomErrorOutsideContract(Example a); +error CustomErrorOutsideContract(Example example); diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index b927b1d2c..12455c572 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -114,8 +114,17 @@ Generated by [AVA](https://avajs.dev). ␊ uint256 constant plusTwo = 0;␊ ␊ + /**␊ + * @dev plusThree␊ + * @param x x␊ + */␊ uint256 constant plusThree = 0;␊ ␊ + /**␊ + * @dev plusThree overloaded␊ + * @param x x␊ + * @param y y␊ + */␊ ␊ ␊ ␊ @@ -128,6 +137,7 @@ Generated by [AVA](https://avajs.dev). ␊ /**␊ * @dev a custom error outside a contract␊ + * @param example example parameter␊ */␊ uint256 constant CustomErrorOutsideContract = 0;␊ `, diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index dafc432beb6f1a99f30fda03ae1b93965b10f9fc..e1462ecbdc926a0343ec16b35a50948afc4d789d 100644 GIT binary patch literal 1257 zcmV2RzVNuf1D0 zs7P2E+w6Cf=ZU!NxlhNELPu6Ov@$$y&m2GMf zPms!%4Q$$`gs-5Tt!A;q@qvqxh>kFNt6qJsx>#Q=7UMXe%`SF34nfC71Wye#u35g2 z%w2&Oh?5FjN*tU7M7XuQSiiJFLXoPAsi&lb=Np(W=Oq| zbTTA)Au-wK*t3}n_MX}}L12qE=DnnajhHyzOq?~d6`Pq6zmTR38yvny|0ewg((30} zEeY$PlX%DIkXRNz1T*Gvi&lweF`LXqmdy>Av&o>$&d;L?x&-eh(T!FQZrU@8eVKZ< z-JYLcO&XMVD<6AI!hr(wU^5Q$f+Q?Ohgg}d09b*rLfI@r)XL@1iRFY2;3AdaBUUZn zM<|I_fmw|5#bKQHnB50<5>^&)C$3qay;W3 zlm`{#h=`%BCl|vgyuEN)Ik*@qji5FO$dR(dTG4s#e-)KT!bk6MT`ArS^zMaf*JA_K zrtd4E{-FK)gi2N2LdRnc$U+>_%h@K;y#0S@5`P@iB${`D@h6P4xecPR z0FcG}<}eKG;rOQSGd-v23;UAq60oOoySMsszi;~u1nF0oNdjL3 T;FkGcC4qkc_L1M5Ck_ArFgIS? literal 1216 zcmV;x1V8&hRzVM=Yu9gYMMSl%}86bW_tyfH58m zdXwk$yo0?xAMcUDK!Z8drn0B$kLdd6U~wQ3L`v%I2_^X@CdmorbBhQ?=r0i5gNAfX zThkmzKF{dHHJNl4dfpsNy=?8=>k!cJ? zCFVZZCQ`6p0dgk^E2Lo8VN>16C1Ax=6pTa^a>T~g&4VkDw1jNYwRU#QO4my5-I9MJj!cDoKiheZTW4J@u$zL3ma zf)}Wh3LHut>;y!(wK!kDxI{vgs*9MyM2-3m%_(a{l=Rbg-Nn>V-o` zBbw)9Kf4@zHgkdRsmTcfOSCcX#ThpGgX3x9G|g6@W=j2ha%7Zn_&T{8_Zw)d&Y_wT z=0ivQ6{8NZEZhMaGq^>o#Iu-9W+G-YL*aBhDATjEsDduS`)PFC>cL5SZhoLsKWMjS zXP4uIVsGVRk4e~2Ko1tWiPCgfKIq~ZaBinIct`w<1LfS5#AI3azMvJmDy#?d7d9Fvs7>dtnf zd3n3Jd$qB#{qk;OeRF-ax$}AicW8^lWRH{$PBK@*t7#6EVU_g{X{HY_g9q3J(>WAr32t3qVkt1jCWBVi2vgE0ofD zptBRItoA2YeC{iU{jB}_97feufey#SWUlYOxuK`#{(KjPk-$DB+pSUn4Pr5K5-~Tqu_nI2Gm$(4n270ofX-^d*gOisz$Gu^%R4OUZA^UOf2NdlCx22-NZfE2~jO}fKDvNAj^PbEL5*9rt32E_Wz+SyEUdR zGw*`nPiPNi)?~&UK<2aSu`sZm@paa9J)_PFOMxF^uxBz0ruyQbRQeqh??TIGmr54^ z@@#gg^b$bUGD@WfR|EZFoVo`3S&?@GACV>?*kpzgD eN&=t4&}U{w68IVb-tIm*`4FCW!-9i%p From 40bee1a8ff8db048c46a7c2c9f194de7d89ead44 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Fri, 24 Nov 2023 16:08:05 -0500 Subject: [PATCH 11/20] Delete documentation from dummy vars --- .../contracts/test/NamespacedToModify.sol | 3 +++ .../core/src/utils/make-namespaced.test.ts.md | 19 ++++++------------ .../src/utils/make-namespaced.test.ts.snap | Bin 1257 -> 1213 bytes packages/core/src/utils/make-namespaced.ts | 4 ++++ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/core/contracts/test/NamespacedToModify.sol b/packages/core/contracts/test/NamespacedToModify.sol index 7edec66ba..067411b50 100644 --- a/packages/core/contracts/test/NamespacedToModify.sol +++ b/packages/core/contracts/test/NamespacedToModify.sol @@ -130,6 +130,9 @@ function plusThree(uint x, uint y) pure returns (uint) { return x + y + 3; } +/** + * @dev using for directive + */ using {plusTwo} for uint; contract UsingForDirectives { diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index 12455c572..6f7d8171c 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -114,20 +114,16 @@ Generated by [AVA](https://avajs.dev). ␊ uint256 constant plusTwo = 0;␊ ␊ - /**␊ - * @dev plusThree␊ - * @param x x␊ - */␊ + ␊ uint256 constant plusThree = 0;␊ ␊ - /**␊ - * @dev plusThree overloaded␊ - * @param x x␊ - * @param y y␊ - */␊ ␊ ␊ ␊ + /**␊ + * @dev using for directive␊ + */␊ + ␊ ␊ contract UsingForDirectives {␊ ␊ @@ -135,10 +131,7 @@ Generated by [AVA](https://avajs.dev). ␊ }␊ ␊ - /**␊ - * @dev a custom error outside a contract␊ - * @param example example parameter␊ - */␊ + ␊ uint256 constant CustomErrorOutsideContract = 0;␊ `, }, diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index e1462ecbdc926a0343ec16b35a50948afc4d789d..4f58f9a1953039ed590524c46677e7650f4e7f34 100644 GIT binary patch literal 1213 zcmV;u1VZ~kRzV$ zAR(gh?l>Ld-LYn7Lrjz+IBVcj)^$*}wgoHS8&nqCBq z@n|rbJf{~r*xUE* z#z0kMzJxG0NC#E|PiiGY!Ac3(1)F)2V_S-iK1;k9p&iEc6Kc-<58Q3oXxs!%XXJ8-0q55%_1eW{5}H(8Og&{KB=^D9HoP}NqsU$G^QkB6&n}{)mCRHx zoH`k@JfC>kun|v=r-`#PTQSXy`T6wBFyZhqdYFtGSgXOY zS`yYnC-IKa0kLg-05s-si<dGl$GY%;pBl*60IWb*p&S+=s-;pG#8ScsXpt)Lk*b;> zqm#rreHn|(zNbo(%9@qZUlmY_`v@ws27rz;3RVFzi7svR0m0>T3EL zYW7W#?+U3~Vsg|i0Y(1ypvY@#;`db5him8IX-#{4I&wI9iF4c=jEcpg0xbZbo&rq` zfh?7V2ZJ>9S1_@Vqcvxvdb)*saQ{aQ*by4pfkA13z}To(S;{tJ=I#GOGj?lCGiKfe z#UCIKt9*e-LnJNOr%oKr- bVCoYyrwH5xz_;dqRRsP9;{=SRj|~6-0HICj literal 1257 zcmV2RzVNuf1D0 zs7P2E+w6Cf=ZU!NxlhNELPu6Ov@$$y&m2GMf zPms!%4Q$$`gs-5Tt!A;q@qvqxh>kFNt6qJsx>#Q=7UMXe%`SF34nfC71Wye#u35g2 z%w2&Oh?5FjN*tU7M7XuQSiiJFLXoPAsi&lb=Np(W=Oq| zbTTA)Au-wK*t3}n_MX}}L12qE=DnnajhHyzOq?~d6`Pq6zmTR38yvny|0ewg((30} zEeY$PlX%DIkXRNz1T*Gvi&lweF`LXqmdy>Av&o>$&d;L?x&-eh(T!FQZrU@8eVKZ< z-JYLcO&XMVD<6AI!hr(wU^5Q$f+Q?Ohgg}d09b*rLfI@r)XL@1iRFY2;3AdaBUUZn zM<|I_fmw|5#bKQHnB50<5>^&)C$3qay;W3 zlm`{#h=`%BCl|vgyuEN)Ik*@qji5FO$dR(dTG4s#e-)KT!bk6MT`ArS^zMaf*JA_K zrtd4E{-FK)gi2N2LdRnc$U+>_%h@K;y#0S@5`P@iB${`D@h6P4xecPR z0FcG}<}eKG;rOQSGd-v23;UAq60oOoySMsszi;~u1nF0oNdjL3 T;FkGcC4qkc_L1M5Ck_ArFgIS? diff --git a/packages/core/src/utils/make-namespaced.ts b/packages/core/src/utils/make-namespaced.ts index bc4f5df8b..d53c1a31b 100644 --- a/packages/core/src/utils/make-namespaced.ts +++ b/packages/core/src/utils/make-namespaced.ts @@ -110,6 +110,10 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI case 'ErrorDefinition': case 'FunctionDefinition': case 'VariableDeclaration': { + // First delete documentation, otherwise it may reference deleted parameters or be orphaned + if (node.documentation) { + modifications.push(makeDelete(node.documentation, orig)); + } // If an identifier with the same name was not previously written, replace with a dummy variable. // Otherwise delete to avoid duplicate names, which can happen if there was overloading. // This does not need to check all identifiers from the original contract, since the original compilation From 0105e419663fdd0bb73188f02cde510c27c45a80 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Fri, 24 Nov 2023 17:25:46 -0500 Subject: [PATCH 12/20] Add another failing scenario --- .../contracts/test/NamespacedToModify.sol | 2 +- .../core/src/utils/make-namespaced.test.ts.md | 2 +- .../src/utils/make-namespaced.test.ts.snap | Bin 1213 -> 1205 bytes 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/contracts/test/NamespacedToModify.sol b/packages/core/contracts/test/NamespacedToModify.sol index 067411b50..9a91a77c5 100644 --- a/packages/core/contracts/test/NamespacedToModify.sol +++ b/packages/core/contracts/test/NamespacedToModify.sol @@ -131,7 +131,7 @@ function plusThree(uint x, uint y) pure returns (uint) { } /** - * @dev using for directive + * @param foo foo */ using {plusTwo} for uint; diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index 6f7d8171c..d478ae695 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -121,7 +121,7 @@ Generated by [AVA](https://avajs.dev). ␊ ␊ /**␊ - * @dev using for directive␊ + * @param foo foo␊ */␊ ␊ ␊ diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index 4f58f9a1953039ed590524c46677e7650f4e7f34..670298e761e86c8ee9a187a8e96e267d45ac5ccc 100644 GIT binary patch literal 1205 zcmV;m1WNlsRzVL>lCyqRi?Om_Ei(6DA zR(js?yx)8C=DqQ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hqdYFtGSgXOY zS`yYnC-IKa0kLg-05s-si<dGl$GY%;pBl*60IWb*p&S+=s-;pG#8ScsXpt)Lk*b;> zqm#rreHn|(zNbo(%9@qZUlmY_`v@ws27rz;3RVFzi7svR0m0>T3EL zYW7W#?+U3~Vsg|i0Y(1ypvY@#;`db5him8IX-#{4I&wI9iF4c=jEcpg0xbZbo&rq` zfh?7V2ZJ>9S1_@Vqcvxvdb)*saQ{aQ*by4pfkA13z}To(S;{tJ=I#GOGj?lCGiKfe z#UCIKt9*e-LnJNOr%oKr- bVCoYyrwH5xz_;dqRRsP9;{=SRj|~6-0HICj From 15526b8c1d85c78777b05fae7c630a26fd5a0657 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Fri, 24 Nov 2023 17:52:32 -0500 Subject: [PATCH 13/20] Replace using-for directives with dummy enums --- .../core/src/utils/make-namespaced.test.ts | 10 ++++++---- .../core/src/utils/make-namespaced.test.ts.md | 4 ++-- .../src/utils/make-namespaced.test.ts.snap | Bin 1205 -> 1236 bytes packages/core/src/utils/make-namespaced.ts | 15 ++++++++++++--- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/core/src/utils/make-namespaced.test.ts b/packages/core/src/utils/make-namespaced.test.ts index 3f938bc37..d2434f239 100644 --- a/packages/core/src/utils/make-namespaced.test.ts +++ b/packages/core/src/utils/make-namespaced.test.ts @@ -35,7 +35,7 @@ async function testMakeNamespaced( const origInput = JSON.parse(JSON.stringify(origBuildInfo.input)); const modifiedInput = makeNamespacedInput(origBuildInfo.input, origBuildInfo.output); - normalizeStateVariableNames(modifiedInput); + normalizeIdentifiers(modifiedInput); t.snapshot(modifiedInput); t.deepEqual(origBuildInfo.input, origInput); @@ -46,12 +46,14 @@ async function testMakeNamespaced( t.is(modifiedOutput.errors, undefined); } -function normalizeStateVariableNames(input: SolcInput): void { +function normalizeIdentifiers(input: SolcInput): void { for (const source of Object.values(input.sources)) { if (source.content !== undefined) { source.content = source.content - .replace(/\$MainStorage_\d{1,6};/g, '$MainStorage_random;') - .replace(/\$SecondaryStorage_\d{1,6}/g, '$SecondaryStorage_random'); + .replace(/\$MainStorage_\d{1,6}/g, '$MainStorage_random') + .replace(/\$SecondaryStorage_\d{1,6}/g, '$SecondaryStorage_random') + .replace(/\$UsingForDirective_\d+_\d{1,6}/, '$UsingForDirective_1_random') + .replace(/\$UsingForDirective_\d+_\d{1,6}/, '$UsingForDirective_2_random'); } } } diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index d478ae695..7210fa3a2 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -123,10 +123,10 @@ Generated by [AVA](https://avajs.dev). /**␊ * @param foo foo␊ */␊ - ␊ + enum $UsingForDirective_1_random { dummy }␊ ␊ contract UsingForDirectives {␊ - ␊ + enum $UsingForDirective_2_random { dummy }␊ ␊ ␊ }␊ diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index 670298e761e86c8ee9a187a8e96e267d45ac5ccc..b35b1938cc9c47e8757eb3f4944a0086a6e73395 100644 GIT binary patch literal 1236 zcmV;_1S|VNRzVs^~| zP?50o*0b||@6B)Cn|}9mfDn*(KpxW1UC__%HQyk%)b;*wdU{&Z&uhA==>@k3wo}Ny#pT~kp4uSwW&j8SJNNR^^d`0Un7W=)H@JL^LWPY^PO3FUP2DnObbpCqBVOzsvra$g}_Q0DcfCOeqZkl<~7KrqiblDhOQ!j;N2 z2C4${C4{+7+OQIMQY#q>R*bOV93QwCiRcKU*Q@2H%eCsNW%craHjlB}X%lo}A^26m6g=z6mYU)qzkzD@PG z)taAQjT4GJRg66*;XnaB*i4&wK@pasL+sR60IWb*p&S+=D#c`v@x127vBm6s!Vb5?$tm^iaw}Soau5&!XTnNg1r~ z?baKYb{qRw>RY?d@7FiCH`g0`FGuh;ZE`paXqz^}HIppY!H@3}KG4Qcsl_^NUo_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`z|09NQ{jdwdH&ZX5RWgv|vAtX~E1pp!fsifx`C7 zSOCakaqATo_Go-d^@(24Qbo7^cPZH8g}qT@x!)E228MS)O2u8#MSwg}+!Z|skd1<_ z=>D}kzZ>`5?!0%;`~hdRwgflb{k=t0{vR Date: Fri, 24 Nov 2023 17:59:58 -0500 Subject: [PATCH 14/20] Update function docs --- packages/core/src/utils/make-namespaced.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/core/src/utils/make-namespaced.ts b/packages/core/src/utils/make-namespaced.ts index c28f2abb2..dba25f958 100644 --- a/packages/core/src/utils/make-namespaced.ts +++ b/packages/core/src/utils/make-namespaced.ts @@ -17,10 +17,9 @@ const OUTPUT_SELECTION = { * * This makes the following modifications to the input: * - Adds a state variable for each namespaced struct definition - * - Deletes all contracts' functions since they are not needed for storage layout - * - Deletes all contracts' modifiers, variables, and parent constructor invocations to avoid compilation errors due to deleted functions and constructors - * - Deletes all using for directives (at file level and in contracts) since they may reference deleted functions - * - Converts all free functions and constants (at file level) to dummy variables (do not delete them since they might be imported by other files) + * - For each contract, deletes the node types that are not needed for storage layout or may reference deleted functions and constructors + * - Converts all using for directives (at file level and in contracts) to dummy enums (do not delete them to avoid orphaning possible NatSpec documentation) + * - Converts all custom errors, free functions and constants (at file level) to dummy variables (do not delete them since they might be imported by other files) * * Also sets the outputSelection to only include storageLayout and ast, since the other outputs are not needed. * From a5d1d8815a68296ae860a1aa32d3ef9e45c29da6 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Mon, 27 Nov 2023 18:19:03 -0500 Subject: [PATCH 15/20] Add failing testcases --- .../contracts/test/NamespacedToModify.sol | 16 ++++++++++++++++ .../core/src/utils/make-namespaced.test.ts.md | 16 ++++++++++++++++ .../src/utils/make-namespaced.test.ts.snap | Bin 1236 -> 1297 bytes 3 files changed, 32 insertions(+) diff --git a/packages/core/contracts/test/NamespacedToModify.sol b/packages/core/contracts/test/NamespacedToModify.sol index 9a91a77c5..6ff2dcb7c 100644 --- a/packages/core/contracts/test/NamespacedToModify.sol +++ b/packages/core/contracts/test/NamespacedToModify.sol @@ -113,6 +113,13 @@ function plusTwo(uint x) pure returns (uint) { return x + 2; } +/** + * @notice originally orphaned natspec + * @dev d + * @param p p + * @return r r + */ + /** * @dev plusThree * @param x x @@ -121,6 +128,13 @@ function plusThree(uint x) pure returns (uint) { return x + 3; } +/** + * @notice originally orphaned natspec 2 + * @dev d + * @param p p + * @return r r + */ + /** * @dev plusThree overloaded * @param x x @@ -130,6 +144,8 @@ function plusThree(uint x, uint y) pure returns (uint) { return x + y + 3; } +function originallyNoDocumentation() pure {} + /** * @param foo foo */ diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index 7210fa3a2..7a1fc22ba 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -114,11 +114,27 @@ Generated by [AVA](https://avajs.dev). ␊ uint256 constant plusTwo = 0;␊ ␊ + /**␊ + * @notice originally orphaned natspec␊ + * @dev d␊ + * @param p p␊ + * @return r r␊ + */␊ + ␊ ␊ uint256 constant plusThree = 0;␊ ␊ + /**␊ + * @notice originally orphaned natspec 2␊ + * @dev d␊ + * @param p p␊ + * @return r r␊ + */␊ + ␊ + ␊ ␊ ␊ + uint256 constant originallyNoDocumentation = 0;␊ ␊ /**␊ * @param foo foo␊ diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index b35b1938cc9c47e8757eb3f4944a0086a6e73395..816c953976245721c16388041877f5ecb5b25797 100644 GIT binary patch literal 1297 zcmV+s1@8JmRzV8?r2baypX)iGnpiXJ?8@+1l(ta$Pd5Cj(y54)ZOPkZ#>X}ySEJo>u2XQron z#@WaU4pdK7z2Ez&_p07|*IP}O*$3kNFNmblC83882=cKhB3fxtXF&2o`di2xZV8K==y= z(lu>W&lqI%8&uHE*8$Rm@o5%X7-_pj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x127vBm6s!Vb5?$tm^iaw}Soau5&!XTnNg1r~ z?baKYb{qRw>RY?d@7FiCH`g0`FGuh;ZE`paXqz^}HIppY!H@3}KG4Qcsl_^NUo_ri zk@GS7Yp{hL!m?E8i)an%K6X)yu|TXK+Qjo+G#iGA@eRs@`hGja9uo@?_U?1npn;c-yd*+ zU4^M;K5{sDiF4c?j0%N<0v!S1?F49Q2xO@=+#jT&zk-Q{9IZJYRpxEng-#-B<&M$F zUJi;B1ja_y@^ZSZGjIMM+Pd$?v~}hkQ2Y*ZUuH{ZEC8gI-Oh!HJsjVreWYi!X;CK; zgFT+vZ&jE3oz~A_cn2hx-DzC}$P?L})^h;a$mq20T?_TAapo54{WI4OIIHC)xIORf y&7|W0h^c9hf|Sg=ECOq0q6iQ(RRlhOsSnMJBJc$OzBK= Date: Tue, 28 Nov 2023 11:50:58 -0500 Subject: [PATCH 16/20] Change deletions to replacements with dummy enum --- .../core/src/utils/make-namespaced.test.ts | 12 ++-- .../core/src/utils/make-namespaced.test.ts.md | 64 +++++++++--------- .../src/utils/make-namespaced.test.ts.snap | Bin 1297 -> 1306 bytes packages/core/src/utils/make-namespaced.ts | 44 ++++++------ 4 files changed, 59 insertions(+), 61 deletions(-) diff --git a/packages/core/src/utils/make-namespaced.test.ts b/packages/core/src/utils/make-namespaced.test.ts index d2434f239..6dbfa7bae 100644 --- a/packages/core/src/utils/make-namespaced.test.ts +++ b/packages/core/src/utils/make-namespaced.test.ts @@ -35,15 +35,16 @@ async function testMakeNamespaced( const origInput = JSON.parse(JSON.stringify(origBuildInfo.input)); const modifiedInput = makeNamespacedInput(origBuildInfo.input, origBuildInfo.output); + + // Run hardhat compile on the modified input and make sure it has no errors + const modifiedOutput = await hardhatCompile(modifiedInput, solcVersion); + t.is(modifiedOutput.errors, undefined); + normalizeIdentifiers(modifiedInput); t.snapshot(modifiedInput); t.deepEqual(origBuildInfo.input, origInput); t.notDeepEqual(modifiedInput, origInput); - - // Run hardhat compile on the modified input and make sure it has no errors - const modifiedOutput = await hardhatCompile(modifiedInput, solcVersion); - t.is(modifiedOutput.errors, undefined); } function normalizeIdentifiers(input: SolcInput): void { @@ -52,8 +53,7 @@ function normalizeIdentifiers(input: SolcInput): void { source.content = source.content .replace(/\$MainStorage_\d{1,6}/g, '$MainStorage_random') .replace(/\$SecondaryStorage_\d{1,6}/g, '$SecondaryStorage_random') - .replace(/\$UsingForDirective_\d+_\d{1,6}/, '$UsingForDirective_1_random') - .replace(/\$UsingForDirective_\d+_\d{1,6}/, '$UsingForDirective_2_random'); + .replace(/\$dummy_astId_\d+_\d{1,6}/g, '$dummy_astId_id_random'); } } } diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index 7a1fc22ba..0e57eb765 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -46,26 +46,26 @@ Generated by [AVA](https://avajs.dev). } SecondaryStorage $SecondaryStorage_random;␊ ␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ struct MyStruct { uint b; }␊ ␊ // keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ /// @notice standlone natspec␊ ␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ // standalone doc␊ ␊ @@ -74,45 +74,45 @@ Generated by [AVA](https://avajs.dev). */␊ ␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ }␊ ␊ contract HasFunction {␊ - ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ + enum $dummy_astId_id_random { dummy }␊ }␊ ␊ contract UsingFunction is HasFunction {␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ }␊ ␊ - uint256 constant FreeFunctionUsingSelector = 0;␊ + enum FreeFunctionUsingSelector { dummy }␊ ␊ - uint256 constant CONSTANT_USING_SELECTOR = 0;␊ + enum CONSTANT_USING_SELECTOR { dummy }␊ ␊ library Lib {␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ }␊ ␊ contract Consumer {␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ }␊ ␊ - uint256 constant plusTwo = 0;␊ + enum plusTwo { dummy }␊ ␊ /**␊ * @notice originally orphaned natspec␊ @@ -122,7 +122,7 @@ Generated by [AVA](https://avajs.dev). */␊ ␊ ␊ - uint256 constant plusThree = 0;␊ + enum plusThree { dummy }␊ ␊ /**␊ * @notice originally orphaned natspec 2␊ @@ -132,23 +132,23 @@ Generated by [AVA](https://avajs.dev). */␊ ␊ ␊ + enum $dummy_astId_id_random { dummy }␊ ␊ - ␊ - uint256 constant originallyNoDocumentation = 0;␊ + enum originallyNoDocumentation { dummy }␊ ␊ /**␊ * @param foo foo␊ */␊ - enum $UsingForDirective_1_random { dummy }␊ + enum $dummy_astId_id_random { dummy }␊ ␊ contract UsingForDirectives {␊ - enum $UsingForDirective_2_random { dummy }␊ + enum $dummy_astId_id_random { dummy }␊ ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ }␊ ␊ ␊ - uint256 constant CustomErrorOutsideContract = 0;␊ + enum CustomErrorOutsideContract { dummy }␊ `, }, 'contracts/test/NamespacedToModifyImported.sol': { @@ -191,12 +191,12 @@ Generated by [AVA](https://avajs.dev). pragma solidity 0.7.6;␊ ␊ contract HasFunction {␊ - ␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ + enum $dummy_astId_id_random { dummy }␊ }␊ ␊ contract UsingFunction is HasFunction {␊ - ␊ + enum $dummy_astId_id_random { dummy }␊ }␊ `, }, diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index 816c953976245721c16388041877f5ecb5b25797..a1496cc79b844451e175f7623676bd625ef5668f 100644 GIT binary patch literal 1306 zcmV+#1?BodRzVXq-}|Wd>f^mTwW`ORJ^A66L{a6D(8qfOG3*l=V28MfvLIAcG91WVuH*-I zTo)_+#>92o7&RK7nKo1N@c%qC0_}Zh7tM1Q%yV1ScZj1*v(ufNoHWb{!?X=E3mEIM zMsMVTnf5T-3Goi;Oq97tU8?Ga`G{$L1`<0INtB{&M{3GX5z46Kp>T-Q2K^3%KcOMh zFqX`iLDq4D(x&|uK&sF_k3-Xmwr9w`{~8gJa@L+239z6|1Miz%1JCn7QJ=m?geKWm zmz3q90yme52bw^V)?{f|E&{vcaHa%ylq@JBRbjIerV8KSF0Iw`l6#u%l?dBhBHNlD zaG{9XWCw>F0Q*g7x2>2%?6~i&Zvpas9G2>V-2=$|IP826?ADlJd^{F|WqP7u#iB4u z7_NH6)nh9gqozd2q#mTKyM`8EYA?z0u9wVQn{Zrm!+C_M*4X+aT_~XP^_AD>)~Q37 zBy(#nkZFw)v4}R-Dw#mw9Umjv+QR7VV*a^&skoHMwBvwQ53nD21RZ7&dmik@VaG-hzF|OdafHwf*an^WZlnjV7 zSPVd-mV~t^m$$?ea=GR{%0(0b73nvwMJhaW+vF&6GrWxDwUFsYK%bMdZnXY2-H`B% zc63oWplT4Qf!72fZFViX`IvDLb&N(XZ*7(P*FJL% zm`nDNt9y{GV33FcJrYEPf+2xKMxT|4zFi3MU>Z?r0G-KR)3C1EO}@e%h$U0a*XaaP zn|f=UH=0&7vh+xcp!Yp14q* zAELukj_z!GKhAbH%Iv?GeuQcQmOGU{C4-$hF;{A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V)YkDsL&T+Yt2doj$h&&w|lcq~|(yRRcu&HT}!YG+{nFKDHnIu5WToU*YwmvdPB!Mph@Rj*rC4s*I9O+|a Hx()yUW(99g diff --git a/packages/core/src/utils/make-namespaced.ts b/packages/core/src/utils/make-namespaced.ts index dba25f958..d3d54fd56 100644 --- a/packages/core/src/utils/make-namespaced.ts +++ b/packages/core/src/utils/make-namespaced.ts @@ -17,9 +17,9 @@ const OUTPUT_SELECTION = { * * This makes the following modifications to the input: * - Adds a state variable for each namespaced struct definition - * - For each contract, deletes the node types that are not needed for storage layout or may reference deleted functions and constructors - * - Converts all using for directives (at file level and in contracts) to dummy enums (do not delete them to avoid orphaning possible NatSpec documentation) - * - Converts all custom errors, free functions and constants (at file level) to dummy variables (do not delete them since they might be imported by other files) + * - For each contract, for all node types that are not needed for storage layout or may reference deleted functions and constructors, converts them to dummy enums with random id + * - Converts all using for directives (at file level and in contracts) to dummy enums with random id (do not delete them to avoid orphaning possible NatSpec documentation) + * - Converts all custom errors, free functions and constants (at file level) to dummy enums with the same name (do not delete them since they might be imported by other files) * * Also sets the outputSelection to only include storageLayout and ast, since the other outputs are not needed. * @@ -64,18 +64,14 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI case 'EventDefinition': case 'FunctionDefinition': case 'ModifierDefinition': + case 'UsingForDirective': case 'VariableDeclaration': { - if (contractNode.documentation) { + if ('documentation' in contractNode && contractNode.documentation) { + // Delete documentation for efficiency reasons only modifications.push(makeDelete(contractNode.documentation, orig)); } - modifications.push(makeDelete(contractNode, orig)); - break; - } - // - UsingForDirective isn't needed, but it might have NatSpec documentation which is not included in the AST. - // We convert it to a dummy enum to avoid orphaning any possible documentation. - case 'UsingForDirective': { - const insertText = getUsingForReplacement(contractNode.id); - modifications.push(makeReplace(contractNode, orig, insertText)); + // Replace with an enum based on astId (the original name is not needed, since nothing should reference it) + modifications.push(makeReplace(contractNode, orig, toDummyWithAstId(contractNode.id))); break; } case 'StructDefinition': { @@ -104,31 +100,29 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI // - UsingForDirective isn't needed, but it might have NatSpec documentation which is not included in the AST. // We convert it to a dummy enum to avoid orphaning any possible documentation. case 'UsingForDirective': { - const insertText = getUsingForReplacement(node.id); - modifications.push(makeReplace(node, orig, insertText)); + modifications.push(makeReplace(node, orig, toDummyWithAstId(node.id))); break; } // - ErrorDefinition, FunctionDefinition, and VariableDeclaration might be imported by other files, so they cannot be deleted. // However, we need to remove their values to avoid referencing other deleted nodes. - // We do this by converting them to dummy variables, but avoiding duplicate names. + // We do this by converting them to dummy enums, but avoiding duplicate names. case 'ErrorDefinition': case 'FunctionDefinition': case 'VariableDeclaration': { - // First delete documentation, otherwise it may reference deleted parameters or be orphaned if (node.documentation) { + // Delete documentation for efficiency reasons only modifications.push(makeDelete(node.documentation, orig)); } - // If an identifier with the same name was not previously written, replace with a dummy variable. - // Otherwise delete to avoid duplicate names, which can happen if there was overloading. + // If an identifier with the same name was not previously written, replace with a dummy enum using its name. + // Otherwise replace with an enum based on astId to avoid duplicate names, which can happen if there was overloading. // This does not need to check all identifiers from the original contract, since the original compilation // should have failed if there were conflicts in the first place. const name = node.name; if (!replacedIdentifiers.has(name)) { - const insertText = `uint256 constant ${name} = 0;`; - modifications.push(makeReplace(node, orig, insertText)); + modifications.push(makeReplace(node, orig, toDummyWithName(name))); replacedIdentifiers.add(name); } else { - modifications.push(makeDelete(node, orig)); + modifications.push(makeReplace(node, orig, toDummyWithAstId(node.id))); } break; } @@ -161,8 +155,12 @@ interface Modification { text?: string; } -function getUsingForReplacement(astId: number) { - return `enum $UsingForDirective_${astId}_${(Math.random() * 1e6).toFixed(0)} { dummy }`; +function toDummyWithName(name: string) { + return `enum ${name} { dummy }`; +} + +function toDummyWithAstId(astId: number) { + return `enum $dummy_astId_${astId}_${(Math.random() * 1e6).toFixed(0)} { dummy }`; } function getPositions(node: Node) { From 3e5e24587174d7312a7aa44de0fb7d43e882e8fe Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Tue, 28 Nov 2023 12:59:09 -0500 Subject: [PATCH 17/20] Test enum with all natspec tags --- .../contracts/test/NamespacedToModify.sol | 22 +++++++++++------- .../core/src/utils/make-namespaced.test.ts.md | 22 +++++++++++------- .../src/utils/make-namespaced.test.ts.snap | Bin 1306 -> 1352 bytes 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/packages/core/contracts/test/NamespacedToModify.sol b/packages/core/contracts/test/NamespacedToModify.sol index 6ff2dcb7c..d30458f8b 100644 --- a/packages/core/contracts/test/NamespacedToModify.sol +++ b/packages/core/contracts/test/NamespacedToModify.sol @@ -115,9 +115,6 @@ function plusTwo(uint x) pure returns (uint) { /** * @notice originally orphaned natspec - * @dev d - * @param p p - * @return r r */ /** @@ -128,12 +125,7 @@ function plusThree(uint x) pure returns (uint) { return x + 3; } -/** - * @notice originally orphaned natspec 2 - * @dev d - * @param p p - * @return r r - */ +/// @notice originally orphaned natspec 2 /** * @dev plusThree overloaded @@ -159,6 +151,18 @@ contract UsingForDirectives { } } +/** + * @title a + * @author a + * @inheritdoc Example + * @dev a + * @custom:a a + * @notice a + * @param a a + * @return a a + */ +enum FreeEnum { MyEnum } + /** * @dev a custom error outside a contract * @param example example parameter diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index 0e57eb765..8117e6047 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -116,20 +116,12 @@ Generated by [AVA](https://avajs.dev). ␊ /**␊ * @notice originally orphaned natspec␊ - * @dev d␊ - * @param p p␊ - * @return r r␊ */␊ ␊ ␊ enum plusThree { dummy }␊ ␊ - /**␊ - * @notice originally orphaned natspec 2␊ - * @dev d␊ - * @param p p␊ - * @return r r␊ - */␊ + /// @notice originally orphaned natspec 2␊ ␊ ␊ enum $dummy_astId_id_random { dummy }␊ @@ -147,6 +139,18 @@ Generated by [AVA](https://avajs.dev). enum $dummy_astId_id_random { dummy }␊ }␊ ␊ + /**␊ + * @title a␊ + * @author a␊ + * @inheritdoc Example␊ + * @dev a␊ + * @custom:a a␊ + * @notice a␊ + * @param a a␊ + * @return a a␊ + */␊ + enum FreeEnum { MyEnum }␊ + ␊ ␊ enum CustomErrorOutsideContract { dummy }␊ `, diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index a1496cc79b844451e175f7623676bd625ef5668f..79ac3d3b8606406292eab9c56cfb70bef347c704 100644 GIT binary patch literal 1352 zcmV-O1-JS^RzVYfFCQ!Sm zAVf6Y9VbI}XRMjo5EG>cBu-p7A&`10{{RP091ubrK;lHjp{JgD>IorLf)hNCckT5$ zspAMsWu>ua=KbEAH}AcfdGAiW=5l*ae)2U@RJp|W@E$=7dqg&{O&mm7!&g)?+>pCm z$&c?i4p#W>%;%OdZnQo#WhNKk|7BPr#m$@WtbVmv}vEsH%d{N>@Gm=#bM|BV82cn#%~ibSh~*( ziI^A03Bxs)IC`AO#;8f*GpPs3#4m;xU}`IUJK438nF|TMl3T_jOa4o~TzUZ0y=9(HS^f$9iiT)}YxYXHRMto6hw z*&z1Wd;k))B&-2Jt9W2&PX)Zz=rF~>IXb3LI;1YbJDn=JCtG9Z9=!Piy7o{ z;hEEiAR=fNeAgo?a$+AN2bDu9gEy#QU0IuamD^x;rrHn5G5dfd3VW!|d8=uaPq|bq z!ns(bqLo(d6FH(_3RTt_G{U-%eYFe0-yTr5O9WM|t0;K-^|V9w13>V=;$Rrq9!Crj zk_1t{V8O81J$q}d&LO-rx^onIW8)d=H>Knv7+cW5;EgkR+xuog~rF z6ZuSU)(C0qb(p%D2?UN^5dt^6y=*qCK`sD93^d*YN^3Vvw%pKJ!Gh2`o{|aju?^gW z`XMOb4$!d`9OMdM7#o!ei~Yr1a`8zh=6*V%n6n-N;SXpN0}HvtJV45Wi@3I9_f9U( zzAy(AXYKmo`v~m0fmK#%u~T0?0LF*VQiJQOO8|L(aD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NObX z_g(n>(f9oUdo@1~N$CGNyV2qP2;6lG+HL!cch1*#?9Tbw?zwaRf~mjlggfVA$}pZt Q4eQSN2Sx5`XZ{fY0NYZ9kpKVy From 10732add839529a91539754982b57e578810a28a Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Tue, 28 Nov 2023 13:04:51 -0500 Subject: [PATCH 18/20] Update changelog --- packages/core/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 61835b8e8..7da5b4348 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Fix Hardhat compile errors when contracts have overloaded functions or standalone NatSpec documentation. ([#918](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/918)) + ## 1.31.1 (2023-11-01) - CLI: Throw error if `--requireReference` and `--unsafeSkipStorageCheck` are both enabled. ([#913](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/913)) From 8771bb173c0ab0f9a55ae04291bdc3fe6e6192ca Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Tue, 28 Nov 2023 13:28:22 -0500 Subject: [PATCH 19/20] Simplify dummy enum names --- .../core/src/utils/make-namespaced.test.ts | 2 +- .../core/src/utils/make-namespaced.test.ts.md | 52 +++++++++--------- .../src/utils/make-namespaced.test.ts.snap | Bin 1352 -> 1337 bytes packages/core/src/utils/make-namespaced.ts | 14 ++--- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/packages/core/src/utils/make-namespaced.test.ts b/packages/core/src/utils/make-namespaced.test.ts index 6dbfa7bae..ed29bafe7 100644 --- a/packages/core/src/utils/make-namespaced.test.ts +++ b/packages/core/src/utils/make-namespaced.test.ts @@ -53,7 +53,7 @@ function normalizeIdentifiers(input: SolcInput): void { source.content = source.content .replace(/\$MainStorage_\d{1,6}/g, '$MainStorage_random') .replace(/\$SecondaryStorage_\d{1,6}/g, '$SecondaryStorage_random') - .replace(/\$dummy_astId_\d+_\d{1,6}/g, '$dummy_astId_id_random'); + .replace(/\$astId_\d+_\d{1,6}/g, '$astId_id_random'); } } } diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index 8117e6047..1ce5813de 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -46,26 +46,26 @@ Generated by [AVA](https://avajs.dev). } SecondaryStorage $SecondaryStorage_random;␊ ␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ struct MyStruct { uint b; }␊ ␊ // keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ /// @notice standlone natspec␊ ␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ // standalone doc␊ ␊ @@ -74,22 +74,22 @@ Generated by [AVA](https://avajs.dev). */␊ ␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ }␊ ␊ contract HasFunction {␊ - enum $dummy_astId_id_random { dummy }␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ }␊ ␊ contract UsingFunction is HasFunction {␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ }␊ ␊ enum FreeFunctionUsingSelector { dummy }␊ @@ -97,19 +97,19 @@ Generated by [AVA](https://avajs.dev). enum CONSTANT_USING_SELECTOR { dummy }␊ ␊ library Lib {␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ }␊ ␊ contract Consumer {␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ }␊ ␊ enum plusTwo { dummy }␊ @@ -124,19 +124,19 @@ Generated by [AVA](https://avajs.dev). /// @notice originally orphaned natspec 2␊ ␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ enum originallyNoDocumentation { dummy }␊ ␊ /**␊ * @param foo foo␊ */␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ contract UsingForDirectives {␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ ␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ }␊ ␊ /**␊ @@ -195,12 +195,12 @@ Generated by [AVA](https://avajs.dev). pragma solidity 0.7.6;␊ ␊ contract HasFunction {␊ - enum $dummy_astId_id_random { dummy }␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ }␊ ␊ contract UsingFunction is HasFunction {␊ - enum $dummy_astId_id_random { dummy }␊ + enum $astId_id_random { dummy }␊ }␊ `, }, diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index 79ac3d3b8606406292eab9c56cfb70bef347c704..4a6b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mm7!&g)?+>pCm z$&c?i4p#W>%;%OdZnQo#WhNKk|7BPr#m$@WtbVmv}vEsH%d{N>@Gm=#bM|BV82cn#%~ibSh~*( ziI^A03Bxs)IC`AO#;8f*GpPs3#4m;xU}`IUJK438nF|TMl3T_jOa4o~TzUZ0y=9(HS^f$9iiT)}YxYXHRMto6hw z*&z1Wd;k))B&-2Jt9W2&PX)Zz=rF~>IXb3LI;1YbJDn=JCtG9Z9=!Piy7o{ z;hEEiAR=fNeAgo?a$+AN2bDu9gEy#QU0IuamD^x;rrHn5G5dfd3VW!|d8=uaPq|bq z!ns(bqLo(d6FH(_3RTt_G{U-%eYFe0-yTr5O9WM|t0;K-^|V9w13>V=;$Rrq9!Crj zk_1t{V8O81J$q}d&LO-rx^onIW8)d=H>Knv7+cW5;EgkR+xuog~rF z6ZuSU)(C0qb(p%D2?UN^5dt^6y=*qCK`sD93^d*YN^3Vvw%pKJ!Gh2`o{|aju?^gW z`XMOb4$!d`9OMdM7#o!ei~Yr1a`8zh=6*V%n6n-N;SXpN0}HvtJV45Wi@3I9_f9U( zzAy(AXYKmo`v~m0fmK#%u~T0?0LF*VQiJQOO8|L(aDDX(KvoCTSN~n%^o})j;q++e z`vYRNumDNy|2jL;?*0_a^%=C=)+z6tZ>-pz^Sjk|=ll&*|5yX=oQp}rcqTcjJLg}c Kq5Abc5&!^zK#chS diff --git a/packages/core/src/utils/make-namespaced.ts b/packages/core/src/utils/make-namespaced.ts index d3d54fd56..b8a328d6d 100644 --- a/packages/core/src/utils/make-namespaced.ts +++ b/packages/core/src/utils/make-namespaced.ts @@ -71,7 +71,7 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI modifications.push(makeDelete(contractNode.documentation, orig)); } // Replace with an enum based on astId (the original name is not needed, since nothing should reference it) - modifications.push(makeReplace(contractNode, orig, toDummyWithAstId(contractNode.id))); + modifications.push(makeReplace(contractNode, orig, toDummyEnumWithAstId(contractNode.id))); break; } case 'StructDefinition': { @@ -100,7 +100,7 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI // - UsingForDirective isn't needed, but it might have NatSpec documentation which is not included in the AST. // We convert it to a dummy enum to avoid orphaning any possible documentation. case 'UsingForDirective': { - modifications.push(makeReplace(node, orig, toDummyWithAstId(node.id))); + modifications.push(makeReplace(node, orig, toDummyEnumWithAstId(node.id))); break; } // - ErrorDefinition, FunctionDefinition, and VariableDeclaration might be imported by other files, so they cannot be deleted. @@ -119,10 +119,10 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput): SolcI // should have failed if there were conflicts in the first place. const name = node.name; if (!replacedIdentifiers.has(name)) { - modifications.push(makeReplace(node, orig, toDummyWithName(name))); + modifications.push(makeReplace(node, orig, toDummyEnumWithName(name))); replacedIdentifiers.add(name); } else { - modifications.push(makeReplace(node, orig, toDummyWithAstId(node.id))); + modifications.push(makeReplace(node, orig, toDummyEnumWithAstId(node.id))); } break; } @@ -155,12 +155,12 @@ interface Modification { text?: string; } -function toDummyWithName(name: string) { +function toDummyEnumWithName(name: string) { return `enum ${name} { dummy }`; } -function toDummyWithAstId(astId: number) { - return `enum $dummy_astId_${astId}_${(Math.random() * 1e6).toFixed(0)} { dummy }`; +function toDummyEnumWithAstId(astId: number) { + return `enum $astId_${astId}_${(Math.random() * 1e6).toFixed(0)} { dummy }`; } function getPositions(node: Node) { From 518ba55c7714c1a84c0f5251fdcc7782ba47ce4b Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Tue, 28 Nov 2023 13:37:51 -0500 Subject: [PATCH 20/20] Avoid deleting Natspec to avoid mixing then up with different nodes --- .../core/src/utils/make-namespaced.test.ts.md | 38 +++++++++++++----- .../src/utils/make-namespaced.test.ts.snap | Bin 1337 -> 1450 bytes packages/core/src/utils/make-namespaced.ts | 21 +++------- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index 1ce5813de..fc7020329 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -45,13 +45,13 @@ Generated by [AVA](https://avajs.dev). uint256 b;␊ } SecondaryStorage $SecondaryStorage_random;␊ ␊ - ␊ + /// @notice some natspec␊ enum $astId_id_random { dummy }␊ ␊ - ␊ + /// @param a docs␊ enum $astId_id_random { dummy }␊ ␊ - ␊ + /// @param a docs␊ enum $astId_id_random { dummy }␊ struct MyStruct { uint b; }␊ ␊ @@ -64,7 +64,7 @@ Generated by [AVA](https://avajs.dev). ␊ /// @notice standlone natspec␊ ␊ - ␊ + /// @notice natspec for var␊ enum $astId_id_random { dummy }␊ ␊ // standalone doc␊ @@ -73,13 +73,21 @@ Generated by [AVA](https://avajs.dev). * standlone doc block␊ */␊ ␊ - ␊ + /**␊ + * doc block without natspec␊ + */␊ enum $astId_id_random { dummy }␊ ␊ - ␊ + /**␊ + * doc block with natspec␊ + *␊ + * @notice some natspec␊ + */␊ enum $astId_id_random { dummy }␊ ␊ - ␊ + /**␊ + * @dev a custom error inside a contract␊ + */␊ enum $astId_id_random { dummy }␊ }␊ ␊ @@ -118,12 +126,19 @@ Generated by [AVA](https://avajs.dev). * @notice originally orphaned natspec␊ */␊ ␊ - ␊ + /**␊ + * @dev plusThree␊ + * @param x x␊ + */␊ enum plusThree { dummy }␊ ␊ /// @notice originally orphaned natspec 2␊ ␊ - ␊ + /**␊ + * @dev plusThree overloaded␊ + * @param x x␊ + * @param y y␊ + */␊ enum $astId_id_random { dummy }␊ ␊ enum originallyNoDocumentation { dummy }␊ @@ -151,7 +166,10 @@ Generated by [AVA](https://avajs.dev). */␊ enum FreeEnum { MyEnum }␊ ␊ - ␊ + /**␊ + * @dev a custom error outside a contract␊ + * @param example example parameter␊ + */␊ enum CustomErrorOutsideContract { dummy }␊ `, }, diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index 4a6bc065938f4c8e726fc65abe3791cf4edb2b00..f9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