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

Add Warning about use of delete #3412

Merged
merged 4 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions contracts/utils/structs/EnumerableMap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ import "./EnumerableSet.sol";
* - `uint256 -> address` (`UintToAddressMap`) since v3.0.0
* - `address -> uint256` (`AddressToUintMap`) since v4.6.0
* - `bytes32 -> bytes32` (`Bytes32ToBytes32`) since v4.6.0
*
* // WARNING!
* // delete function should not be used. It will corrupt the data structure,
* // clear function should be used instead.
* // ref https://github.com/ethereum/solidity/pull/11843
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format is not correct.

See utils/Address.sol for how to properly format a warning.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, delete in not a "function", and there is no clear function in this structure.

I would suggest something like:

Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
See ethereum/solidity#11843 for more info

In order to clean an EnumerableMap, you can either remove all elements one by one or create a fresh instance using an array of EnumerableMap.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed wording and format.
maybe add an issue at contracts/utils/cryptography/MerkleProof.sol to make Warning's Format consistent ?

*/
library EnumerableMap {
using EnumerableSet for EnumerableSet.Bytes32Set;
Expand Down
5 changes: 5 additions & 0 deletions contracts/utils/structs/EnumerableSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ pragma solidity ^0.8.0;
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* // WARNING!
* // delete function should not be used. It will corrupt the data structure,
* // clear function should be used instead.
* // ref https://github.com/ethereum/solidity/pull/11843
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
Expand Down