Closed klkvr closed 8 months ago
This should also fix issues with aliases (like https://github.com/foundry-rs/foundry/issues/2545, https://github.com/foundry-rs/foundry/issues/3265).
Current impl handles aliases renaming via regex'es and may often be inaccurate.
I've refactored code and added logic for correct processing of references to types declared in scope of contracts.
It requires such workaround because for some reason solc does not give any information about the parent contract for UserDefinedTypeName
objects representing types like ParentContract.EnumName
. Such node will only have AST ID and location of EnumName
definition included.
That way, if we want to rename contract ParentContract
, we need to be able to determine that AST ID of EnumName
is related to that contract and replace it with ParentContract_i.EnumName
@sakulstra I believe you had some issues with flattening in the past, do you know any projects we should test this against?
@mattsse there were a few issues/things i commented in the past:
https://github.com/foundry-rs/foundry/issues/2378
e.g. cast etherscan-source -d etherscan/0x7b2a3cf972c3193f26cdec6217d27379b6417bd0 0x7b2a3cf972c3193f26cdec6217d27379b6417bd0 && forge flatten ./etherscan/0x7b2a3cf972c3193f26cdec6217d27379b6417bd0/AToken/@aave/protocol-v2/contracts/protocol/tokenization/AToken.sol --output ./etherscan/0x7b2a3cf972c3193f26cdec6217d27379b6417bd0/Flattened.sol
would remove pragma experimental ABIEncoderV2;
and therefore creating non-identical(in this case breaking) code.
https://github.com/foundry-rs/foundry/issues/6539 not really an issue but more a feature request i guess?
For #4034 specifically we also had some issues with that, but can't recall right now in which contracts. Will check if i can find on monday.
Added test and fix for https://github.com/foundry-rs/foundry/issues/2378
If any of files contains any experimental
pragma, it's getting added to the target
Pushed solution for https://github.com/foundry-rs/foundry/issues/6539.
I've also shared it's logic with current flattening implementation and rewritten it a bit as it not longer needs to be recursive.
@mattsse pushed fixes
let's merge a bit later, I will now write integration of it into foundry and may decide to change the API of Flattener
a little bit
Ref https://github.com/foundry-rs/foundry/issues/4034.
Solution
solang-parser AST was not sufficient to rename stuff, because it doesn't collect IDs of declarations and we can't match specific identifier to the declaration. Native solc AST gives such ability, so I've implemented native solc AST visitor.
The implementation of flattening itself consits of several steps:
OracleLike
interfaces becomeOracleLike_0
andOracleLike_1
)This flattener implementation can be a full replacer of the current impl for all cases when source being flattened can be compiled via solc.