Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better struct handling in code generation util #1933

Closed
wants to merge 28 commits into from

Conversation

webthethird
Copy link
Contributor

@webthethird webthethird commented May 22, 2023

Generates better code, which will compile without manual editing, when dealing with structs.

  • Avoids using a struct's canonical name, which will not match the generated interface once an I is prepended to the contract name.
  • Handles arrays of structs in function parameters and returns
  • Handles nested mappings inside and outside of structs
  • Handles structs defined in other contracts/libraries
  • Converts the type of enums used in structs, in case include_enums is false

@webthethird
Copy link
Contributor Author

@montyly @0xalpharush pip-audit may need to be updated again

@webthethird
Copy link
Contributor Author

webthethird commented May 23, 2023

One unresolved issue (edit: resolved below) is that structs defined in a library and referenced in a using-for statement do not get included in the interface, though they may be referenced in a function's arguments or returns. For example:
The contract at 0xaec84eac74981ab22905919cb282b78c7ca782df uses FixedLib.Position in a couple of public mappings:

contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable, ERC4626 {
  using FixedLib for FixedLib.Pool;
  using FixedLib for FixedLib.Position;

  /// @notice Tracks account's fixed deposit positions by maturity, account and position.
  mapping(uint256 => mapping(address => FixedLib.Position)) public fixedDepositPositions;
  /// @notice Tracks account's fixed borrow positions by maturity, account and position.
  mapping(uint256 => mapping(address => FixedLib.Position)) public fixedBorrowPositions;
  ...

for which generate_interface creates the following function signatures:

    function fixedDepositPositions(uint256,address) external returns (Position memory);
    function fixedBorrowPositions(uint256,address) external returns (Position memory);

This causes the compilation error below:

Error: Identifier not found or not unique.
--> DiffFuzzUpgrades.sol:257:71:
|
257 |     function fixedDepositPositions(uint256,address) external returns (Position memory);
|                                                                           ^^^^^^^^

webthethird and others added 23 commits May 23, 2023 14:20
so we don't end up with two functions with the same name
readme updates for 0.9.4 release
patch for python 3.11 support
* docs(readme): add new docs link

Fix the status badges and include a link to the documentation page that is now generated

* docs(citation): create CITATION.cff

This creates a `CITATION.cff` file. The information is taken from arXiv's bibtex for the whitepaper:

```bibtex
@inproceedings{Feist_2019, doi = {10.1109/wetseb.2019.00008}, url = {https://doi.org/10.1109%2Fwetseb.2019.00008}, year = 2019, month = {may}, publisher = {{IEEE} }, author = {Josselin Feist and Gustavo Grieco and Alex Groce}, title = {Slither: A Static Analysis Framework for Smart Contracts}, booktitle = {2019 {IEEE}/{ACM} 2nd International Workshop on Emerging Trends in Software Engineering for Blockchain ({WETSEB})} }
```
* 0.9.6

* lint readme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants